从2个命令简单聊聊CentOS账户锁定原理

简介:

实验环境

#uname -a

Linux a69.hunk.edu 2.6.32-696.el6.x86_64 #1 SMP Tue Mar 21 19:29:05 UTC 2017 x86_64 x86_64 x86_64 GNU/Linux

#cat /etc/redhat-release

CentOS release 6.9 (Final)

passwd命令

-l, --lock              lock the password for the named account (root only)

-u, --unlock            unlock the password for the named account (root only)

usermod命令

-L, --lock                    lock the user account

-U, --unlock                  unlock the user account

创建用户user1和user2

#useradd user1

#useradd user2

修改2个用户的密码

#echo 123456|passwd --stdin user1

Changing password for user user1.

passwd: all authentication tokens updated successfully.

#echo 123456|passwd --stdin user2

Changing password for user user2.

passwd: all authentication tokens updated successfully.

分别登录测试,正常。

spacer.gif26f355e5b1c941483453a951476d7a69.png-wh_

spacer.gifb86c4fed34224821e848a54fcec84195.png-wh_

查看user1和user2在/etc/shadow下的密码栏位,均显示正常。

spacer.gif1e9c675ce98358b1ae2c27dc385a4862.png-wh_

将最后2栏导出到文件以便后续对比old1.txt

#tail -2 /etc/shadow > /app/old1.txt

实验一

使用passwd -l 锁定与解锁user1

1.使用passwd锁定user1

#passwd -l user1

Locking password for user user1.

passwd: Success

2.将变化后的数据导出以新文件new1.txt

#tail -2 /etc/shadow > new1.txt

3.对比,新文件增加了2个字节,

spacer.gif6b7140bf085108354c4cc6cf0234ec99.png-wh_

使用文本对比工具,发现左边的new1.txt在密码栏多出了2个!(叹号)

spacer.gif826712b3533383f766af8313723a003c.png-wh_

4.无法登陆

spacer.gifd9d394830e1d2625dfe7bb2b0640cbec.png-wh_

5.使用passwd解锁user1

#passwd -u user1

Unlocking password for user user1.

passwd: Success

6.将变化后的数据导出以新文件renew.txt

#tail -2 /etc/shadow > renew.txt

左边为renew.txt,比右边的new1.txt少了2个!(叹号)

spacer.gif36c2c7f102ebd0ddb96496eb274150b6.png-wh_

7.系统正常登录

a671e64920cbb90cb464772fede0334a.png-wh_

实验二

使用passwd -l 锁定与解锁user2

1.使用usermod锁定user2

#usermod -L user2

2.将变化后的数据导出以新文件new2.txt

#tail -2 /etc/shadow > new2.txt

3.对比,新文件增加了1个字节

spacer.gif5e5181feaef0d615a04a173ae4f048fc.png-wh_

使用文本对比工具,发现左边的new2.txt在密码栏多出了1个!(叹号)

spacer.gif3880529488420b2e8fd4e239b765cb6c.png-wh_

4.无法登陆

spacer.gif86e84e688a928af0d4eb8e89f732c293.png-wh_

5.使用usermod解锁user2

#usermod -U user2

6.将变化后的数据导出以新文件renew2.txt

#tail -2 /etc/shadow > renew2.txt

左边为renew2.txt,比右边的new2.txt少了1个!(叹号)

spacer.gif36ee1ca57847c87bfcbba3443e37a0de.png-wh_

7.系统正常登录

spacer.gif16b7510947cc1dc26e9e5c6255f461d3.png-wh_

实验三

使用passwd 锁定user1,再使用usermod 解锁user1

1.使用passwd锁定user1

#passwd -l user1

2.无法登录

02ffecc0724d0300446037b35118ef12.png-wh_spacer.gif

3.使用usermod解锁user1

#usermod -U user1

4..将变化后的数据导出以新文件pL2mU.txt

#tail -2 /etc/shadow > pL2mU.txt

5.对比,新文件减少了2个字节

555bc87700ce8ace10c6b2555a8eb4bf.png-wh_spacer.gif

使用文本对比工具,发现左边的pL2mU.txt在密码栏减少了2个!(叹号)

spacer.gifecf757aabd42a510f391bcde3f4eac49.png-wh_

6.系统正常登录

spacer.gif8816e60bc4c16cfdd4b7a5cf7174deb5.png-wh_

实验四

使用usermod 锁定user2,再使用passwd 解锁user2

1.使用usermod锁定user2

#usermod -L user2

2.无法登录

spacer.gif2f4a4f1998eaa3bad29331454cc4b959.png-wh_

3.因为部分对比上面的实验中已经有数据了,这里就不再重复对比了。

会在密码栏减少了2个!(叹号)

4.使用passwd解锁user2

#passwd -u user2

Unlocking password for user user2.

passwd: Success

5.正常登录

spacer.gif7d06ea62f63222d03162be14454cc460.png-wh_

总结:

passwd -l与usermod -L没有什么区别,作用都是让用户账户密码暂时失效(也就是锁定)。

锁定的原理就是在/etc/shadow第二栏(代表用户密码)最前面加上2个叹号(!),让密码暂时失效。

因为linux帐户的密码是经过特殊加密的,每一种加密方式产生的密码长度和格式是相同的,加上叹号使之暂时失效。

使用相应的passwd -u 或usermod -U进行解锁

较旧的版本,usermod -L 一次只能去除一个!(叹号)。在新版本已经修正此不规范了。

谢谢阅读。




本文转自 ljpwinxp 51CTO博客,原文链接:http://blog.51cto.com/191226139/1982625
相关文章
|
24天前
|
Linux 网络安全
Centos 防火墙端口控制命令
Centos 防火墙端口控制命令
29 3
|
6月前
|
Linux Windows
Centos和Windows进程相关命令
Centos 杀死同名的全部进程命令:ps -efww|grep 进程名 |grep -v grep|cut -c 9-15|xargs kill -9 Centos 查看同名的全部进程数命令:ps -ef | grep 进程名 | wc -l Windows杀死同名进程命令:taskkill /F /IM chrome.exe Windows查看同名进程命令:tasklist /fi "...
51 0
|
5月前
|
存储 关系型数据库 Linux
Linux之centos7安装配置及Linux常用命令
Linux之centos7安装配置及Linux常用命令
219 0
|
17天前
|
网络协议 应用服务中间件 Linux
centos7 Nginx Log日志统计分析 常用命令
centos7 Nginx Log日志统计分析 常用命令
33 2
|
1月前
|
监控 网络协议 Linux
Linux 命令大全 & CentOS常用运维命令
Linux 命令大全 & CentOS常用运维命令
157 0
|
1月前
|
关系型数据库 MySQL 数据库
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
虚拟机Linux-Centos系统网络配置常用命令+Docker 的常用命令
45 0
|
5月前
|
安全 Unix Linux
Centos虚拟机安装配置与MobaXterm工具及Linux常用命令(下)
Centos虚拟机安装配置与MobaXterm工具及Linux常用命令(下)
138 0
|
5月前
|
Unix Linux 开发工具
【Linux】centos7安装配置及Linux常用命令
【Linux】centos7安装配置及Linux常用命令
171 1
|
5月前
|
关系型数据库 MySQL Linux
CentOS mysql常用命令
CentOS mysql常用命令
57 0
|
3月前
|
消息中间件 Java Kafka
Apache Kafka-初体验Kafka(02)-Centos7下搭建单节点kafka_配置参数详解_基本命令实操
Apache Kafka-初体验Kafka(02)-Centos7下搭建单节点kafka_配置参数详解_基本命令实操
60 0

热门文章

最新文章