Linux-04
用户管理
[root@qls ~]
root:x:0:0:root:/root:/bin/bash
以:为分隔符
root
x
0
0
root
/root
/bin/bash
[root@qls ~]
root:$6$PZUVzAeQdrf8bOt5$6fhIZlLOf6EoweOMBbv7JMKaA6hCwfBUAHfNbvXI6eXl2ePXJZmmciXQk3yfcUesYRRjvD.Tk6VXcDl0wkV6d.::0:99999:7:::
[root@qls ~]
跟用户相关的命令
useradd
选项
-u
-g
-c
-s
-M
-G
-r
-d
usermod
选项
-u
-g
-c
-s
-l
-G
-a
userdel
-r
CentOS-7
0
1-200
201-999
1000+
用户的创建过程
[root@qls ~]
-rw-r--r--. 1 root root 2028 Oct 30 2018 /etc/login.defs
[root@qls ~]
-rw-r--r--. 1 root root 119 Oct 30 2018 /etc/default/useradd
[root@qls ~]
MAIL_DIR /var/spool/mail
PASS_MAX_DAYS 99999
PASS_MIN_DAYS 0
PASS_MIN_LEN 5
PASS_WARN_AGE 7
UID_MIN 1000
UID_MAX 60000
SYS_UID_MIN 201
SYS_UID_MAX 999
GID_MIN 1000
GID_MAX 60000
SYS_GID_MIN 201
SYS_GID_MAX 999
CREATE_HOME yes
UMASK 077
USERGROUPS_ENAB yes
ENCRYPT_METHOD SHA512
[root@qls ~]
GROUP=100
HOME=/home
INACTIVE=-1
EXPIRE=
SHELL=/bin/bash
SKEL=/etc/skel
CREATE_MAIL_SPOOL=yes
-bash-4.2
/root
-bash-4.2
-bash-4.2
密码管理
passwd
passwd
passwd username
root用户可以给任意用户设置密码,密码没有要求
普通用户只能针对自己设置密码,密码必须最低是8位,且结构不能太简单
非交互设置密码
[root@qls ~]
随机密码
[root@qls ~]
[root@qls ~]
[root@qls ~]
用户组
基本组,一个用户只能有一个基本组
附加组,用户有多个附加组
用户组相关配置文件
[root@qls ~]
-rw-r--r--. 1 root root 670 Aug 17 11:29 /etc/group
[root@qls ~]
----------. 1 root root 524 Aug 17 11:29 /etc/gshadow
[root@qls ~]
root:x:0:
root
x
0
4列
[root@qls ~]
root:::
组相关命令
groupadd
选项
-g
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
uid=888(user-1) gid=1005(test-1) groups=1005(test-1),1006(test-2)
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
uid=888(user-1) gid=1005(test-1) groups=1005(test-1),1006(test-2),1007(test-3)
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
uid=888(user-1) gid=1005(test-1) groups=1005(test-1),1008(test-4)
groupmod
选项
-g
-n
groupdel
用户组不属于任何用户的基本组,可以删除,否则,不能删除
解决删除用户组属于用户的基本组
1.修改该用户的基本组
2.删除用户组下面的用户。
查看用户的信息
id
[root@qls ~]
root
[root@qls ~]
0
w
who
whoami
用户授权
su
su 和 su - 有什么区别
个人配置
-rw-r--r--. 1 root root 193 Aug 17 10:36 .bash_profile
-rw-r--r--. 1 root root 231 Aug 17 10:36 .bashrc
全局
[root@qls ~]
-rw-r--r--. 1 root root 1819 Oct 31 2018 /etc/profile
[root@qls ~]
[root@qls ~]
-rw-r--r--. 1 root root 2884 Aug 15 16:11 /etc/bashrc
profile
bashrc
个人和全局变量有冲突,个人优先全局
交互式shell
非交互式shell
登录式shell
非登录式shell
sudo
visudo
100 root ALL=(ALL) ALL
101 user01 ALL=(ALL) /bin/cat,/bin/yum
用户名 主机名=(角色) 权限
user01 ALL=(ALL) NOPASSWD:/bin/cat,/bin/yum
不需要输入密码