Linux Chmod,chown Command detailed

Source: Internet
Author: User
Tags readable

directive Name: chmod

Usage rights: All users
Mode of use: chmod [-CFVR] [--help] [--version] Mode file ...
Description: Linux/unix file access rights are classified into three levels: file owners, groups, and others. The use of chmod can be
To control how files are accessed by others.
Mode: Permission set string in the following format: [Ugoa ...] [[+-=][RWXX] ...] [,...], where u represents the ownership of the file
, g means that the owner of the file belongs to the same group (group), and O means the other person, a means that all three
Is.
+ indicates an increase in permissions,-represents a cancellation permission, = Represents a unique set of permissions.
R means readable, w means writable, x is executable, x means only if the file is a subdirectory or the file has been
has been set to be executable.
-C: If the file permissions have changed, the change action will be displayed
-F: Do not display an error message if the file permissions cannot be changed
-V: Show details of permission changes
-r: The same permissions change for all files in the current directory and subdirectories (that is, they are changed in a recursive manner)
--HELP: Show Auxiliary Instructions
--version: Display version
Example: Set the file file1.txt to be read by everyone:
chmod ugo+r File1.txt
Set the file file1.txt to be readable by everyone:
chmod a+r File1.txt
The file file1.txt and File2.txt are set as the owner of the file, which can be written to the same group as the person belonging to it, but other than
The person is not writable:
chmod ug+w,o-w file1.txt File2.txt
Set ex1.py to only the owner of the file can perform:
chmod u+x ex1.py
Set all files and subdirectories in the current directory to be readable by anyone:
Chmod-r A+r *
In addition chmod can also use numbers to represent permissions such as chmod 777 file
The syntax is: chmod ABC file
Each of the a,b,c is a number that represents the permissions of the user, Group, and other respectively.
R=4,w=2,x=1
To rwx the attribute then 4+2+1=7;
To rw-the attribute then 4+2=6;
To r-x the property, 4+1=7.
Example:
chmod a=rwx File
And
chmod 777 File
Same effect
chmod ug=rwx,o=x File
And
chmod 771 File
Same effect
Use chmod 4755 filename to give the program root privileges
directive Name: Chown
usage rights: Root
How to use: Chown [-CFHVR] [--help] [--version] user[:group] File ...
Description: Linux/unix is a multi-person and multi-work system, with all files owned by the owner. With Chown, the archive can be
The people who have changed. Generally speaking, this instruction is only used by the system administrator (root), the general user does not have the authority to
Change other people's file owner, also do not have the authority to change the owner of their own files to other persons. Only system administrator (root)
have this permission.
User: New file owner's user idgroup: The user group of the new file owner (group)-C: If the file
The owner has indeed changed to show its change action-F: If the file owner cannot be changed, do not display the error message-H:
Make changes to the link only, not the one that the link really points to.-V: Show details of owner changes-R:
All files in the previous directory are made with the same owner changes as subdirectories (that is, they are changed individually)--help: Display Auxiliary
Description--version: Display version
Example:
Set the owner of the archive file1.txt to the Users group user jessie:
Chown Jessie:users File1.txt
The owner of all files and subdirectories in the current directory is set to user Lamport of the Users group:
Chown-r Lamport:users *
-RW-------(600)--only the master has read and write permission.
-rw-r--r--(644)--only the master has read and write permission, and the group user and other users have Read permission only.
-RWX------(700)--only the owner has read, write, and execute permissions.
-rwxr-xr-x (755)-The master has read, write, execute permission, but the group user and other users only read, execute permissions.
-rwx--x--x (711)-The master has read, write, execute permissions, but the group user and other users only execute permissions.
-rw-rw-rw-(666)--All users have file read and write permissions. This approach is undesirable.
-RWXRWXRWX (777)-All users have read, write, and execute permissions. More undesirable approach.
Here are two general settings for the directory:
DRWX------(700)-only the owner can read and write in the directory.
Drwxr-xr-x (755)-All users can read the directory, but only the owner can change the contents of the directory
SUID's representative number is 4, for example 4755 results are-rwsr-xr-x
Sgid's representative number is 2, for example 6755 results are-rwsr-sr-x
The sticky bit represents a number of 1, for example 7755 results are-rwsr-sr-t
(Of course 7755 this chmod setting doesn't make much sense, here is just a demo)

Chown command
Use
Change the owner or group associated with the file.
Grammar
chown[- F][- H][- R] Owner [: Group] {File ... | Directory ...}
Chown- R[- F][- H|- L|- P] Owner [: Group] {File ... | Directory ...}
Describe
The chown command changes the owner of the file specified by the files parameter to the user specified by the owner parameter. The value of the Owner parameter can be a user ID or login that can be found in the/etc/passwd file. You can also optionally specify a group. The value of the group parameter can be either a set identifier or a group name that can be found in the/etc/group file.
Only the root user can change the owner of the file. You can change the group of files only if you are the root user or if you own the file. If you have a file but not the root user, you can only change the group to the group that you are a member of.
Although the-H,-l, and-p flags are mutually exclusive, specifying more than one is not considered an error. The last flag specified determines the action that the command draft will demonstrate.
Sign
-F
All error messages except usage messages are forbidden.
-H
Changes the ownership of the symbolic link that is encountered, rather than the ownership of the file or directory that the symbolic link points to.
When you encounter a symbolic link and you do not specify the-H flag, the Chown command changes the ownership of the file or directory that the link points to, not the link itself.
If you specify the-r flag, the Chown command recursively specifies the directory in descending order.
-H
If the-r option is specified, and the symbolic link of a file referencing the type directory is specified on the command line, the chown variable changes the user ID (and group identity, if specified) of the directory referenced by the symbol and all files in the file hierarchy in that directory.
-L
If the-r option is specified, and the symbol referencing the type directory is specified on the command line or is encountered during traversal of the file hierarchy, the chown command changes the user identity (and group identity, if specified) of the directory referenced by the symbolic link and all files in the file hierarchy under that directory.
-P
If the-r option is specified and the symbolic link is specified on the command line or is encountered during traversal of the file hierarchy, the chown command changes the owner identity (and group ID, if specified) of the symbolic link if the operation is supported by the system. The Chown command does not execute symbolic links to any other part of the file hierarchy.
-R
Recursively descending the directory, changing the ownership of each file. When a symbolic link is encountered and the link points to the directory, the ownership of the directory is changed, but the directory is not further traversed. However, if the-H,-H,-l OR-P flag is not specified, the group ownership of the directory changes but does not traverse the directory further when the symbolic link is encountered and the link points to the directory.
Security
Access control: This program should be installed as a normal user program in trusted computing base.
Exit status
The command returns the following exit values:
0
The command executes successfully and all requested changes have been performed.
>0
An error has occurred.
Example

  • To change the owner of a file program.c:
    Chown Jim Program.c
    The user access rights for PROGRAM.C are now applied to Jim. As an owner, Jim can use
    chmod
    command allows or denies other users access to PROGRAM.C.
  • To change the owner and group of all files in directory/tmp/src to user John and group build:
    Chown-r JOHN:BUILD/TMP/SRC
    File
    /usr/bin/chown
    Chown command
    /etc/group
    Files that contain group identities
    /etc/passwd
    Files that contain user identities

Linux Chmod,chown Command detailed

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.