1. 用户管理
# 新增用户 useradd
root@bk:~/ckh# id root
uid=0(root) gid=0(root) groups=0(root)
root@bk:~/ckh#
root@bk:~/ckh# useradd admin
root@bk:~/ckh# id admin
uid=1002(admin) gid=1003(admin) groups=1003(admin)
# 切换用户 su - 用户名
root@bk:~# whoami
root
root@bk:~# su - admin
$ whoami
admin
# 给用户添加密码 passwd
root@bk:~/ckh# passwd
New password: Qwer.1234
Retype new password: Qwer.1234
passwd: password updated successfully
# 退出当前用户 exit
root@bk:~# su - admin
$ whoami
admin
$ exit
root@bk:~#
# 删除用户 userdel
root@bk:~# userdel -r admin
userdel: admin mail spool (/var/mail/admin) not found
userdel: admin home directory (/home/admin) not found
# 查看所有用户 /etc/passwd 这个文件
root@bk:~# cat /etc/passwd
root:x:0:0:root:/root:/bin/bash
daemon:x:1:1:daemon:/usr/sbin:/usr/sbin/nologin
bin:x:2:2:bin:/bin:/usr/sbin/nologin
sys:x:3:3:sys:/dev:/usr/sbin/nologin
sync:x:4:65534:sync:/bin:/bin/sync
games:x:5:60:games:/usr/games:/usr/sbin/nologin
man:x:6:12:man:/var/cache/man:/usr/sbin/nologin
lp:x:7:7:lp:/var/spool/lpd:/usr/sbin/nologin
mail:x:8:8:mail:/var/mail:/usr/sbin/nologin
news:x:9:9:news:/var/spool/news:/usr/sbin/nologin
uucp:x:10:10:uucp:/var/spool/uucp:/usr/sbin/nologin
proxy:x:13:13:proxy:/bin:/usr/sbin/nologin
www-data:x:33:33:www-data:/var/www:/usr/sbin/nologin
backup:x:34:34:backup:/var/backups:/usr/sbin/nologin
list:x:38:38:Mailing List Manager:/var/list:/usr/sbin/nologin
irc:x:39:39:ircd:/run/ircd:/usr/sbin/nologin
gnats:x:41:41:Gnats Bug-Reporting System (admin):/var/lib/gnats:/usr/sbin/nologin
nobody:x:65534:65534:nobody:/nonexistent:/usr/sbin/nologin
_apt:x:100:65534::/nonexistent:/usr/sbin/nologin
systemd-timesync:x:101:101:systemd Time Synchronization,,,:/run/systemd:/usr/sbin/nologin
systemd-network:x:102:103:systemd Network Management,,,:/run/systemd:/usr/sbin/nologin
systemd-resolve:x:103:104:systemd Resolver,,,:/run/systemd:/usr/sbin/nologin
messagebus:x:104:110::/nonexistent:/usr/sbin/nologin
sshd:x:105:65534::/run/sshd:/usr/sbin/nologin
systemd-coredump:x:999:999:systemd Core Dumper:/:/usr/sbin/nologin
_chrony:x:106:112:Chrony daemon,,,:/var/lib/chrony:/usr/sbin/nologin
mysql:x:107:113:MySQL Server,,,:/nonexistent:/bin/false
nginx:x:1001:1002::/home/nginx:/sbin/nologin
root@bk:~# id mysql
uid=107(mysql) gid=113(mysql) groups=113(mysql)
root@bk:~#
root@bk:~# id nginx
uid=1001(nginx) gid=1002(nginx) groups=1002(nginx)
# 添加密码的第二种方式
useradd admin
echo "Aliyun12345" | passwd --stdin admin
# 通过脚本创建用户
#!/bin/bash
# $1 是执行脚本的第一个参数,$2 是执行脚本的第二个参数
useradd $1
echo "$2" | passwd --stdin $1
# 执行过程
[root@xg ~]# bash adduser.sh "admin" "admin123"
Changing password for user admin.
passwd: all authentication tokens updated successfully.
[root@xg ~]#
[root@xg ~]# id admin
uid=1000(admin) gid=1000(admin) groups=1000(admin)
[root@xg ~]# bash adduser.sh "xiaoming" "xiaoming"
Changing password for user xiaoming.
passwd: all authentication tokens updated successfully.
[root@xg ~]#
[root@xg ~]# id xiaoming
uid=1001(xiaoming) gid=1001(xiaoming) groups=1001(xiaoming)
标签:02,sbin,admin,nologin,用户,bk,usr,权限,root
From: https://www.cnblogs.com/ckh2023/p/17745061.html