如何使用正确的SSH私钥?

我在/home/myuser/.ssh/privateKey中有一个私钥

我有一个连接到ssh服务器的问题,因为我总是得到:

Permission denied (publickey). 

我试图debugging的问题,我发现SSH读取错误的文件,看看输出:

 [damiano@Damiano-PC .ssh]$ ssh -v root@vps1 OpenSSH_5.8p2, OpenSSL 1.0.0g-fips 18 Jan 2012 debug1: Reading configuration data /etc/ssh/ssh_config debug1: Applying options for vps1 debug1: Applying options for * debug1: Connecting to 111.111.111.111 [111.111.111.111] port 2000. debug1: Connection established. debug1: identity file /home/damiano/.ssh/id_rsa type -1 debug1: identity file /home/damiano/.ssh/id_rsa-cert type -1 debug1: identity file /home/damiano/.ssh/id_dsa type -1 debug1: identity file /home/damiano/.ssh/id_dsa-cert type -1 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.8p1 Debian-7ubuntu1 debug1: match: OpenSSH_5.8p1 Debian-7ubuntu1 pat OpenSSH* debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_5.8 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: Server host key: RSA 74:8f:87:fe:b8:25:85:02:d4:b6:5e:03:08:d0:9f:4e debug1: Host '[111.111.111.111]:2000' is known and matches the RSA host key. debug1: Found key in /home/damiano/.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: Roaming not allowed by server debug1: SSH2_MSG_SERVICE_REQUEST sent debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey debug1: Next authentication method: publickey debug1: Trying private key: /home/damiano/.ssh/id_rsa debug1: Trying private key: /home/damiano/.ssh/id_dsa debug1: No more authentication methods to try. 

正如你可以看到ssh试图阅读: /home/damiano/.ssh/id_rsa但我没有这个文件,我命名它不同。 我怎么能告诉SSH使用正确的私钥文件?

谢谢!

你可以用个人configuration文件覆盖这个文件并指向你的密钥文件;

 vi ~/.ssh/config 

然后你可以附加下面的内容。

 Host vps1 IdentityFile ~/.ssh/privateKey 

提示:我通常必须在任何主机声明之前进行设置,它会首先尝试默认密钥,然后在〜/ .ssh / $ hostname / $ userid文件夹中查找,最后在〜/ .ssh / $ hostname;

 IdentityFile ~/.ssh/id_rsa IdentityFile ~/.ssh/id_dsa IdentityFile ~/.ssh/%h/%r/id_rsa IdentityFile ~/.ssh/%h/%r/id_dsa IdentityFile ~/.ssh/%h/id_rsa IdentityFile ~/.ssh/%h/id_dsa 

你需要使用:

 ssh -i <Key file> 

即使在设置Mark提示的选项后,我也必须设置IdentitiesOnly yes以确保只使用指定的键。