How to chown directory for multiple users?

71,087

Solution 1

You'll need a group with apache and all the VPS users in it, call it vpsusers for instance

# do this as root
groupadd vpsusers
gpasswd -a apache vpsusers
gpasswd -a bob vpsusers   # if you have a user named bob
gpasswd -a alice vpsusers # if you have a user name alice
# etc...

And then make that group the group owner of the directory in question, eg

# also do this as root
chown -R apache:vpsusers /your/directory

And finally, make that group-writeable

# again, as root
chmod -R g+w /your/directory

(As always, think about what you're doing before you chmod or chown...)

Solution 2

Just use this linux command

sudo chown -R :users your_directory
Share:
71,087

Related videos on Youtube

Travis
Author by

Travis

Updated on September 18, 2022

Comments

  • Travis
    Travis over 1 year

    Specs: Running Centos 6 64 Bit

    I am trying to chown a directory for all users on the VPS, aswell as for apache. But for some reason I can only have either apache, or just the users.

    I tried doing the normal chown command but making a user a owner then apache the group, and vice versa.

    travis:apache and apache:travis

    I have to do it fully as in apache:apache or travis:travis.

    The usual command I run to chown a user:

    sudo chown -R userhere:userhere /path/to/whatever/i/need

    For either to work fully.

    Why is this important? Because whenver I am using wordpress, or any script that gives basic input to modify other items on the VPS it requires the apache to have access.

    If its on apache the perms change to 48/48.

    If I want users to be able to have FTP access I have to do userhere:userhere for it to work. But in the end I wont be able to use the web based scripts again.

    Really lost, please help..

    I am also confused about another perms issue: https://superuser.com/questions/694746/centos-6-31592-31592-use-group-permissions

  • Er.KT
    Er.KT almost 9 years
    Superb man, it helps me a lot
  • DavidPostill
    DavidPostill over 6 years
    While this may answer the question, it would be a better answer if you could provide some explanation why it does so.
  • T.Todua
    T.Todua over 5 years
    can you tell a bit more? you say: ...And then make that group the group owner of the directory in question..., but under that, you are naming only apache user in that line. what does that mean? should we execute same commands for other users too, one by one? or why only apache ? I think you should have used just chown -R :vpsusers /your/directory , right?
  • Bandrami
    Bandrami about 5 years
    No, it's always better to set uid ownership explicitly, particularly in an example that's being used like this for illustatration.
  • Qumber
    Qumber over 2 years
    What does it do?
  • theberzi
    theberzi over 2 years
    @Qumber this sets the ownership of your_directory and all subdirectories (-R) to the group users. The colon separates the user name (which in this case is empty) from the group name.