I know I can assign the permission to write to an owner\group\others like this:

chmod u+w myfolder

Can I specify the specific user here? Some like this:

chmod username u+w myfolder
  • I don't think it's possible. Why don't you just add the user to the group? – Emil Jun 24 '14 at 10:50
up vote 110 down vote accepted

If you want to change the user owning this file or directory (folder), you will have to use the command chown. For instance, if you run

sudo chown username: myfolder

the user owning myfolder will be username. Then you can execute

sudo chmod u+w myfolder

to add the write permission to the username user.

But if you want to add this user to the group associated with "myfolder", you can run

sudo usermod -a -G groupname username

and then execute

sudo chmod g+w myfolder

to add the write permission to the group.

  • There is a way in which both users will have access to the folder, and a group is not needed; it was suggested in an answer for the same question here: superuser.com/a/235398/191720. – Luan Nico Feb 3 '16 at 17:17
  • Can I do this without sudo? – becko Jun 2 '16 at 13:36
  • @becko: You can if you drop to a root shell. – Charo Jun 2 '16 at 14:07
  • @Charo I meant without root – becko Jun 2 '16 at 14:28
  • @becko: You must have root privileges to change permissions associated to users or groups. – Charo Jun 2 '16 at 15:24

You could use setfacl:

setfacl -m u:username:rwx myfolder

This sets permissions for specific users, without changing the ownership of the directory.

Check out the man page for further details and examples.

  • 7
    Perfect answer! Also setfacl is available on CentOS (yum -y install acl) & FreeBSD as well. – Viet Apr 20 '17 at 12:21
  • 4
    just a note: setfacl = set File ACL, ACL = Access Control List hence for short "setFacl" - easier way to remember i think. – Yawar Murtaza Aug 22 '17 at 10:29
  • 5
    If you want to apply it recursively to all the subdirectories: add the -R flag like this: setfacl -R -m u:username:rwx myfolder – Jose A Mar 14 at 21:01
  • easiest way to give permission for a new user – Rajesh Mbm Mar 17 at 17:03
  • 1
    Is there a way to grant a user rw without changing any existing x permission, if operating on multiple files or recursively? – Qi Fan Apr 23 at 21:58

No this is not possible. You can either change the owner of the file with

[sudo] chown username: foldername

or you can add the user to the group that owns the file with

usermod -a -G {group-name} username
  • useradd -G {group-name} username tells me that username already exists – Erdal G. Sep 20 '16 at 11:51
  • i tried this but my user still can't write to that folder – Sonic Soul Sep 9 at 16:32

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

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