How to make directory writable by non-root users

To make folder writable by all the selected non-root users, group can be used in which specific non-root users will be added in the group.

The following steps requires root user privileges and can be followed in Ubuntu, CentOS, Fedora and RedHat

1) Create a group:

sudo groupadd <groupname>

2) Add user to the group:

sudo useradd -g <username> <groupname>

If user is already present then use following command

sudo usermod -a -G <groupname> <username>

3) Change group of the folder recursively:

sudo chown -R :<groupname> <folderpath>

4) Make the folder writable for the group:

sudo chmod -R g+rwX <folderpath>

5) Set group id:

sudo chmod g+s <folderpath>

if directories are present under the folder, then use following command

find <folderpath>/var/www -type d -exec chmod g+s '{}' \;

when a new file is created in the directory it will inherit the group of the directory instead of the user who created the file.

Reboot the machine to check by creating a file/folder using GUI mode.


To make folder /var/www/ and all it subfolders writable,

sudo groupadd www

sudo useradd -g testadmin www


sudo usermod -a -G www testadmin

sudo chown -R :www /var/www
sudo chmod -R g+rwX /var/www

sudo chmod g+s /var/www


find /var/www -type d -exec chmod g+s '{}' \;

That's all !

Share on Facebook3Share on Google+0Tweet about this on TwitterShare on StumbleUpon0Share on LinkedIn0Share on Tumblr0Pin on Pinterest0Email this to someonePrint this page

About Abhijit Sandhan

Abhijit Sandhan

Loves Linux, Blogging, Traveling, Hiking and sharing Knowledge!

Leave a Reply

Your email address will not be published. Required fields are marked *