SSH: use specific key when logging in

ssh

In /home/petri/.ssh/ I have my private key called petri. When I try to connect to my server using ssh, it does not accept my private key. Running -v learns that it is not trying my key petry, but just the non-existent id_rsa and id_dsa:

$ssh server
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Offering public key: petri@office
debug1: Authentications that can continue: publickey
debug1: Offering public key: petri@office
debug1: Authentications that can continue: publickey
debug1: Offering public key: petri@office
debug1: Authentications that can continue: publickey
debug1: Offering public key: petri@office
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/petri/.ssh/id_rsa
debug1: Trying private key: /home/petri/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

The odd thing is that things were fine before. Anyway, how do I tell SSH to use my petri key and quite trying the non-existent standard keys?

NOTE: my .ssh folder is chmod 700 and the petri file is 600, that is not the problem.

Best Answer

Two ways:

  1. Specify the key in your ssh command, something like "ssh -i ~/.ssh/petri server.example.com"

  2. Create a .ssh/config file with something like:

Host *

IdentityFile /home/petri/.ssh/petri

For more options, do a "man ssh_config" or "man ssh", depending on which you want to do.