Basic Linux Learning (v)

Source: Internet
Author: User

The previous chapter we learned the user's rights and user management, this chapter we will learn the permissions and management of files

The content of this chapter is very important, because everything in Linux is a file. Therefore, the management of documents is particularly important


File permissions

1. View of file properties:

ls-l filename

-|rw-r--r--. | 1| Root|  Root| 46| OCT 1 05:03 |filename

1 2 3 4 5 6 7 8

Here, we manually divide the output of this command into 9 segments (the delimiter in the middle of the output "|"). Is that we add to the convenience of observing ourselves), and then we'll explain what the 9 paragraphs were.

1. File types

-# #普通文件

D # #目录

C # #字符设备

S # #套接字

P # #管道

B # #块设备

L # #连接


2. File read and Write permissions

rw-|r--|r--

*   $   @

* Owner's privileges

$ has permissions for the group

@ Other People's permissions


3. Number of times the contents of the file were recorded


4. Owner of the file


5. File Owning Group


6. Size of File contents


7. Time the file was last modified


8. File name


File owner owns the management of the group


Chown Username File|directory # #更改拥有人

Chown Username:groupname File|directory # #更改拥有人拥有组

Chown-r Username Directory # #更改目录本身及里面所有内容的拥有人

Chgrp-r GroupName Directory # #更改目录本身及里面所有内容的拥有组

Monitoring command: Watch-n 1 ls-lr/mnt

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M01/88/5C/wKioL1fzeHSSIrFSAAA64DoxfQE030.jpg-wh_500x0-wm_3 -wmp_4-s_2829341893.jpg "title=" 2.jpg "alt=" Wkiol1fzehssirfsaaa64doxfqe030.jpg-wh_50 "/>

As we can see from the above, we are just beginning to have a file called Westos, whose owner is Westos

Then we executed the Chown 0 Westos operation (0=root), and its owner became root.


File Normal Permissions


rw-|r--|r--

U g o

U: File owner can read and write to file

G: File owning group to file can read

O: Other people can read the file

U first match, G priority, O match when U,g mismatch

    1. R

To files: You can view the characters in a file

For directories: You can view the information for a file in a directory


0.5

To file: You can change the characters in the file

For directories: You can delete add files in the directory


3.x

To files: can run files

To the directory: You can enter the directory


4. modify file permissions by character mode

chmod [-R] [u|g|o] [+|-|=] [r|w|x] File|dir


chmod u-x File1 # #file1拥有者去掉x权限

chmod g+w File1 # #file1拥有组添加w权限

chmod u-x,g+w file1 # #file1拥有者去掉x权限, with group Add W permission

chmod ugo-r File2 # #file2的用户组其它人去掉r权限

chmod ug+x,o-r File3 # #file3拥有者和拥有组添加x权限, others remove R permission


5. Digitally modify file permissions

In Linux

R=4

w=2

X=1

File permission number representation:

rw-|r--|r--

U g o

U=rw-=4+2+0=6

G=r--=4+0+0=4

O=r--=4+0+0=4

So file permissions are represented as 644


chmod Modified Permission value file

chmod 777 File

7=rwx

6=rw-

5=r-w

4=r--

3=-wx

2=-w-

1=--x


After understanding these, we must all want to try to see oneself touch a file or directory permissions are 777

But the students who have tried will surely find that this is not the case.

We mkdir a new directory and will find that its permissions are shown so drwxr-xr-x is 755

and touch a new file, its permissions are-rw-r--r--that is 644

What is this for?
When we create a file or directory, the system defaults to 777 on the basis of the 022 minus, this is for the sake of security. We only give the owner the right to write and execute, so that the owning group and others only have read rights. However, the file in the initial creation for the sake of Ann, you can not give anyone the power to execute, so to 755 based on the deduction of 111, there is 644 this result, such as:

650) this.width=650; "Src=" Http://s2.51cto.com/wyfs02/M02/88/5C/wKioL1fzebTysIxDAAAlcxaOb0I279.jpg-wh_500x0-wm_3 -wmp_4-s_102337898.jpg "title=" 3.jpg "alt=" Wkiol1fzebtysixdaaalcxaob0i279.jpg-wh_50 "/>

Of course, 022 is the default option for the system, and we can also change it

Umask 077 # #修改系统保留权限为077, this setting is set to temporary, only valid in the current shell

Permanent modification Method:

VIM/ETC/BASHRC # #shell

Lines 71st through 74 are as follows:

Umask 002 # #普通用户umask

Else

Umask 022 # #超级用户umask

The fi


Vim/etc/profile # #系统

In line 60th to 63rd below

Umask 002 # #普通用户umask

All else

Umask 022 # #超级用户umask

+ fi

You just have to change the umask here to make a permanent change.

Two files above Umask set values must be consistent

Source/etc/bashrc

Source/etc/profile

Make the setting effective immediately


Special permissions

    1. SUID # #冒险位

For binary executables only

Role: Can be set in the file program is executed as a file owner, not the real performer

The teacher gave the example is very image: You borrowed a neighbor's pot cooking, add suid can borrow his pot also let him cook for you.


Setting mode:

1. Parameter mode: chmod u+s file

Because of the suid=4, so there is a digital way

2. Digital mode: chmod 4xxx file


2.sgid # #强制位

To file: only binary executables

Role: You can set all groups of processes that are generated when anyone runs a binary executable file that are all groups of files


For directories: When the directory has Sgid permissions, all the groups of all newly created files in the directory are automatically attributed to all groups in the directory, regardless of the group where the file creator is located (note that this is the new file!) The NEW!!! )


Setting mode:

1. Parameter mode: chmod g+s file|directory

Because sgid=2, so there are digital ways

2. Digital way: chmod 2xxx file|directory


3.sticky # #粘制位

T permissions:

For directories only, when a directory has T permissions, the files in the directory can only be deleted by the owner


Setting mode:

1. Command mode: chmod o+t Directory

Because T=1, so there are digital ways

2.chmod 1xxx Directory




Basic Linux Learning (v)

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.