Categories: Linux

Linux 強制使用者下次登入修改密碼教學

介紹如何在 Linux 系統中強制使用者在下一次登入系統時,一定要變更自己的密碼。

強制使用者變更密碼通常都是用於建立新帳號的情況,新的 Linux 帳號建立時,會設定一組初始的密碼,而基於安全考量,最好要求使用者在第一次登入之後,就變更成自己設定的密碼。

查詢使用者密碼狀態

若要查詢 Linux 使用者的密碼狀態(例如上次密碼變更日期、密碼使用期限等),可以使用 chage 指令加上 -l 參數,並指定使用者名稱,例如若要查詢 officeguide 這位使用者的密碼狀態,則可執行:

# 查詢使用者密碼狀態
chage -l officeguide
Last password change                                    : May 31, 2020
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

強制使用者變更密碼

若要強制使用者在下次登入時變更密碼,可以使用 passwd 指令加上 --expire 參數,例如:

# 強制使用者變更密碼(設定讓密碼過期)
passwd --expire officeguide

此參數的作用就是設定讓使用者的密碼過期,產生的效果就是使用者在下次登入時一定要變更密碼。設定之後,可用 chage 查詢使用者的密碼狀態:

# 查詢使用者密碼狀態
chage -l officeguide
Last password change                                    : password must be changed
Password expires                                        : password must be changed
Password inactive                                       : password must be changed
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

除了 passwd 指令之外,chage 也可以用來設定讓密碼過期:

# 強制使用者變更密碼(設定讓密碼過期)
chage --lastday 0 officeguide

參考資料:Tecmint

Share
Published by
Office Guide
Tags: 資訊安全

Recent Posts

Python 使用 PyAutoGUI 自動操作滑鼠與鍵盤

本篇介紹如何在 Python ...

9 個月 ago

Ubuntu Linux 以 WireGuard 架設 VPN 伺服器教學與範例

本篇介紹如何在 Ubuntu ...

9 個月 ago

Linux 網路設定 ip 指令用法教學與範例

本篇介紹如何在 Linux 系...

9 個月 ago

Windows 使用 TPM 虛擬智慧卡保護 SSH 金鑰教學與範例

本篇介紹如何在 Windows...

10 個月 ago

Linux 以 Shamir’s Secret Sharing 分割保存金鑰教學與範例

介紹如何在 Linux 中使用...

11 個月 ago

Linux 以 Cryptsetup、LUKS 加密 USB 隨身碟教學與範例

介紹如何在 Linux 系統中...

11 個月 ago