Linux user management

#In Linux systems, UIDs are divided as follows (different Linux distributions, these numbers may be different)

0 means administrator (root)

1 - 500 for system users

501 - 65535 for normal users

 

#In Linux, each user has a corresponding record line in the /etc/passwd file

 

#Add user

用法: useradd  [option]  USERNAME

$ useradd -u 1010 user1

-u specifies the UID of the newly added user. According to the regulations, the UID of ordinary users must be greater than 499 and cannot be duplicated with the existing UID.

 

$ useradd -g root user2

-g specifies the base group of the newly added user

 

$ useradd -G user1,root user3

-G specifies the additional group of the newly added user, there can be multiple additional groups, and multiple additional groups are separated by commas

 

$ useradd -s /sbin/nologin user4

-d specifies the home directory for the newly added user. By default, the home directory is the directory with the same name as the user name under /home

-M do not create home directories for new users

-s specifies the default shell for the newly added user (there is a nologin shell in the system that can prohibit an account from logging in)

 

#View user information

Usage: id [option] [USERNAME], the default user is the current user when no username is specified

-u view UID

-g View the GID of the base group

-G View GIOs for all groups

-n is used in combination with the above options to display the name, not the id number

 

#delete users

用法:userdel  [option]  USERNAME

-r also deletes the user's home directory

 

#Fix the user information

#Add an existing user user to an existing user group group

$ usermod -aG group user

Note: If you use -G to modify the additional group for the user, the original additional group will be overwritten by default. If you only want to append a new additional group, you can use -aG where a means append

 

#Modify user password

Usage: passwd [USERNAME]

For ordinary users, only the passwd command can be used to modify their own passwords. For administrators, not only can use passwd to modify their own passwords, but also use the passwd USERNAME command to modify other people's passwords.

 

#Create a group

The creation of the group uses the groupadd command, you can use -g to specify the GID, and -r indicates that the group is reorganized into a system group.

 

#group information modification

The groupmod command is used to modify group information, -g modifies GID, -n modifies group name.

 

# delete group

The groupdel command is used to delete a group

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326171677&siteId=291194637