Linux study notes (10) -- Linux user management

Linux is a multi-user and multi-tasking operating system. Any user who wants to use system resources must apply for an account from the system administrator and then enter the system as this account.

This article takes CentOS7this as an example.

Directory structure of this article

Linux study notes (10) -- Linux user management.png

Add user
  • For added users, the default home directory is/home/用户名
useradd -d [指定家目录路径] [用户名]
  • Add new user to specified group
useradd -g [指定组名] [用户名]

Note: If a new user does not specify a group name, the system will create a group with the same user name by default and place the new user under this group.

Specify/modify password
passwd  [用户名]
  • If no username is written, the username will be modified for the current user by default.

delete users
  • Remove user but keep home directory
userdel [用户名]
  • Delete the user and the user's home directory
userdel -r [用户名]
  • It is generally recommended to keep the home directory and delete user information.

Query user information
id  [用户名]

Switch user
su  - [用户名]
  • In addition, switching from a user with high permissions to a user with low permissions does not require entering a password, and vice versa.

Log out of current user
logout
exit

View currently logged in users
  • The following command records the user information of the first login, no matter how many times the user is switched
who am i

Add new group
groupadd [组名]

Delete group
groupdel [组名]

Switch user groups
usermod -g [用户组名] [用户名]

User and group related files
  • /etc/passwdFile
    Configuration file that records various user information
    Data format:
用户名:口令:用户标识号(即uid):组标识号(gid):注释性描述:主目录:登录Shell
  • /etc/shadowFile
    Password configuration file, used to verify passwords
    Data format:
登录名:加密口令:最后一次修改时间:最小时间间隔:最大时间间隔:警告时间:不活动时间:失效时间:标志
  • /etc/groupFile
    Configuration file that records user group information
    Data format:
组名:口令:组表示号(即gid):组内用户列表

Guess you like

Origin blog.csdn.net/qq_22255311/article/details/126234734