how do we specify an ssh default identity?

35

10

id_rsa is normally a default key.

I've created a new key named 'keyhello'

Update: I've also added this key by doing:

ssh-add /home/myuser/.ssh/keyhello

But I believe it still isn't my default key.

So, how can we put keyhello to be the default identity, instead of the id_rsa ?

I do see a -t but I've tried:

ssh-agent /home/mysuser/.ssh/keyhello -t 

No luck with this. I get a "Permission Denied" (if I put sudo ssh-agent ... I got the same "Permission Denied w/out even prompt me my sudo pass).

MEM

Posted 2011-03-28T01:22:27.000

Reputation: 907

Answers

52

In your ~/.ssh/config file put:

IdentityFile /home/myuser/.ssh/keyhello

which will tell the outgoing ssh connections to use that as the default identity

Wes Hardaker

Posted 2011-03-28T01:22:27.000

Reputation: 1 796

2Go it. If the config file doesn't exist. I must create it. – MEM – 2011-03-28T10:18:33.860

5

You can specify an alternate keyfile on the command line with the -i option, or you can change it permanently with IdentityFile in the ssh client config file.

MattBianco

Posted 2011-03-28T01:22:27.000

Reputation: 1 763

3

/usr/bin/ssh-copy-id will use the last created file that match id_*.pub. To change which one is default just touch it.

me@my-machine:~/.ssh$ touch id_rsa id_rsa.pub

Benoit Bourgault

Posted 2011-03-28T01:22:27.000

Reputation: 51

1

In my file /usr/bin/ssh-copy-id at line 59:

most_recent_id="$(cd "$HOME" ; ls -t .ssh/id*.pub 2>/dev/null | grep -v -- '-cert.pub$' | head -n 1)"

DEFAULT_PUB_ID_FILE="${most_recent_id:+$HOME/}$most_recent_id"

The most recent file will be the default, and you can probably change this. Note that your file must start with 'id'.

Patafikss

Posted 2011-03-28T01:22:27.000

Reputation: 11

-2

if you want to change the default one you send, change id_*.pub to to keyhello.pub in file /usr/bin/ssh-copy-id. You will find that on line 60 or something. The line starts with DEFAULT_PUB_ID_FILE and you will see after that "$HOME/$(cd "$HOME" ; ls -t .ssh/id_*.pub".

ramsey322

Posted 2011-03-28T01:22:27.000

Reputation: 1

Seriously?  The only way this user can make a configuration change that affects them (and only them) is to modify a system file (potentially affecting all the users on the system)?  Is your answer better than the other (6½-year-old) answers to this question? – Scott – 2017-09-17T08:33:15.773