File and directory permissions under Linux

Source: Internet
Author: User
Tags chmod readable

User, Group (group), and others (Others)

Linux is a multi-user multitasking operating system, at the same time there may be multiple users logged into the system, considering the security of files and other issues, so the files under Linux belong to a specific user (user), such as we use the user name User1 login system, User1 in their working directory to create a file diary.txt to record their own diary, the journal diary.txt the user is User1, there may be other users in the system, and User1 do not want others to read their own diary, User1 can set the journaling permissions to control all on the host User access to their own diary (set to their own journal readable writable, other users do not have permissions). Why do you have a group concept when you have a user? Sometimes for a file, we want to set a permission for the same group of users, and set another permission on the user outside the group, imagine one day User1 suddenly want to let another user on the host User2 to read his diary, but previously set the permissions are only self-readable writable, other people do not have access rights , and User1 only want to increase the access rights of User2, at this time through the group can be easily resolved by adding User1 and User2 to the same group group1, and then add read access to Group1, So the user under the group group1 User2 can also read User1 's diary, not the other users in the group (Others) still cannot access User1 diary.

Under Linux, the user is logged in the /etc/passwd file, the user password is recorded in the /etc/shadow file, and the group name is recorded in the /etc/group file.

Second, the file permissions under Linux

1. View File permissions

You can use the command ls -al to view the file permissions in the current directory,-A to display all files in the directory, including hidden files with. Start,-L is displayed as a long list. For example, I entered the download directory after ls -al , as shown below

The first column represents the type and permissions of the file, and for -rwxrwxrwx , we can divide it into 4 parts, such as:

Where type indicates the type of file:

    • When [ d] is the directory;
    • When [ -] is the ordinary file;
    • If [ l] is linked (link file);
    • If [ b] is indicated as the device file inside the storage interface device (can be random access device);
    • If [ c] is indicated as a serial port device inside the appliance file, such as a keyboard, mouse (one-time reading device).

[-] The characters behind each of the 3 groups analyze its meaning, where r is readable (read), W for writable (write), X for executable (execute), so the above meaning is the file Data_format.zip to the file owner readable writable executable (rwx), User-readable writable executable (RWX) in the group to which the file belongs, readable and writable executable (RWX) for other users, that is, readable and writable executable for all users.

The second column indicates the number of links to this file (which can be understood as shortcuts under Windows);

The third column represents the user of this file;

The fourth column indicates the group in which the file resides;

The fifth column indicates the size of the file, the default unit is byte;

The sixth column indicates the date on which the file was created, the last modified date;

The seventh column is the file name (or directory name).

2. Modify File Permissions

Commands to modify file permissions are commonly used in 3: Chgrp Modify the file group, chown modify the file owner, chmod modify the file permissions.

2.1. Change the file group Chgrp

You can use chgrp [OPTION] ... Group file to modify the filegroup of the file, in the example above the file Data_format.zip in the group is Hadoop, in the following command, I will data_format.zip the group to root

sudo chgrp Root Data_format. Zip [email protected] ls -al data_format. Zip 1 612614352  in Ten: Data_format. Zip

As you can see, the Data_format.zip group has been changed to root. If you want to modify all the groups of files under the directory, add the option-R.

2.2, change the file owner Chown

Method:

Chown [-R] Account name file or directory Chown [-r] Account name: Group name file or directory

In the following command, I changed the data_format.zip user to root

sudo chown Root Data_format. Zip [email protected] ls -al data_format. Zip 1 612614352  in Ten: Data_format. Zip

2.3, change the file permissions chmod

File and directory permissions under Linux

Related Article

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.