简体   繁体   English

在Linux服务器上设置目录权限

[英]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. 我正在学习如何使用Putty访问Linux服务器,目前正在研究设置目录权限。 For this, I did some simple test commands. 为此,我做了一些简单的测试命令。 I created a test directory and set the permissions to 0 like so 我创建了一个测试目录,并将权限设置为0,如下所示

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. 因此,现在我尝试删除ftp客户端中的文件夹,并使用与Putty中相同的凭据登录到服务器。 I wasn't able to delete it which was the expected behavior since I set the permission to 0. 由于将权限设置为0,因此无法删除它,这是预期的行为。

However, I was still able to delete the directory in Putty doing 但是,我仍然能够删除Putty中的目录

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? 使用Putty命令行会自动覆盖这些权限吗?

Use command chattr +i -R folder_name to do your directory unremovable. 使用命令chattr +i -R folder_name使目录不可移动。
chmod 000 will denie creating/reading files and folders inside, not changing itself. chmod 000将拒绝在内部创建/读取文件和文件夹,而不更改自身。

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? 您如何尝试删除ftp中的目录?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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