323

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
1
  • 3
    I don't think it's possible. Why don't you just add the user to the group?
    – Emil
    Jun 24, 2014 at 10:50

5 Answers 5

423

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.

Note:

  • setfacl is short for set File ACL (Access Control List)

  • If you want to apply it recursively to all the subdirectories: add the -R flag like this:

    setfacl -R -m u:username:rwx myfolder
    
11
  • 13
    Perfect answer! Also setfacl is available on CentOS (yum -y install acl) & FreeBSD as well.
    – Viet
    Apr 20, 2017 at 12:21
  • 9
    just a note: setfacl = set File ACL, ACL = Access Control List hence for short "setFacl" - easier way to remember i think. Aug 22, 2017 at 10:29
  • 28
    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, 2018 at 21:01
  • 2
    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, 2018 at 21:58
  • 2
    I get Operation not supported
    – Wassadamo
    Jan 21, 2022 at 17:26
261

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.

10
  • 2
    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, 2016 at 17:17
  • 1
    Can I do this without sudo?
    – a06e
    Jun 2, 2016 at 13:36
  • 1
    @becko: You can if you drop to a root shell.
    – Charo
    Jun 2, 2016 at 14:07
  • 1
    @Charo I meant without root
    – a06e
    Jun 2, 2016 at 14:28
  • 1
    @AER: In the first command, if a colon follows username the owning group is also changed to username (if you omit such a colon, the owning group will not change).
    – Charo
    Apr 18, 2018 at 8:46
16

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
2
  • 1
    useradd -G {group-name} username tells me that username already exists
    – Erdal G.
    Sep 20, 2016 at 11:51
  • 4
    i tried this but my user still can't write to that folder
    – Sonic Soul
    Sep 9, 2018 at 16:32
11

If you want to apply it recursively to all the subdirectories: add the -R flag like this:

setfacl -R -m u:username:rwx myfolder
1
  • This does not work for multiple drives.
    – Andor Kiss
    Oct 26, 2023 at 14:40
7

In Ubuntu recursively (folder and it's all sub folders) giving permission to a specific user:

sudo chown -R <username>: <folderName>
0

You must log in to answer this question.

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