0

How can i change the permissions of directory public to all users only read and only sudo users (group members of sudo) to only read/write access.

I prefer to do it like this :

chown root:sudo ~/public
0

chmod and chgrp are the tools needed here:

# make the group 'sudo' the owner of the directory 'public'
chgrp sudo public   

# give the group read/write access and others just read access
chmod g=rwx,o=rx public

Result:

ls -ld public
drwxrwxr-x 2 pduck sudo 4096 Feb  4 14:08 public

Update

If you also want to prevent the current owner pduck from accessing the directory (regardless of his membership), then give the ownership to root:

sudo chown root:sudo public
sudo chmod 0750 public

# result:
drwxrwxr-x 2 root sudo 4096 Feb 28 11:32 public 

Now only root and members of the sudo group have read/write access. But root can access the directory anyway, even when he's not the owner, so this is safe.


The first thought might be to keep the ownership and just reduce the rights:

sudo chown pduck:sudo public
sudo chmod 0050 public

# gives
d---r-x--- 2 pduck sudo 4096 Feb 28 11:32 public 

Now – although the owner – pduck cannot access the directory. But (as owner) he can simply regain access by issuing chmod u+rwx public himself, so this is not safe.

| improve this answer | |
  • What if pduck is not in group sudo ? – An0n Feb 26 '18 at 23:04
  • @An0n Because there is rwx in the owner bits and he is the owner, he has full access – regardless of his group membership. I updated my post to explain how to circumvent that. – PerlDuck Feb 27 '18 at 10:47

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.