ssh|為什麼通過公鑰進行授權後仍然需要密碼才能登陸?
遠端登陸主機每次輸入密碼是一個繁瑣的事情,因為我們可以通過將公鑰放到遠端主機上進行授權實現無密碼登陸。
- ofollow,noindex">ssh使用金鑰認證
然而有時候出現這種情況,我們已經合理地配置好了,但登陸時仍然需要密碼。這主要是遠端主機的目錄或檔案許可權上出現了問題,Linux防止篡改,當ssh相關目錄或檔案允許除本人以外的人有寫入許可權時,就必須使用密碼 。
我今天就出了這個么蛾子,百度和谷歌了一大推,但是沒有解決問題。中文博文主要討論2個關鍵點,~/.ssh
目錄只允許自己可寫入,以及authorized_keys檔案也只允許自己可寫入。
- ssh配置authorized_keys後仍然需要輸入密碼的問題
- SSH無金鑰登陸 與 配置公鑰後仍需要輸入密碼的解決方案
stackexange上的一個回答讓我第一時間發現問題所在:
-
Your home directory
~
, your~/.ssh
directory and the~/.ssh/authorized_keys
file on the remote machine must be writable only by you:rwx------
andrwxr-xr-x
are fine, butrwxrwx---
is no good¹, even if you are the only user in your group (if you prefer numeric modes:700
or755
, not775
).
If~/.ssh
orauthorized_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
.
我的家目錄給了同組的人寫許可權,就是該問題導致ssh認證失敗!