0

I have a private key inside /home/myuser/.ssh/privateKey

I have a problem connecting to the ssh server, because i always get:

Permission denied (publickey).

I tried to debug the problem and i find that ssh is reading wrong file, take a look at the output:

[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.

as you can see ssh is trying to read: /home/damiano/.ssh/id_rsa but i don't have this file, i named it differently. How could I tell to SSH to use the correct private key file?

Thanks!

3 Answers 3

9

You can override this with a personal config file and point to your keyfile;

vi ~/.ssh/config

And then you can append the following;

Host vps1
IdentityFile ~/.ssh/privateKey

Tip: I usually have to following set before any host declaration, it will try your default key first, then it will look in the folder ~/.ssh/$hostname/$userid and finally in ~/.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
6

You need to use:

ssh -i <Key file>
0

Even after setting the options suggested by Mark, I also had to set IdentitiesOnly yes to make sure ONLY the specified key was used.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .