简体   繁体   中英

Setting directory permissions on Linux server

I am learning how to use Putty to access Linux servers and I am looking into setting directory permissions at the moment. For this, I did some simple test commands. I created a test directory and set the permissions to 0 like so

chmod 000 myTestDir

My understanding is that the first digit sets the permission for the owner of the directory, the second digit sets the permission for groups (which I am not sure what they are) and the third digit sets permissions for the rest of the world.

So now I tried to delete the folder in my ftp client, logged into the server using the same credentials as in Putty. I wasn't able to delete it which was the expected behavior since I set the permission to 0.

However, I was still able to delete the directory in Putty doing

rmdir myTestDir

Why am I able to delete the directory? I set the permission to non-readable, non-writable. Does using Putty command line automatically override those permissions?

Use command chattr +i -R folder_name to do your directory unremovable.
chmod 000 will denie creating/reading files and folders inside, not changing itself.

If you want to prevent file or directory removal, you have to change permissions on the parent directory.

mkdir 0
cd 0
mkdir 1
chmod a-w .  # This removes write permissons on 0.
rmdir 1

Output:

rmdir: failed to remove `1': Permission denied

How did you try to remove the directory in ftp?

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