Permissions for files in Linux systems

Source: Internet
Author: User
Tags file permissions

To view file permission statements:
In Terminal input:
Ls-l xxx.xxx (xxx.xxx is the file name)
Then there will be similar messages, mostly these:
-rw-rw-r--
A total of 10 digits
Which: the front one-represents the type
The middle three rw-represents the owner (user)
Then those three rw-represent groups (group)
The last three r--represent others (other).
And then I'll explain the 9 digits in the back:
R indicates that a file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
-Indicates that the appropriate permission has not been granted
Now it's time to talk about modifying file permissions.
In Terminal input:
chmod o W xxx.xxx
Give other people permission to write xxx.xxx this file
chmod GO-RW xxx.xxx
Represents the deletion of read and write permissions for groups and others in xxx.xxx
which
U on behalf of owner (user)
G represents the group where the owner resides
O stands for others, but not u and g (other).
A represents all people, including U,g and O.
R indicates that a file can be read (read)
W indicates that the file can be written (write)
x indicates that the file can be executed (if it is a program)
Where: Rwx can also be replaced by numbers
R------------4
W-----------2
X------------1
-------------0
Let's go:
Represents the Add permission
-Indicates delete permission
= indicates a permission to make it unique
When we all understand the above, then we often have some of the following permissions are easy to understand:
-RW-------(600) Only the owner has read and write permissions
-rw-r--r--(644) Only the owner has read and write permissions, and the group and other people only have Read permissions
-RWX------(700) Only the owner has read, write, execute permissions
-rwxr-xr-x (755) Only the owner has read, write, execute permissions, groups and other people only read and Execute permissions
-rwx--x--x (711) Only the owner has read, write, execute permissions, groups and other people only execute the permissions
-rw-rw-rw-(666) Everyone has access to read and write
-RWXRWXRWX (777) Everyone has access to read and write and execute

Linux file and Directory access permissions settings

Use chmod and numbers to change the access rights of a file or directory
Permissions for files and directories are represented by the rwx three characters to represent the permissions of the owner, user group, and other users. Sometimes, characters seem to be too cumbersome, so there is another way to represent permissions in numbers, and only three numbers are required.
R: Corresponding value 4
W: Corresponding value 2
x: Corresponding value 1
-: Corresponding value 0
The key to digital setting is the value of mode, at first many beginners will be confused, in fact, it is very simple, we will rwx as a binary number, if there are 1 said, no 0 said, then rwx r-x R-can be expressed as:
111 101 100
Then convert every three bits into a decimal number, which is 754.
For example, we want a.txt this file to have the following permissions:
Other users of the same group as themselves
Is readable yes Yes Yes
Can be written yes Yes
Executable
So, we first get permission string according to the above table: rw-rw-r--, then convert to binary number is 110 110 100, and then every three bits into a decimal number, we get 664, so we execute the command:
[Email protected] ~]# chmod 664 a.txt
According to the above rules, rwx together is 4 2 1=7, a file with a rwxrwxrwx permission, the value is 777, and the file "---------" with a completely open permission is represented as 000. Here are a few examples:
-RWX------: equals the number represents 700.
-rwxr-r--: equals the number represents 744.
-rw-rw-r-x: equals the number represents 665.
Drwx-x-x: equals the number represents 711.
DRWX------: equals the number represents 700.
In text mode, you can execute the chmod command to change permissions on files and directories. Let's take a look at the ls-l in the directory:
[Email protected] ~]# ls-l
Total dosage 368
-rw-r--r--1 root root 12172 August 23:18 conkyrc.sample
Drwxr-xr-x 2 root root 48 September 4 16:32 Desktop
-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6
Drwxr-xr-x 2 root root 48 August 22:25 MyMusic
-rwxr-xr-x 1 root root 9776 November 5 08:08 Net.eth0
-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1
-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo
Drwxr-xr-x 2 root root 48 September 6 13:06 VMware
You can see that the permissions of the file Conkyrc.sample file are 644, and then change the permissions of this file to 777. Execute the following command
[Email protected] ~]# chmod 777 Conkyrc.sample
Then ls-l look at the results after the execution:
[Email protected] ~]# ls-l
Total dosage 368
-rwxrwxrwx 1 root root 12172 August 23:18 conkyrc.sample
Drwxr-xr-x 2 root root 48 September 4 16:32 Desktop
-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6
Drwxr-xr-x 2 root root 48 August 22:25 MyMusic
-rwxr-xr-x 1 root root 9776 November 5 08:08 Net.eth0
-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1
-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo
Drwxr-xr-x 2 root root 48 September 6 13:06 VMware
You can see that the permissions for the Conkyrc.sample file have been modified to rwxrwxrwx
If you want to add special permissions, you must use a 4-digit number to represent it. The corresponding values for special permissions are:
s or S (SUID): Corresponds to the value 4.
s or S (SGID): corresponds to the value 2.
T or T: corresponds to the value 1.
Use the same method to modify the file permissions.
For example:
[Email protected] ~]# chmod 7600 conkyrc.sample
[Email protected] ~]# ls-l
Total dosage 368
-rws--s--t 1 root root 12172 August 23:18 conkyrc.sample
Drwxr-xr-x 2 root root 48 September 4 16:32 Desktop
-r--r--r--1 root root 331844 October 21:08 libfreetype.so.6
Drwxr-xr-x 2 root root 48 August 22:25 MyMusic
-rwxr-xr-x 1 root root 9776 November 5 08:08 Net.eth0
-rwxr-xr-x 1 root root 9776 November 5 08:08 net.eth1
-rwxr-xr-x 1 root root 512 November 5 08:08 Net.lo
Drwxr-xr-x 2 root root 48 September 6 13:06 VMware
Add the permission to modify all the files in a directory at once, including the file permissions in subdirectories to be modified, to use the parameter-R to initiate recursive processing.
For example:
[[email protected] ~]# chmod 777/home/user Note: Set the/home/user directory to rwxrwxrwx only
[[email protected] ~]# chmod-r 777/home/user Note: The permissions for the entire/home/user directory and its files and subdirectories are set to RWXRWXRWX

Transferred from: http://www.cnblogs.com/CgenJ/archive/2011/07/28/2119454.html

Permissions for files in Linux systems

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.