Linux user management related commands (full)

1. Linux user (account) management

Query user (account) information (judging whether the user (account) exists)

id account

Add new user (account)

useradd account

Set user (account) password

方式1:
passwd account
方式2:
echo 123|passwd --stdin account;	#密码为123

Delete user (account)

删除用户(账号)只能root登陆进行删除
方式1:保留用户(账号)目录。
userdel account
方式2:不保留用户(账号)目录。(不建议)
userdel -r account

Query the currently logged in user (account) information

who am i

Switch user (account)

su - account

2. User (account) group

An intermediate role created to facilitate the management of user (account) permissions. A
user (account) added to a user group has all the permissions of the group
and does not override the user (account)'s own unique permissions.

new group

groupadd  wudang

delete group

groupdel  wudang

Specify user groups when creating users

useradd -g 用户组 用户名
useradd -g wudang zwj	
#创建一个账号zwj,指定分组为wudang,
#如果创建账号不指定分组,系统会默认用账号创建一个分组,并把该账号归档到该用户组。

modify user group

usermod -g 用户组 用户名 
usermod -g shaolin zwj	#把用户zwj重新分组到shaolin组里

3. Important files of users and groups

/etc/passwd		记录了所有用户
/etc/shadow		记录了账号密码
/etc/group		记录了所有用户组

4. Summary

Our usual ideas for creating users should be as follows:
1. Check whether the user group has been created.

cat /etc/group |grep wudang

2. Create user groups.

groupadd  wudang

3. Create users and specify user groups.

useradd -g wudang zwj;

4. Set a password for the user account.

echo 123|passwd --stdin zwj;

5. Assign corresponding permissions to user groups.

[root@localhost ~]# chmod [ugoa] [=+-] [rwx] 文件或目录...      
u  属主        g  属组        o  其他用户        a  所有  
=  赋予...权限        +  加上...权限        -   去掉...权限
 -R //递归修改指定目录下所有文件、子目录的权限

insert image description here
insert image description here

Guess you like

Origin blog.csdn.net/Brave_heart4pzj/article/details/130848626