Linux Learning Notes (eight) file and directory permissions chmod, change owner and owning group Chown, umask, hidden permissions

Source: Internet
Author: User

The Chmodchmod command is used to modify the permissions of a file or folder.

Have studied before

ls -l


, the first one--has been studied before, and substituting refers to this is a text
The following rw-r--r--is the file's permissions
The first three bits of rw-are the permissions of the file owner
Intermediate three-bit r--is the permission of the group to which the file belongs
The latter three-bit r--is the permission of other users
There are three kinds of permissions for files:
R (Read, reading): For a file, have permission to read the contents of the file, and for the directory, have permission to browse the directory.
W (write, writes): For the file, with the new, modify, delete the contents of the file permissions, for the directory, with new, delete, modify, move files within the directory permissions.
X (Execute, execute): For the file, it has permission to execute the file, and for the directory the user has permission to enter the directory.
Permissions have permission values, r=4, w=2, X=1,
In rw-r--r--, you can use 644 to indicate
Modify the permissions of this file to 700

chmod 700  /tmp/chen1/123.txt

And then

ls -l /tmp/chen1/


You can see that the 123.txt permissions become rwx------
You can also use

chmod  g+r,o+w /tmp/chen1/123.txt

At this point the file permissions change to rwxr---w 742

G IS group user groups
O is other users,
There is also a U refers to the file owner, this method can explicitly modify the file permissions, than the permission to modify the value of a little trouble;
Next, modify permissions for the folder

ls -ld /tmp/chen1/

File permissions are rwxr-xr-x 755

chmod 700 /tmp/chen1/
ls -l /tmp/chen1/


You can find that the 123.txt file permissions have not changed, that is, the chmod command only modifies the permissions of the folder itself, and does not modify the folder internal file permissions
If you want to modify permissions for folders and folders inside files, use the following command

chmod -R 741 /tmp/chen1/

You can find that the permissions for folder/tmp/chen1/and file/tmp/chen1/123.txt have changed to 741;

Second, Chownchange owner modify the file belongs to the user
cat /etc/passwd


You can see that the last two are the users I added before Chen1 and User1
Then I'll modify the file/tmp/chen1/123.txt user

ls -l /tmp/chen1/123.txt


Users and groups of users who can see the files are root
Modify the owning user

chown chen1 /tmp/chen1/123.txt


View

ls -l /tmp/chen1/123.txt

Modify the owning group

chgrp user1 /tmp/chen1/123.txt

View

ls -l /tmp/chen1/123.txt

You can also use

chown user1:chen1  /tmp/chen1/123.txt

Modify user groups and users at the same time, separated by colons,

ls -l /tmp/chen1/123.txt

Individually modifying user groups can also

chown :user1  /tmp/chen1/123.txt

Umaskumask used to change the default permissions for new files and new folders

Folder default All permissions value 777, File 666

Umask defaults to 0022
The first digit of umask 0 can be omitted first
So the default permission for new folder is 777-022 = 755
The new text default permission is 666-002=644;
If you change the umask to 0003

umask 0003

The newly created folder permission changes to 777-003=774
While the new text permission is 664 and not 663
This is because the text all permissions are 664 (rw-rw-rw-) 003 (-------WX)
Because there is no X permission in the 664 permission, now the permission is (rw-rw-rw-)-(-------wx) = (rw-rw-r--)

Iv. Chattr Special Privileges

Use
Man chattr can view specific usage

chattr +i /tmp/chen1/123.txt


The file/tmp/chen1/123.txt cannot be modified, deleted
Use

You can see I have permission

You can delete the I permission;

chattr +a /tmp/chen1/123.txt


The file/tmp/chen1/123.txt can only be appended, cannot be deleted, and other actions

chattr -a /tmp/chen1/123.txt  

Delete a permission;
When the folder has the I permission or a permission, you can modify the contents of the file already exists in the folder, but can not delete the file, when you have a permission, the folder can also add files;

Lsattr-r/tmp/chen1/
You can view hidden permissions for all child files and folders within a file.

Linux Learning Notes (eight) file and directory permissions chmod, change owner and owning group Chown, umask, hidden permissions

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.