If we check ownership of site1, we will find something like this,
ls -ld /var/www/site1/
drwxr-xr-x 2 root root 4096 Oct 24 21:06 site1/
This means that the directory is owned by user root, group root. While user root has write permission (plus read and execute permissions) to the directory, group root has only read and execute permissions.
We will want to change the group ownership to another (new) group and add user1 to that particular group. We will give write permission to that particular group as well.
Create a new group,
sudo addgroup site1
Add user1 to the newly created group,
sudo adduser user1 site1
Check that user1 is really in that group,
groups user1
The output should be a list something like,
user1 : <other-groups> site1
Now we can change the group ownership of your intended directory.
sudo chown -vR :site1 /var/www/site1/
changed ownership of `/var/www/site1/' from root:root to :site1
Grant write permission to this new group owner,
sudo chmod -vR g+w /var/www/site1/
mode of `/var/www/site1/' changed from 0755 (rwxr-xr-x) to 0775 (rwxrwxr-x)
Check that all the changes are indeed there,
ls -ld /var/www/site1/
drwxrwxr-x 2 root site1 4096 Oct 24 21:06 /var/www/site1/
So, the directory now is owned by user root, group site1. Both user root and group site1 have write permission (plus read and execute permissions) to the directory. Any user belonging to group site1 will enjoy all the privileges granted to that group.
Now login as user1, move to site1 directory and try to create a file in that directory,
echo "My User1 Site" > index.html
bash: index.html: Permission denied
This failed since most likely the primary group of user1 is not site1. So, change to that group.
newgrp - site1
Be the first to comment
You can use [html][/html], [css][/css], [php][/php] and more to embed the code. Urls are automatically hyperlinked. Line breaks and paragraphs are automatically generated.