Linux 创建账号、设置有效期及提权

374 阅读1分钟

1. 创建账号

# 创建账号
adduser -d /opt/test test
# 设置新密码
passwd test

2. 账号有效期设置为永久

# 查询账号有效期
chage -l hdc
# 修改帐号有效期
chage -M 99999 test

默认情况下,账号建立后,有效期限是永久的。注意下面命令结果:

root@dev ~]# chage -l test
Last password change : Oct 26, 2016
Password expires : never
Password inactive : never
Account expires : never
Minimum number of days between password change : 0
Maximum number of days between password change : 99999
Number of days of warning before password expires : 7

Last password change:表示账号创建时的时间
Account expires:表示账号到期时间

3. 帐号提权

给 test 帐号提权,提权后可以使用 sudo su 切换到 root
chmod u+w /etc/sudoers
vi /etc/sudoers +100
root ALL=(ALL) ALL
test ALL=(ALL) NOPASSWD: ALL
chmod u-w /etc/sudoers