1. 用户管理命令
1. useradd == adduser
选项:
-u
-g
-G
-d
-c
-s
-r
-M
[root@qls ~]
[root@qls ~]
user01:x:1000:1000::/home/user01:/bin/bash
[root@qls ~]
user01:!!:18464:0:99999:7:::
[root@qls ~]
[root@qls ~]
user02:x:666:1001:test:/opt/user02:/bin/bash
[root@qls ~]
drwx------ 2 user02 user02 62 Jul 21 16:47 user02
[root@qls ~]
[root@qls ~]
user03:x:665:665::/home/user03:/bin/bash
[root@qls ~]
total 0
drwx------ 2 user01 user01 62 Jul 21 16:40 user01
[root@qls ~]
[root@qls ~]
user04:x:664:664::/home/user04:/sbin/nologin
[root@qls ~]
total 0
drwx------ 2 user01 user01 62 Jul 21 16:40 user01
[root@qls ~]
[root@qls ~]
user05:x:1001:1002::/home/user05:/sbin/nologin
[root@qls ~]
total 0
drwx------ 2 user01 user01 62 Jul 21 16:40 user01
2. usermod
选项:
-u
-g
-a
-G
-m
-d
-c
-s
-l
-L
-U
[root@qls ~]
[root@qls ~]
user123:x:6666:1001:123:/opt/user01:/bin/bash
[root@qls ~]
uid=6666(user123) gid=1001(user02) groups=1001(user02),665(user03),664(user04)
[root@qls ~]
[root@qls ~]
user05:x:1001:1002::/home/user05:/bin/bash
[root@qls ~]
[root@qls ~]
[root@qls ~]
Changing password for user user02.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[C:\~]$ ssh user02@10.0.0.100
Connecting to 10.0.0.100:22...
Connection established.
To escape to local shell, press 'Ctrl+Alt+]'.
Last failed login: Tue Jul 21 17:22:10 CST 2020 from 10.0.0.1 on ssh:notty
There were 4 failed login attempts since the last successful login.
Last login: Tue Jul 21 17:20:45 2020 from 10.0.0.1
[user02@qls ~]$
3. userdel
选项:
-r
[root@qls ~]
total 1016
drwx------ 2 user123 user02 62 Jul 21 16:40 user01
drwx------ 2 user02 user02 62 Jul 21 16:47 user02
[root@qls ~]
[root@qls ~]
total 1016
drwx------ 2 6666 user02 62 Jul 21 16:40 user01
drwx------ 2 user02 user02 62 Jul 21 16:47 user02
[root@qls ~]
[root@qls ~]
total 0
drwx------ 2 user06 user06 62 Jul 21 17:45 user06
[root@qls ~]
total 0
-rw-rw---- 1 user02 mail 0 Jul 21 16:47 user02
-rw-rw---- 1 user05 mail 0 Jul 21 16:55 user05
-rw-rw---- 1 user06 mail 0 Jul 21 17:45 user06
-rw-rw---- 1 6666 mail 0 Jul 21 16:40 user123
[root@qls ~]
[root@qls ~]
total 0
[root@qls ~]
total 0
-rw-rw---- 1 user02 mail 0 Jul 21 16:47 user02
-rw-rw---- 1 user05 mail 0 Jul 21 16:55 user05
-rw-rw---- 1 6666 mail 0 Jul 21 16:40 user123
[root@qls ~]
userdel: user user02 is currently used by process 8333
[root@qls ~]
user02 8333 0.0 0.1 161364 2348 ? S 17:42 0:00 sshd: user02@pts/1
root 8389 0.0 0.0 112708 976 pts/0 R+ 17:46 0:00 grep --color=auto 8333
[root@qls ~]
4. 查看用户的命令
[root@qls ~]
uid=0(root) gid=0(root) groups=0(root)
[root@qls ~]
[root@qls ~]
Login: root Name: root
Directory: /root Shell: /bin/bash
On since Tue Jul 21 17:49 (CST) on pts/0 from 10.0.0.1
7 seconds idle
No mail.
No Plan.
[root@qls ~]
root pts/0 2020-07-21 17:49 (10.0.0.1)
[root@qls ~]
root
[root@qls ~]
09:59:15 up 22:14, 1 user, load average: 0.00, 0.01, 0.05
USER TTY FROM LOGIN@ IDLE JCPU PCPU WHAT
root pts/0 10.0.0.1 17:49 ? 0.02s 0.00s w
[root@qls ~]
09:59:49 up 22:14, 1 user, load average: 0.00, 0.01, 0.05
2. 用户创建相关的文件
创建用户的时候,没有指定相关信息,系统创建用户是根据两个文件进行创建的
[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
3. 用户命令行故障
[root@qls ~]
Changing password for user test.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@qls ~]
-bash-4.2$
-bash-4.2$
-bash-4.2$ pwd
/home/test
-bash-4.2$ cp -a /etc/skel/.bash* ./
Permission denied
[root@qls ~]
[root@qls ~]
drwx------ 2 root root 6 Jul 21 10:53 /home/test
[root@qls ~]
-bash-4.2$ cd /home/test
-bash-4.2$ pwd
/home/test
-bash-4.2$ cp -a /etc/skel/.bash* ./
-bash-4.2$ logout
4. 用户的密码信息
管理员可以给任何用户设置密码 密码的长度没有限制
普通用户只能给自己设置密码 且是无规律的8位以上的密码
[root@qls ~]
[root@qls ~]
Changing password for user root.
New password:
[root@qls ~]
Changing password for user qls01.
New password:
BAD PASSWORD: The password is a palindrome
Retype new password:
passwd: all authentication tokens updated successfully.
[root@qls ~]
非交互式设置密码
--stdin
[root@qls ~]
Changing password for user qls01.
passwd: all authentication tokens updated successfully.
[root@qls ~]
28241
[root@qls ~]
6c8a1df9e12e9c553d0f9a397b860f4e -
[root@qls ~]
64091f6823
[root@qls ~]
df0676f775
[root@qls ~]
Changing password for user qls01.
passwd: all authentication tokens updated successfully.
[root@qls ~]
b676039b3f
[root@qls ~]
Changing password for user qls01.
passwd: all authentication tokens updated successfully.
[root@qls ~]
7d53328b61
tee
-a
[root@qls ~]
选项:
-l
-d
-c
-C
-s
[root@qls ~]
gC}2atTf9
[root@qls ~]
sv_^WF85J@DF5Ng5|3{f3/ng
[root@qls ~]
9px3Sesrx[ybtbvElubxxltj
[root@qls ~]
uimYw\Z4amzffhti0eljucgg
[root@qls ~]
impossible to generate 24-character password with 2 numbers, 2 lowercase letters, 2 uppercase letters and 24 special characters.
[root@qls ~]
$.$}+?;-~]|)>(
[root@qls ~]
Changing password for user qls01.
passwd: all authentication tokens updated successfully.
[root@qls ~]
:{]~"/'%[,+"^*%??%,'?}~$
5. 用户组的管理
什么是用户组
组分为两类
基本组
附加组
跟组相关的文件
[root@qls ~]
-rw-r--r-- 1 root root 573 Jul 21 11:04 /etc/group
[root@qls ~]
---------- 1 root root 449 Jul 21 11:04 /etc/gshadow
[root@qls ~]
[root@qls ~]
root:x:0:
bin:x:1:
daemon:x:2:
mail:x:12:postfix
第一列: root
第二列: x
第三列: 0
第四列:
[root@qls ~]
root:::
bin:::
daemon:::
mail:::postfix
第一列: root
第二列: !或者空
第三列: 空
第四列: 空
[root@qls ~]
[root@qls ~]
user01:x:1000:qls01
user03:x:665:qls01
user05:x:1002:qls01
qls01:x:1006:
[root@qls ~]
user01:!::qls01
user03:!::qls01
user05:!::qls01
qls01:!::
6. 用户组的相关命令
1. 创建用户组的命令 groupadd
选项:
-g
-r
[root@qls ~]
[root@qls ~]
user_group01:x:1007:
[root@qls ~]
[root@qls ~]
user_group02:x:666:
[root@qls ~]
[root@qls ~]
user_group03:x:664:
2. 修改用户组的命令 groupmod
选项:
-g
-n
[root@qls ~]
[root@qls ~]
user_group01:x:6666:
[root@qls ~]
[root@qls ~]
new_group:x:6666:
3. 删除用户组的命令 groupdel
[root@qls ~]
[root@qls ~]
[root@qls ~]
[root@qls ~]
user05:x:1002:qls01
[root@qls ~]
user05:x:1001:1002::/home/user05:/bin/bash
test:x:1002:1003::/home/test:/bin/bash
[root@qls ~]
uid=1001(user05) gid=1002(user05) groups=1002(user05)
解决:
给这里面的用户重新找个基本组
把用户也一并删除掉
[root@qls ~]
groupdel: cannot remove the primary group of user 'user05'
[root@qls ~]
[root@qls ~]
uid=1001(user05) gid=1003(test) groups=1003(test)
[root@qls ~]