linux下設定了SSH免密碼登入但還是需要輸入密碼的解決辦法
阿新 • • 發佈:2019-01-06
今天在設定linux的免密碼登入後,仍然需要輸入密碼,後來找到了原因,是因為使用者沒有許可權修改.ssh目錄下的know_hosts檔案導致的。
具體情況是這樣的:
在/home/username/.ssh輸入以下命令後:
#ssh-keygen -t rsa -P '' -f id_rsa
#cat id_rsa.pub >> authorized_keys
#ssh localhost
出現下面命令
[email protected] ~ $ ssh localhost
The authenticity of host 'localhost
(::1)' can't be established.
RSA key fingerprint is 6e:6b:0f:2a:b8:91:3f:c8:f0:39:e4:df:b4:d8:16:6b.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost
(::1)
' (RSA) to the list of known hosts.
[email protected]'s password:
仍然讓我輸入密碼,這時應該修改一下.ssh的使用者和許可權
- chown username: /home/username/.ssh
- chown username: /home/username/.ssh/*
- chmod 700 /home/username/.ssh
- chmod 600 /home/username/.ssh/*
這樣一切就可以直接免密碼登入了。