用户管理

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-Ae5HJ25V-1621342151394)(E:\培训\shadow字段说明)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-M2PQaEBN-1621342151399)(C:\Users\CGZ\AppData\Roaming\Typora\typora-user-images\image-20210518095138053.png)]

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-u3as5NOl-1621342151402)(C:\Users\CGZ\AppData\Roaming\Typora\typora-user-images\image-20210518095224018.png)]

指定uid添加用户(-u)
[root@oldboy ~]# useradd -u 5000 test2 #创建test2用户,并指定uid为5000
[root@oldboy ~]# id test2
uid=5000(test2) gid=5000(test2) 组=5000(test2)

3)指定用户的登录shell(-s)
[root@oldboy ~]# useradd -s /sbin/nologin test3 #创建test3用户,禁止登录
[root@oldboy ~]# id test3
uid=5001(test3) gid=5001(test3) 组=5001(test3)
[root@oldboy ~]# tail -1 /etc/passwd
test3❌5001:5001::/home/test3:/sbin/nologin
[root@oldboy ~]# su - test3
This account is currently not available.
企业应用:配置网络服务时候,编译安装需要,创建虚拟用户。

4)指定用户家目录(-d)
[root@oldboy ~]# useradd -d /opt test4
useradd:警告:此主目录已经存在。
不从 skel 目录里向其中复制任何文件。
[root@oldboy ~]# tail -1 /etc/passwd
test4❌5002:5002::/opt:/bin/bash
su - test4
正常报错
-bash-4.1$ ##缺少用户环境变量所致。

范例14-1:使用oldboy用户登录到Linux系统后,发现提示符为如下所示异常情况,
请问如何恢复到正常的Linux命令行提示符情况?
-bash-4.1$
-bash-4.1$

4)添加用户指定属于其他用户组(-g)
[root@oldboy ~]# useradd test5 -g root #添加用户属于root组。
[root@oldboy ~]# id test5
uid=5004(test5) gid=0(root) 组=0(root)

5)添加用户设置过期时间(-e)
企业应用:给非运维人员设置用户登录的固定期限,到期了自动无法登陆。
[root@oldboy ~]# date
2030年 05月 18日 星期六 12:07:59 CST
[root@oldboy ~]# useradd -e “2030/05/30” test6
[root@oldboy ~]# passwd test6
更改用户 test6 的密码 。
新的 密码:
无效的密码: 密码少于 8 个字符
重新输入新的 密码:
passwd:所有的身份验证令牌已经成功更新。

[root@oldboy ~]# date -s “2030/06/01”
2030年 06月 01日 星期六 00:00:00 CST

[root@oldboy ~]# ssh test6@127.0.0.1 #SSH客户端类似xshell。
test6@127.0.0.1’s password:
Your account has expired; please contact your system administrator
Authentication failed.

[外链图片转存失败,源站可能有防盗链机制,建议将图片保存下来直接上传(img-wmQKLNbZ-1621342151408)(C:\Users\CGZ\AppData\Roaming\Typora\typora-user-images\image-20210518111154359.png)]

usermod 修改用户====================
-u 指定UID
-g 指定属于的组
-e 指定过期时间
-d 指定家目录
-M 不创建家目录
-s 指定登录的解释器

1)修改test1的UID
[root@oldboy ~]# id test1
uid=1001(test1) gid=1001(test1) 组=1001(test1)
[root@oldboy ~]# usermod -u 10001 test1
[root@oldboy ~]# id test1
uid=10001(test1) gid=1001(test1) 组=1001(test1)
UID已改,组ID没改。

2)修改test2属于的新组root
[root@oldboy ~]# usermod -g root test2
[root@oldboy ~]# id test2
uid=5000(test2) gid=0(root) 组=0(root)

3)#修改过期时间为2031/7/18
[root@oldboy ~]# id test6
uid=5005(test6) gid=5005(test6) 组=5005(test6)
[root@oldboy ~]# chage -l test6 #查看密码的属性,间接看/etc/shadow内容
最近一次密码修改时间 :5月 18, 2030
密码过期时间 :从不
密码失效时间 :从不
帐户过期时间 :5月 30, 2030
两次改变密码之间相距的最小天数 :0
两次改变密码之间相距的最大天数 :99999
在密码过期之前警告的天数 :7

[root@oldboy ~]# usermod -e “2031/7/18” test6 #修改过期时间为2031/7/18
[root@oldboy ~]# chage -l test6
最近一次密码修改时间 :5月 18, 2030
密码过期时间 :从不
密码失效时间 :从不
帐户过期时间 :7月 18, 2031
两次改变密码之间相距的最小天数 :0
两次改变密码之间相距的最大天数 :99999
在密码过期之前警告的天数 :7

4)更改test3解释器为/bin/bash(-s)
[root@oldboy ~]# grep test3 /etc/passwd
test3❌5001:5001::/home/test3:【/sbin/nologin】

[root@oldboy ~]# usermod -s /bin/bash test3
[root@oldboy ~]# grep test3 /etc/passwd
test3❌5001:5001::/home/test3:【/bin/bash】

输能力,不输人品。

=userdel用户删除==
-r 删除家目录,有风险的。

[root@oldboy ~]# userdel -r test6
[root@oldboy ~]# ls -l /home/
总用量 0
drwx------. 3 oldboy oldboy 121 5月 30 21:01 oldboy
drwx------. 2 10001 1001 62 5月 18 11:47 test1
drwx------. 2 test3 test3 62 5月 18 11:55 test3
drwxr-xr-x. 2 root root 6 6月 30 00:52 test4
drwx------. 2 test5 root 62 5月 18 12:06 test5

企业应用:人员离职,他的用户怎么管?
a.userdel -r 离职人员 #容易把离职人员数据删除。不明智

6 6月 30 00:52 test4
drwx------. 2 test5 root 62 5月 18 12:06 test5

企业应用:人员离职,他的用户怎么管?
a.userdel -r 离职人员 #容易把离职人员数据删除。不明智

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

加油干sit!

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值