I created a key to connect in SSH with a passphrase. I have named my key id_rsa_admin. When I log in, the following message is displayed Permission denied (publickey).

In the logs, I find that ssh looks for a file id_rsa and therefore does not find the right file.

I find that if the key is not named id_rsa it does not work.

How to connect in ssh ?


ssh admin@vps718449.ovh.net -p 9215

Arronical's answer is good for a one-time connection, but would be painful in the long term. In order to make ssh always use this key when connecting to this server, you can add this to your ~/.ssh/config (or create it if it does not exist):

Host vps718449.ovh.net
    IdentityFile ~/.ssh/id_rsa_admin

Then you can connect with just ssh admin@vps718449.ovh.net -p 9215. As an added bonus you can also configure the port:

Host vps718449.ovh.net
    IdentityFile ~/.ssh/id_rsa_admin
    Port 9215

Then you can connect with just ssh admin@vps718449.ovh.net. Even further:

Host vps718449.ovh.net vps
     Hostname vps718449.ovh.net
     User admin
     IdentityFile ~/.ssh/id_rsa_admin
     Port 9215

Then just ssh vps will work! Of course vps is just an example, you can use any other alias you want (for example if you have more than one VPS). See man ssh_config for a list of the options you can set there.

| improve this answer | |
  • @fkraiem thank you. How to do with three keys ? – Mathieu Dec 15 '16 at 16:41
  • 1
    @Mathieu Why three keys? If it's for three different hosts, just add one entry for each host, each with the appropriate key. – fkraiem Dec 15 '16 at 16:46
  • @fkraiem I have 3 different keys on the same server but for 3 user – Mathieu Dec 15 '16 at 17:23
  • @Mathieu I can't confirm this right now, but I think just adding three IdentityFile lines in the Host section should work. Also, if you put a User line, that user will become the default when connecting to that host, but you can still override it with @. – fkraiem Dec 15 '16 at 17:31
  • @fkraiem Thank you so much. It works, but the following error is displayed "Agent admitted failure to sign using the key". I use "SSH_AUTH_SOCK=0 " to connect but it must be done at each restart. Is there any other greeting ? – Mathieu Dec 15 '16 at 20:15

You need to use the -i option to your ssh command using the path to your key. The modified command will be:

ssh -i ~/.ssh/id_rsa_admin admin@vps718449.ovh.net -p 9215
| improve this answer | |
  • thank you. With your reply, the following error is displayed "ssh: Could not resolve hostname i: Name or service not known" – Mathieu Dec 15 '16 at 15:36
  • 5
    Putting -i before the hostname works too; I think @Mathieu simply forgot the hyphen. :p – fkraiem Dec 15 '16 at 15:52

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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