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
heemayl
  • 91,753
An0n
  • 2,119

1 Answers1

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.

PerlDuck
  • 13,335
  • 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