Summary of Linux user and permissions-related common commands

Source: Internet
Author: User
Tags chmod superuser permission

 First, view the identity

Id:display user identity.

The output of this command displays the Uid,gid and the group to which the user belongs.

UID is the user ID, which is assigned when the account is created.

The GID is the primary group ID and is the ID of the primary group. Of course, this user can also belong to more groups.

The user account information is defined in the/etc/passwd file, and the group information is defined in the/etc/group file.

 Second, chmod

Command name: chmod

Command English original meaning: Change the permissions mode of a file

Path to command:/bin/chmod

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

Function Description: Change file or directory permissions.

User type:

U:user, actually refers to the owner

G:group Owning Group

O:others other people

A:all all, that is, the combination of Ugo, if you do not specify a user type, the default is all.

+ Add permissions,-remove permissions, = directly grant permissions

R Readable, W writable, x executable.

Specific to files and folders have different meanings, such as a file called Doc, to the owner plus WX permissions: chmod u+wx doc

  Third, the use of numbers to express authority

The code is as follows:

R-4

W-2

X-1

Add the permissions numbers for each group as the entire set of permissions, such as:

RWX is 7,r-x, 5,r--is 4.

Then rwxr-xr--can be expressed as 754

More commonly used numbers: 7 (RWX), 6 (rw-), 5 (R-x), 4 (r--), 0 (---)

 Iv. umask Order

Umask command feature: Displays and sets the default permissions for files.

umask command syntax: umask [-S]

-S: Displays the default permissions for the new file or directory as rwx.

Executive Umask:

Show 0022

First 0: special permission bit

022 user right bit, permission mask value.

You need 777 minus 022 to get 755, three digits to represent Ugo (user,group,others) permissions.

Umask–s:

U=rwx,g=rx,o=rx

Linux Permissions rules:

The file created by default cannot grant executable x permissions, which is for security's sake, the file defaults are not executed.

You can use Umask to change the default permissions, in the form of umask plus a mask value.

For example, to change the permissions to 750, to use 777 minus 750, and umask 027 command.

 V. Change of identity changing identities

You can change your current identity in three different ways in Linux:

1. Log out and login with another account (... orz ...).

2. Use the SU command.

3. Use sudo command.

A:su

Su:run a Shell with substitute User and Group IDs.

Su [-[l]] [user]

If the-l option (often abbreviated to-) is used, the result is a login shell.

The user's environment is loaded, and the current work path is changed to the user's home path. If you do not specify a user, the default is Superuser.

After the su– is executed, you need to enter a superuser password, and after you enter it, a new shell is opened, the command prompt will change to # ($), and the current working directory becomes the Superuser home directory (/root), and if you want to exit after the end, Enter exit and it will go back to the previous shell.

You can also directly execute a command:

The code is as follows:

Su–c ' Command '

You need to put the commands in quotes to make a distinction.

B:sudo

Sudo:execute a Command as Another User.

sudo and Su are similar, there are some additional attributes, the administrator can configure sudo, under good control, so that ordinary users to execute commands in different capacities.

A user may be restricted to certain commands and cannot perform other.

Another difference is that sudo does not require to know the superuser password, only need to know the current user's password, enter the password, complete authentication, sudo will not open a new shell, also will not load another user's environment, the command does not need to be enclosed in quotes. This behavior can be overridden by a variety of options to view the Sudo man page.

Sudo–l can view the permissions given by sudo.

Vi. changing owners and affiliated groups

Change owner: Chown

Command English original meaning: Change file ownership

Syntax: chown [user] [file or directory]

Function: Change the owner of a file or directory.

Change belong group: CHGRP

Command English original meaning: Change file group ownership

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

Function: Change the group to which the file or directory belongs.

The Chown command can also be used to change the owning group.

The code is as follows:

Chown [Owner][:[group]] file ...

 Seven, change the password

passwd [user]

When you reset your password, you need to enter an old password.

If you have Superuser permission, you can also set the other user's password.

Other options can set account lockout, password expiration, and so on, details can be viewed passwd's man page.

Related Article

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.