從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 19:22
下一篇 2017-11-17 09:46

相關推薦

  • 馬哥教育網絡班21期+第六周課程練習

    第六周作業 1、復制/etc/rc.d/rc.sysinit文件至/tmp目錄,將/tmp/rc.sysinit文件中的以至少一個空白字符開頭的行的行首加#; cp /etc/rc.d/rc.sysinit /tmpvim /tmp/rc.sysinit # 命令模式下,輸入一下內容:%s@\(^[[:space:]]…

    Linux干貨 2016-10-17
  • 基于Keepalived+Nginx實現高可用負載均衡

    練習貼,測試keepalived+lvs_dr高可用負載均衡

    2017-12-11
  • Linux網站架構系列之Mysql—-部署篇

    原創作品,允許轉載,轉載時請務必以超鏈接形式標明文章 原始出處 、作者信息和本聲明。否則將追究法律責任。http://nolinux.blog.51cto.com/4824967/1321079   MySQL是一個關系型數據庫管理系統,由瑞典MySQL AB公司開發,目前屬于Oracle公司。MySQL所使用的SQL語言是用于…

    Linux干貨 2015-04-01
  • 軟鏈接,硬鏈接區別

    軟硬鏈接涉及文件系統inode, 區分于inode號,硬鏈接inode號與鏈接文件相同,且創建鏈接不占空間.而軟鏈接占名稱字節個空間,且inode號與鏈接文件不同; 兩者查找inode號命令都可查找inode號,命令為ls -i,如需查找本目錄要加d; 在創建鏈接環境上,硬鏈接只能在同分區創建一個,不能跨分區創建;而軟鏈接可以跨分區創建多個鏈接文件且可以多個…

    Linux干貨 2016-10-20
  • 在學習的過程中,我們應該如何獲取幫助?

    正文 在學習的過程當中,我們總是遇到不會使用的問題,以各種姿勢來獲取幫助是一個運維人員的基本要求 在Linux系統中我們獲取幫助主要有以下幾種方式 1. 使用命令內建的選項來獲取幫助 2. 使用man來查看命令使用手冊 3. 使用info來查看命令的信息頁 4. 查看軟件自帶的幫助文檔 5. 查看軟件官方的文檔 6. 查看發行版本的文檔 7. Google相…

    Linux干貨 2016-03-04
  • 13-高級文件系統管理-Quota,RAID,LVM

    配置配額系統     綜述         在內核中執行         以文件系統(磁盤分區)為單位啟用         對不同組或者用戶的策略不同         根據塊或者節…

    2017-03-16
欧美性久久久久