Linux用户管理

通过本文掌握centos7/rhel7用户、用户组的管理,用户策略管理。

步骤:
1、 为保证安全,强制所有用户至少每60天必须修改一次密码
2、 新建一个名为instructors的用户组,GID为30000
3、 新建三个用户,gorwell、rbradbury、dadams,密码均为firstpw
4、 设置刚才新建的三个用户使用期限为60天,60天后不允许再登陆使用
5、 更改gorwell账户的密码策略,要求其10天修改一次密码
6、 强制所有用户首次登陆必须修改密码

参考命令:

1、通过vi打开新建用户默认设置文件,将密码更改时间设置为60天

[root@localhost ~]# vi /etc/login.defs
Linux用户管理

新建用户进行测试
`[root@localhost test]# useradd test111 添加用户名为test111的用户
[root@localhost test]# passwd test111 为用户test111设置密码,接下来输入两次密码
注:密码太简单系统会提示,但不影响配置

然后crt上用test111登陆,或直接在虚拟机上用test111登陆
[root@localhost ~]# timedatectl set-ntp no 关闭NTP自动同步时间
[root@localhost ~]# timedatectl set-time 2018-01-01 手动修改系统日期
[root@localhost ~]# date 查看系统时间
2018年 01月 01日 星期一 00:00:02 CST
因为已超过60天,test111会被禁止登陆,并提示密码过期需重新设置

Linux用户管理
su命令为从test用户切换到test111用户
因为从root切换至普通用户无需输入密码,所以从root切换到test,再从test切换至test111进行测试

2、 新建用户组

[root@localhost ~]# groupadd -g 30000 instructors
[root@localhost ~]# tail -5 /etc/group
tcpdump:x:72:
ttt:x:1000:
test:x:1001:
test111:x:1002:
instructors:x:30000:
[root@localhost ~]#

groupadd –g 建立用户组,用户组有组名和组id,-g是手动指定组id,组名和组id的对应关系在/etc/group文件中

3、 添加用户进相应用户组

[root@localhost ~]# useradd -G instructors gorwell
[root@localhost ~]# useradd -G instructors rbradbury
[root@localhost ~]# useradd -G instructors dadams
[root@localhost ~]# tail -5 /etc/group
test111:x:1002:
instructors:x:30000:gorwell,rbradbury,dadams
gorwell:x:1003:
rbradbury:x:1004:
dadams:x:1005:
useradd –G,useradd为添加用户 –G为将用户添加进某个附属组(也叫补充组),用户只可以属于一个基本组(也叫主组),但可以属于多个附属组。用户拥有主组合附属组的所有权限。用户可以从附属组中删除,但不能从基本组中删除。
useradd -g ,可指定用户加入的基本组,基本组信息在/etc/passwd文件查看

4、 密码时效管理

[root@localhost ~]# date -d "+60days"
2017年 05月 15日 星期一 14:05:19 CST
[root@localhost ~]# chage -E 2017-05-15 gorwell
[root@localhost ~]# chage -E 2017-05-15 rbradbury
[root@localhost ~]# chage -E 2017-05-15 dadams
chage –E 用来指定用户密码到期时间,到指定日期必须更新密码

5、 设置密码策略

Linux用户管理
chage -M 设置密码保持最长天数
chage -l 显示用户密码策略

6、 要求用户登陆时立即修改密码

[root@localhost ~]# chage -d 0 gorwell
chage -d为手动修改上次用户设置密码的时间,0为默认时间1970年1月1日,等于要求用户登陆时立即修改密码

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

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

余额充值