遠(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~/.sshdirectory and the~/.ssh/authorized_keysfile on the remote machine must be writable only by you:rwx------andrwxr-xr-xare fine, butrwxrwx---is no good1, even if you are the only user in your group (if you prefer numeric modes:700or755, not775).
If~/.sshorauthorized_keysis a symbolic link, the canonical path (with symbolic links expanded) is checked. - Your
~/.ssh/authorized_keysfile (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.
我的家目錄給了同組的人寫權(quán)限,就是該問題導(dǎo)致ssh認(rèn)證失敗!