change permission of directory and all its sub-directories/files recursively
Linux - NewbieThis Linux forum is for members that are new to Linux.
Just starting out and have a question?
If it is not in the man pages or the how-to's this is the place!
Notices
Welcome to LinuxQuestions.org, a friendly and active Linux Community.
You are currently viewing LQ as a guest. By joining our community you will have the ability to post topics, receive our newsletter, use the advanced search, subscribe to threads and access many other special features. Registration is quick, simple and absolutely free. Join our community today!
Note that registered members see fewer ads, and ContentLink is completely disabled once you log in.
If you have any problems with the registration process or your account login, please contact us. If you need to reset your password, click here.
Having a problem logging in? Please visit this page to clear all LQ-related cookies.
Get a virtual cloud desktop with the Linux distro that you want in less than five minutes with Shells! With over 10 pre-installed distros to choose from, the worry-free installation life is here! Whether you are a digital nomad or just looking for flexibility, Shells can put your Linux machine on the device that you want to use.
Exclusive for LQ members, get up to 45% off per month. Click here for more info.
change permission of directory and all its sub-directories/files recursively
I have search around but can't find the correct answer.
How do I change the permission of a directory and all its sub-directories/files then also when a user creates a file or directory this must also follow the same permissions set at the beginning.
Basically this is what i want to do:
Keep in mind I am running a Ubuntu Server 16.04.3 with 2 virtual hosts (so 2 separate IP's used)
1= create a new virtual host (i have completed this)
2= create a new directory /var/www/example ()i have completed this)
3= created new group and user with the same name(as i wanted to mimic the same as www-data user and group.)
3= change ownership of directory:
-- used command: sudo chown -R user:group /var/www/example (this change the owner to my desired owner and group owner)
4= set permissions of this directory to 775
-- used command: sudo chmod -R 775 /var/www/example (this changed the permissions)
after all of these done i am still able to use a user to create a file which is good as this user is in the group i created but the thing is that the permissions are all wrong and the file owner is also wrong. (the user i used is also part of another group that is used on the other virtual host).
I usually set my user to my birthdate DDMM (so when i access wiht different distros, it doesn not matter, as it is awlays my birthday user code.
and i set my groupid also to the same number
I think the thinking in usernames is just wrong. afaik the system thinks in usernumber and groupnumber. the name is just an abreviation in my point of view
I also think the user definition just translates it into those numbers.
It's a little complicated in the default file systems used in GNU/Linux. I wrote a short blog post about setting group permissions for directories using either the setGUID bit or ACLs. See if that helps or if it brings up more questions.
Now when user1 creates a file then that file inherits the groups name but the user1 becomes the owner. The permissions of that created file becomes rw-rw-r-- user1.
Another user called user2 who is part of the group who owns the directory /var/www/example.com then goes to the file just created by user1 and can edit this file. The user2 can edit without any problem on the server via Putty however when editing the file via WINscp an error pops up saying "Upload of file.html was successful, but error occurred while setting the permission and/or timestamp." The user2 is using a windows pc to edit files using WINscp. This is very weird to me.
The other thing is are the above steps correct when changing ownership of directory group then the chmod,find and setfacl.
I then changes the find /var/www/example.com/ -type f -exec chmod u=rw,g=rw,o=r "{}" \; to find /var/www/example.com/ -type f -exec chmod u=rwx,g=rwx,o=rx "{}" \;
but then the permissions were still coming up as rw-rw-r which i think is the reason for that error i am getting in WINscp. This is now getting so confusing. Am i understanding it wrong?
First, the group permissions must be set to allow writing. Just doing +s leaves too much up to the umask, so to set an absolute value the second line should be like this one, followed by a verification:
Code:
chmod g=rwxs /var/www/example.com
ls -lhd /var/www/example.com
Either way the ls should show the group can write.
Second, are those users in the group 'staff' on that machine?
Code:
groups user1 user2
And the ACL is there to override the umask. So it may or may not be needed. However, you can view it:
I have done what you suggested above however when user1 creates a file then the permissions for the file is still rw-rw-r. Which is 664 i think? when i want it to be 774 (rwxrwxr--).
The users are on the machine. When i run the command "groups user1 user2" then they do show that both are in the staff group.
This is my output when i run the command "getfaclt /var/www/example.com":
LinuxQuestions.org is looking for people interested in writing
Editorials, Articles, Reviews, and more. If you'd like to contribute
content, let us know.