從2個命令簡單聊聊CentOS賬戶鎖定原理

linux中 passwd -l 和usermod -L有什么區別,各自的解鎖和鎖定原理是什么樣的呢?

實驗環境

#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 一次只能去除一個!(嘆號)。在新版本已經修正此不規范了。

謝謝閱讀。

本文出自 “金色之謎” 博客,請務必保留此出處http://191226139.blog.51cto.com/211244/1982625

本文來自投稿,不代表Linux運維部落立場,如若轉載,請注明出處:http://www.www58058.com/88465

(0)
金色之謎金色之謎
上一篇 2017-11-16
下一篇 2017-11-17

相關推薦

  • 文件查找

    文件查找: locate查找:     locate:     依賴于事先構建好的索引庫,操作系統剛完成沒有       系統自動實現(周期性任務);      &nbs…

    Linux干貨 2016-08-15
  • 數據庫基礎知識

    關系模型:結構化數據模型實體-關系模型對象關系模型:基于對象的數據模型半結構化數據模型:XML(擴展標記語言) SQL:Structure Query Language結構化查詢語言DML:數據操作語言INSERT DELETE SELECT UPDATEDDL:數據定義語言CREATE DROP ALTERDCL: 數據控制語言GRANT REVOKE R…

    Linux干貨 2017-09-25
  • VSFTP通過pam_mysql插件創建進行基于mysql的虛擬用戶

      1、對pam_mysql-0.7RC1包進行編譯安裝 編譯安裝環境配置 編譯安裝所需的包如下: ~]#yum -y groupinstall "Development Tools" "Server Platform Development" ~]#yum -y install mariadb-server…

    Linux干貨 2016-11-14
  • linux用戶和組管理

    linux系統是一個多用戶的系統,每個賬號都干什么用,你必須了如指掌。 【Linux用戶】 即UID分為兩大類:管理員 UID:0                               普通用戶 UID:…

    Linux干貨 2016-08-05
  • 馬哥網絡21-第5周作業

    1、顯示/boot/grub/grub.conf中以至少一個空白字符開頭的行; [root@localhost proc]# grep "^[[:space:]]\{1,\}" /boot/grub/grub.conf root (hd0,0) kernel /vmlinuz-2…

    Linux干貨 2016-08-08
  • 網絡管理、進程管理、計劃任務及啟動流程

          網絡管理 一.網卡模塊操作步驟: 查詢網卡模塊類型:ethtool  -i  eth1 查詢網卡模塊lsmod |grep e1000 刪除網卡模塊rmmod e1000  或者modprobe  -r  e1000 添加網卡模塊 modprobe e1000 刪除?!?/p>

    Linux干貨 2016-09-08
欧美性久久久久