Linux commands chmod and chown

Source: Internet
Author: User

chmod command

The "chmod" command is to change the file's mode bit. chmod will change the file mode (permissions) of each given file, folder, script, etc. according to the required mode.

There are 3 types of permissions in the file (folder or other, for simplicity, we use the file)

?
123 Read (r)=4Write(w)=2Execute(x)=1

So if you want to give the file read-only permission, set to ' 4 '; write-only permission, set the permission to ' 2 '; Execute permission only, set to 1; Read and Write permissions, that is 4+2 = 6, and so on.

Now you need to set up 3 user and user group permissions. The first one is the owner, then the user's group, and finally the other user.

?
1 rwxr-x--x   abc.sh

The root privilege here is rwx ( Read and write and Execute permissions ),
The owning User group permission is r-x ( only Read and Execute permissions, no write permission),
For other user rights-x(only Execute permissions)

In order to change its permissions, the owner, the user group and other users to provide read, write, execute permissions.

?
1 [email protected]:~# chmod 777 abc.sh

Three are only read and write access

?
1 [email protected]:~# chmod 666 abc.sh

The owner user has read-write and Execute permissions, and the user's group and other users have only executable permissions

?
1 [email protected]:~# chmod 711 abc.sh

Note: This command is one of the most useful commands for system administrators and users. In a multiuser environment or server, for a user, if the file is set is not accessible, then this command can be resolved, if the wrong permissions are set, then provides for authorized access.

Chown command

the "chown" command changes the owner of the file and the user group. Each file belongs to one user group and one user. In your directory, use "ls-l" and you will see something like this.

?
1234 [email protected]:~# ls -l drwxr-xr-x 3 server root 4096 May 10 11:14 Binary drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

here, the directory binary belongs to the user "server", and the user group "root", and the directory "Desktop" belongs to the user "server "and user group"server"

the "chown" command is used to change the ownership of a file, so only the user and user groups that administer and provide the files are authorized.

?
1234 [email protected]:~# chown server:server Binarydrwxr-xr-x 3 server server 4096 May 10 11:14 Binary drwxr-xr-x 2 server server 4096 May 13 09:42 Desktop

Note: The files given by "chown" Change the ownership of users and groups to new owners or existing users or groups of users.

Linux commands chmod and chown

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.