ssh|為什么通過公鑰進(jìn)行授權(quán)后仍然需要密碼才能登陸?

遠(yuǎn)程登陸主機每次輸入密碼是一個繁瑣的事情,但我們可以通過將公鑰放到遠(yuǎn)程主機上進(jìn)行授權(quán)實現(xiàn)無密碼登陸。

然而有時候出現(xiàn)這種情況,我們已經(jīng)合理地配置好了,但登陸時仍然需要密碼。這主要是遠(yuǎn)程主機的目錄或文件權(quán)限上出現(xiàn)了問題,Linux防止篡改,當(dāng)ssh相關(guān)目錄或文件允許除本人以外的人有寫入權(quán)限時,就必須使用密碼。

我今天就出了這個幺蛾子,百度和谷歌了一大推,但是沒有解決問題。中文博文主要討論2個關(guān)鍵點,~/.ssh目錄只允許自己可寫入,以及authorized_keys文件也只允許自己可寫入。

stackexange上的一個回答讓我第一時間發(fā)現(xiàn)問題所在:

  • Your home directory ~, your ~/.ssh directory and the ~/.ssh/authorized_keys file on the remote machine must be writable only by you: rwx------ and rwxr-xr-x are fine, but rwxrwx--- is no good1, even if you are the only user in your group (if you prefer numeric modes: 700 or 755, not 775).
    If ~/.ssh or authorized_keys is a symbolic link, the canonical path (with symbolic links expanded) is checked.
  • Your ~/.ssh/authorized_keys file (on the remote machine) must be readable (at least 400), but you'll need it to be also writable (600) if you will add any more keys to it.
  • Your private key file (on the local machine) must be readable and writable only by you: rw-------, i.e. 600.

鏈接:https://unix.stackexchange.com/questions/36540/why-am-i-still-getting-a-password-prompt-with-ssh-with-public-key-authentication

我的家目錄給了同組的人寫權(quán)限,就是該問題導(dǎo)致ssh認(rèn)證失敗!

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
【社區(qū)內(nèi)容提示】社區(qū)部分內(nèi)容疑似由AI輔助生成,瀏覽時請結(jié)合常識與多方信息審慎甄別。
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點,簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

相關(guān)閱讀更多精彩內(nèi)容

友情鏈接更多精彩內(nèi)容