1

I'm relatively new to this Linux OS. I am not familiar with the command code or what it stands for. What I wanted to ask is I have a 750GB SSD partitioned into 4 ext4 drives. One for entertainment, one for my wife's storage, one for my storage, and one for gaming stuff. They are respectively named as 'Entertainment', Bethy's Drive, Ed's Drive, and Games/Extra. What I would like to accomplish is to allow my wife's account (username bethy) access to do everything to her drive, and also be able to save stuff to Entertainment as well. I would have sole permission to Games/Extra and Ed's Drive. I have given myself owner permission by formatting the drives directly from the desktop since formatting in GPARTED only gave permission to root and made it so I couldn't access them. After I fixed that, I attempted to try and give permissions to user bethy for the two drives named above and I get one of two restrictions.

  1. If the drive is unmounted it asks for my password as authentication as a superuser.

  2. If the drive is mounted, it doesn't even open at all and gives absolutely no response.

Can someone please assist me in understanding what I would need to do to restrict user bethy to the two specific drives? Preferably I would like to restrict access to the main Computer drive as well to only myself, but I have no way of editing those permissions for even myself let alone another user.

1
  • Just to clarify: mounting a partition always requires root (unless you are mounting a filesystem with FUSE). This act (mounting the partition) is completely independent of the permissions of directories on the partition. It is possible, however, to have a partition mounted at boot by editing /etc/fstab. Nov 5, 2015 at 3:01

1 Answer 1

2

First you will need to make the drives mount at boot by editing /etc/fstab. See: https://help.ubuntu.com/community/Fstab

Once you have modified fstab and restarted and all the drives are mounted in the correct place you can set up permissions.

You will need to change the owner of Bethy's drive to her. Assuming it is mounted in /media/Bethy you can do this by running the following in the terminal.

sudo chown bethy:bethy /media/Bethy -R

This will change the user and group to be bethy. (If you need to be able to access her files then you should add yourself to her group.. see below.)

So your own partitions are owned by you, and the group should also be you. Lets assume all your drives are mounted in /media you could run:

ls -al /media/

This should list the drives in the form

drwxrwxr-x  2 julian agroup  4096 Jun  1 22:44 SomeName

This tells us that the directory "SomeName" (which could be a mounted drive, as they just mount as directories) is owned by julian and has the group "agroup". The first block tells us some permission info, the first letter tells us it is a directory; the next 3 are the owner read, write, execute permissions; the next 3 are the group, read, write, execute permissions; final 3 are the read, write, execute permissions for any other user.

For each drive you will want to make sure the other permissions are off. For example for the bethy drive you would run this command chmod -R o-rwx /media/bethy

this recursively removes the read, write, and execute permissions for all users that are not bethy or in the bethy group, on all files in bethy.

For the drives you want access for just you, you should make sure that your account is user and group. And also use chmod as above to remove the other permissions.

For entertainment you want to make an entertainment group that you and bethy are in. To do this run these 3 commands (I assume your username is ed)

sudo groupadd entertain
sudo usermod -a -G entertain ed
sudo usermod -a -G entertain bethy

So assuming the entertainment partition is mounted in /media/Entertainment you can run:

sudo chown ed:entertain /media/Entertainment -R

Also it is best to again use chmod to remove the other permissions.

Now we want any file added to this directory to inherit the group so we setgid with

sudo chmod g+s /media/Entertainment

Finally we need to edit how new files get file permissions so the "other" permissions are off. To do this edit the file /etc/login.defs by finding the line starting with umask and replacing the number afterwards (probably 022) with 027.

I think you need to log in and out again for your permissions to update.

That, I think, should have you ready to rock.

1
  • You may see root:root as the owner of /media/<user name> but a plus (+) sign after the permissions (drwxr-x---+). The plus sign means that there are additional ACLs applied to the folder. You can check ACLs by running getfacl /media/<user name> Aug 24, 2021 at 11:48

You must log in to answer this question.

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