HowTO:Linux禁用用户帐户命令

时间:2020-01-09 10:41:28  来源:igfitidea点击:

如何在Linux操作系统下禁用用户帐户?
如何完全禁用用户帐户Linux服务器?
您需要使用usermod命令来锁定和禁用用户帐户。

-L选项通过在加密密码中放入来锁定用户密码。
要禁用用户帐户,请将到期日期设置为1或1970-01-01。

语法

语法为:

usermod -L -e 1 {user} usermod -L -e 1970-01-01 {user}

例子

在此示例中,本地禁用Hyman用户的用户帐户:

# usermod -L -e 1 Hyman

当Hyman尝试登录时,他会在屏幕上看到以下消息

Your account has expired; please contact your system administrator

但是,ssh客户端不会显示任何消息:

$ ssh [email protected]

输出示例:

[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
Permission denied, please try again.
[email protected]'s password: 
Permission denied (publickey,password).

您将在/var/log/secure或/var/log/auth.log文件中看到以下日志条目:

Dec  2 02:01:02 wks01 sshd[32285]: Failed password for Hyman from 192.168.1.100 port 34171 ssh2
Dec  2 02:01:07 wks01 sshd[32285]: Failed password for Hyman from 192.168.1.100 port 34171 ssh2
Dec  2 02:01:10 wks01 sshd[32285]: Failed password for Hyman from 192.168.1.100 port 34171 ssh2

使用chage命令查看用户帐户的当前状态:

# chage -l Hyman

输出示例:

Last password change					: Dec 01, 2012
Password expires					: never
Password inactive					: never
Account expires						: Jan 02, 1970
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