4

I encrypted a device using these directions

sudo dd if=/dev/urandom of=/dev/sdb1
sudo cryptsetup -y -v luksFormat /dev/sdb1
sudo cryptsetup luksOpen /dev/sdb1 $name #change "$name" to any name you wish
#now format
mkfs.ext4 /dev/mapper/$name
sudo mkdir /media/mount_point
sudo mount /dev/mapper/$name /media/mount_point

When I unlock and mount the setup, I can't write or copy anything to it because root is the owner and all permissions are only for root. Can I change this so that I have access to it?

2 Answers 2

5

Just to clarify for others as I've stumbled on this question when first searching for it on Google:

Issue: After doing all the necessary setup for a LUKS container file/harddisk that is already mounted with root, a user account has not write privileges to it, only read. (this is the case for most tutorials and instructions above)

Solution:

We need to change the permissions of the newly-minted filesystem that is in the encrypted harddisk/file container.

Using the example in the example where /dev/mapper/$name has already been mounted to /media/mount_point with a command like:

sudo mount /dev/mapper/$name /media/mount_point

Open a terminal in your account and type enter this command:

sudo chown -R yourUserName /media/mount_point

For example if joe has a mount point named myEncryptedHD he should do:

sudo chown -R joe /media/myEncryptedHD

What this does is Joe changes the owner of all files in myEncrypted to joe, and he now has read and write access. Life is good.

If you decide you don't want R/W permissions anymore, just sudo chown -R root /media/mount_point and you'll revoke your rights.

References for chown examples for more complicated permissions handling and a related question on SuperUser with a comment on the answer that also suggests the alternative sudo chmod -R 775 /media/mount_point that will set read write execute permissions on user, group and only read and execute (5) for others. A chmod man page for further info

1
  • your mount method didn't work for me, because after rebooting and plugging in, my device was already mounted as /dev/mapper/luks-series-of-hash-codes Your tutorial only worked, after I did repeat following "mount or remount encrypted partition" steps described in the tutorial, I used to encrypt my device: archive.ph/02NKD#selection-2057.0-2057.46 And instead of chown myUserName I used chmod 777 so I can write on my portable device from any Linux PC which knows LUKS: chmodcommand.com/chmod-777
    – gloschtla
    Commented Dec 17, 2019 at 8:27
1

I believe you can change this. After you get Root Privileges

sudo su

you should use

chmod 777 /directory/of/the/device

I am not sure if the device should be mounted or not before you attempt this.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .