简体   繁体   中英

dir1 and dir2 chmod 700, dir3 chmod 777 but I am getting Permission denied

I am learning Linux and permissions.

I have following folders dir1/dir2/dir3 and the file myfile.txt within dir3 . I am trying to give permission chmod 700 to dir1 and dir2 to both folders and files but to all files and folders within dir3 I want to give permission chmod 777 .

According to this post I did following:

To change permission for dir1 and all the directories within dir1 to chmod 700

find /home/user/dir1 -type d -exec chmod 700 {} \\;

To change all the files within dir1 to chmod 700 including the sub-folders

find /home/user/dir1 -type f -exec chmod 700 {} \\;

After that I did following:

To change permission to dir3 and all the directories within dir3 to chmod 777

find /home/user/dir1/dir2/dir3 -type d -exec chmod 777 {} \\;

To change permission to all the files within dir3 to chmod 700

find /home/user/dir1/dir2/dir3 -type f -exec chmod 777 {} \\;

When I check permission with ls -al everything looks fine but when I change the user and try to get access to dir3 and myfile.txt I am always getting message "Permission denied" .

What am doing wrong? Is there some better way to do that I want?

700 means that only the owner of dir1 and dir2 have rwx access to dir1 and dir2. If some other user will try to access the inside the dir1 or dir2 he will not be allowed irrespective of 777 inside dir3.So please check that your user is the owner. One solution is to give 770 to dir1 and dir2 this will allow the group( you have to specify ) to have rwx permission.Then you can add your user in the group so that only this user has rwx access not the other users.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM