Linux Learning Note III: Linux Permissions handling commands

Source: Internet
Author: User

1. Change file or directory permissions chmod

syntax:chmod [{ugo} {+-=} {rwx}] [file or directory] or [mode] [file or directory]

In the first syntax:

The u here is the owner, G refers to the owning group, O is the other person

+ refers to the increase of permissions,-refers to the reduction of permissions, = refers to the granting of permissions

R refers to read permission, W refers to write permission, X is just execute permission

The second type of syntax:

Here, the value of R is the value of 4,w is the value of 2,x is 1.

The mode in this case is a set of numbers. such as: 421. Here 421, refers to the owner of the permissions of the total number is 4, the owning group has the sum of the permissions of 2, the number of other people have the sum of 1. Here 421, the corresponding rwx is: R---w---x.

Example:

chmod u+wx hello.txt Add write and Execute permissions to the owner of the file

chmod O-rx hello.txt to reduce read and execute permissions for other people

chmod 421 Hello.txt Set the Read permission for the owner, set write permissions for the owning group, and set executable permissions for others. (Used for example only, when actually applied, please apply according to the actual situation)

2. Change the owner of the file or directory Chown

Syntax: chown [user] [file or directory]

Example: $chown Nobody file1 change the owner of the file file1 to nobody

3. Add a user and set a password

$useradd Hellen//Add user Hellen

$PASSWD Hellen//Set password for user Hellen

4. Change the group to which the file or directory belongs

Syntax: chgrp [user Group] [file or directory]

Example: $chgrp adm file1 Change the owning group of file File1 to ADM

5. View default permissions when creating new files or directories

Example: When the command "Umask" is entered

[Email protected] desktop]$ umask0002

The output is: 0002, where the first 0 is a special permission bit. The following "002" represents the permission mask value. The mode (421 = r---w---x) that changes the file or directory above is the permission code, the permission Mask value = 777-Permission code.

When we need to change the default permissions when creating a file, you can use: "Umak [Permission Mask value]" to give permissions.

[[email protected] desktop]$ umask 027  --Modify default permissions [[email protected] desktop]$ umask  --View default permissions 0027[[email Protected] desktop]$ Touch test.txt  --Create file [[email protected] desktop]$ ls-ld test.txt  --file's permission code is: 640-rw-r----- . 1 Chanshuyi chanshuyi 0 Nov 07:32 test.txt

The above command modifies the default permission to create a file or folder: 750, which is the owner RWX permission, the owning group R-x permission, the other person has no permissions.

But after we created a new file, we found that the default permissions for its files are not the same as our settings. This is because Linux has a default permission rule: Files created by default cannot be granted executable permissions, that is, x permissions.

Next: Linux Learning note four: Linux file Search command

Linux Learning Note III: Linux Permissions handling commands

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.