Server Fault is a question and answer site for system and network administrators. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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 [] 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 '[]: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_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?


share|improve this question
up vote 9 down vote accepted

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
share|improve this answer

You need to use:

ssh -i <Key file>
share|improve this answer

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

share|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.