Linux

禁用 SSH 的密碼登錄與刪除所有使用者的密碼相同嗎?

  • October 30, 2013

我有一個只有 root 使用者的雲伺服器。我只使用 RSA 密鑰 SSH 到它。為了使其更安全,我想禁用密碼功能。我知道這可以通過編輯/etc/ssh/sshd_config文件並更改PermitRootLogin yesPermitRootLogin without-password. 我想知道是否簡單地刪除 root 密碼 viapasswd -d root將是等效的(假設我沒有創建更多使用者或新使用者也刪除了他們的密碼)。一種方法與另一種方法相比是否存在任何安全問題?

使用公鑰認證繞過了其他認證方法,所以沒有必要使用PermitRootLogin without-password,如果有人嘗試以 root 身份登錄並且沒有被強制提供公鑰,這是很危險的。

要完成您想要的,在 sshd 中禁用密碼身份驗證,PasswordAuthentication no請在您的sshd_config.

此設置不會影響/etc/shadow儲存使用者密碼的內容。如果另一個應用程序想要通過密碼進行身份驗證(例如 CUPS),這仍然可以工作。

如果要禁用此功能,使用上述命令刪除使用者密碼將不起作用。它允許給定使用者無密碼登錄,這絕對不會增加安全性。

發行passwd -l <user>將完成您的預期。請記住,除了 ssh 之外的其他應用程序可能會遇到問題,因為它們希望在預設設置(sudo、su、CUPS 等)中使用密碼驗證。

引自man passwd

-l, --lock
          Lock the password of the named account. This option disables a password by changing it to a value which matches no possible encrypted value (it adds a ´!´ at the beginning of the password).

          Note that this does not disable the account. The user may still be able to login using another authentication token (e.g. an SSH key). To disable the account, administrators should use usermod
          --expiredate 1 (this set the account's expire date to Jan 2, 1970).

          Users with a locked password are not allowed to change their password.

引用自:https://serverfault.com/questions/549582