Linux系统管理——用户操作
一、用户相关介绍
多用户多任务操作系统
1、用户类型
- 管理员 root , uid=0
- 普通用户
- 系统用户, 保证某个软件/应用可正常运行; uid=1–999
2、用户相关文件
- /etc/passwd 用户信息
// 统计用户数
[root@martin-host ~]# wc -l /etc/passwd | awk '{print $1}'
48
// 文件格式
用户名:x:uid:gid:说明信息:家目录:shell
操作系统使用uid区分不同的用户
用户组:基本组(一个)、附加组(多个)
shell:
/bin/bash:默认shell, 可正常登录系统、执行操作
/sbin/nologin: 不允许与系统进行交互
-
/etc/shadow 用户密码信息
-
/etc/group 用户组信息
二、用户操作
1、创建用户
# useradd [选项] 用户名
- -s 指定用户shell, 默认/bin/bash
[root@martin-host ~]# useradd -s /sbin/nologin www
[root@martin-host ~]#
[root@martin-host ~]# grep "www" /etc/passwd
www:x:1004:1004::/home/www:/sbin/nologin
- -M 不创建家目录, 系统用户
[root@martin-host ~]# useradd -s /sbin/nologin -M docker
- -r 创建系统用户
[root@martin-host ~]# useradd -r -s /sbin/nologin -M redis
[root@martin-host ~]#
[root@martin-host ~]# tail -n 1 /etc/passwd
redis:x:986:980::/home/redis:/sbin/nologin
[root@martin-host ~]#
[root@martin-host ~]# ls /home/
AAA BBB demon martin www
[root@martin-host ~]#
- -G 指定用户的附加组
[root@martin-host ~]# groupadd IT
[root@martin-host ~]# useradd -G IT tome
[root@martin-host ~]#
[root@martin-host ~]# id tome
uid=1006(tome) gid=1007(tome) 组=1007(tome),1006(IT)
[root@martin-host ~]#
[root@martin-host ~]# grep -i "it" /etc/group
polkitd:x:998:
rtkit:x:172:
gnome-initial-setup:x:982:
IT:x:1006:tome
[root@martin-host ~