2016-01-05 260 views
-1

我設置了公鑰訪問的ssh,我想我已經正確配置了sshd_config並生成了id_rsa.pub和authorized_keys。通過公鑰的ssh密鑰登錄

ssh-kengen -t rsa 
cd .ssh 
cat id_rsa.pub >> authorized_keys 

我還設置了權限,這些文件

chmod 700 ~/.ssh 
chmod 600 ~/.ssh/authorized_keys 

當我嘗試sudo ssh localhost,它的工作原理,沒有密碼被問過,但以root身份登錄。

但是,當我嘗試ssh localhost時,它仍在要求輸入密碼。在此期間產生的

日誌: -

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013 
debug1: Reading configuration data /etc/ssh/ssh_config 
debug1: Applying options for * 
debug1: Connecting to localhost [127.0.0.1] port 22. 
debug1: Connection established. 
debug1: identity file /home/cwei/.ssh/identity type -1 
debug1: identity file /home/cwei/.ssh/identity-cert type -1 
debug1: identity file /home/cwei/.ssh/id_rsa type 1 
debug1: identity file /home/cwei/.ssh/id_rsa-cert type -1 
debug1: identity file /home/cwei/.ssh/id_dsa type -1 
debug1: identity file /home/cwei/.ssh/id_dsa-cert type -1 
debug1: identity file /home/cwei/.ssh/id_ecdsa type -1 
debug1: identity file /home/cwei/.ssh/id_ecdsa-cert type -1 
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 
debug1: match: OpenSSH_5.3 pat OpenSSH* 
debug1: Enabling compatibility mode for protocol 2.0 
debug1: Local version string SSH-2.0-OpenSSH_5.3 
debug1: SSH2_MSG_KEXINIT sent 
debug1: SSH2_MSG_KEXINIT received 
debug1: kex: server->client aes128-ctr hmac-md5 none 
debug1: kex: client->server aes128-ctr hmac-md5 none 
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP 
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent 
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY 
debug1: Host 'localhost' is known and matches the RSA host key. 
debug1: Found key in /home/cwei/.ssh/known_hosts:1 
debug1: ssh_rsa_verify: signature correct 
debug1: SSH2_MSG_NEWKEYS sent 
debug1: expecting SSH2_MSG_NEWKEYS 
debug1: SSH2_MSG_NEWKEYS received 
debug1: SSH2_MSG_SERVICE_REQUEST sent 
debug1: SSH2_MSG_SERVICE_ACCEPT received 
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi- 
with-mic,password 
debug1: Next authentication method: gssapi-keyex 
debug1: No valid Key exchange context 
debug1: Next authentication method: gssapi-with-mic 
debug1: Unspecified GSS failure. Minor code may provide more information 
Credentials cache file '/tmp/krb5cc_604' not found 
debug1: Unspecified GSS failure. Minor code may provide more information 
Credentials cache file '/tmp/krb5cc_604' not found 
debug1: Unspecified GSS failure. Minor code may provide more information 
debug1: Unspecified GSS failure. Minor code may provide more information 
Credentials cache file '/tmp/krb5cc_604' not found 
debug1: Next authentication method: publickey 
debug1: Trying private key: /home/cwei/.ssh/identity 
debug1: Offering public key: /home/cwei/.ssh/id_rsa 
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password 
debug1: Trying private key: /home/cwei/.ssh/id_dsa 
debug1: Trying private key: /home/cwei/.ssh/id_ecdsa 
debug1: Next authentication method: password 
[email protected]'s password: 
+0

您能否提供'authorized_keys'創建的絕對路徑?什麼是root用戶的主文件夾? –

+0

Stackoverflow是用於軟件開發的幫助。您應該考慮在http://unix.stackexchange.com/或http://superuser.com/上提問。 – Kenster

+0

檢查服務器日誌,找出您的密鑰被拒絕的原因。同時檢查'authorized_keys'文件的權限以確保它是正確的。 – Jakuje

回答

1

SSH公用密鑰訪問是基於用戶的。該配置可以爲root用戶完成。它需要通過配置本地用戶本地.ssh目錄來爲本地用戶完成。

+0

如何配置本地.ssh目錄?通過將sshd_config複製到.ssh? –

+1

假設你有本地用戶'chenwei','chenwei'的主目錄是'/ home/chenwei',那麼你應該把客戶端的公鑰(不帶密碼的ssh登錄)放到'/ home/chenwei/.ssh/authorized_keys'文件。您不需要複製sshd_config文件。 – cbesiktas