8

I am working with serverals hosts and I do not want specify the password every time that I want to connect to any hosts. Then I have generated a key with:

Enter file in which to save the key (/home/robe/.ssh/id_rsa): my_key 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in my_key.
Your public key has been saved in my_key.pub.
The key fingerprint is:
e6:d9:a3:85:38:b1:b2:a9:4d:3b:c1:33:65:df:57:25 robe@computer
The key's randomart image is:
+--[ RSA 2048]----+
|                 |
|              E .|
|               o |
|      o       .  |
|   . o..S.   .   |
|    =  *.+. .    |
|    o++ + +.     |
|   o.= . o .     |
|  ..=.  .        |
+-----------------+

then I copy the my_key.pub to the authorized_keys file in every hosts and I can connect with:

ssh -i /path/to/my_key  user@host

But here is my problem, I want to connect without specify the key. I will like to find a way that I run:

ssh user@host

Note: I want to keep my default id_rsa and id_rsa.pub keys. The my_key key is an alterntive option to manage other hosts.

2 Answers 2

20

You are looking for the ~/.ssh/config configuration file. For instance, add this entry in this file.

Host host
    HostName host.example.com
    User johndoe
    IdentityFile ~/.ssh/host.key

Now you can type

ssh host

And ssh will automatically use the username and key you specified by the IdentityFile parameter. Therefore that command is equivalent to:

ssh [email protected] -i ~/.ssh/host.key

see http://www.openbsd.org/cgi-bin/man.cgi/OpenBSD-current/man5/ssh_config.5 for all the configuration details for that file.

1

If you are in *nix, you can use ssh-agent/ssh-add to store your identities in memory for your session.

  1. Run ssh-agent from a terminal

user@machine$ ssh-agent bash

This will create a bash process with ssh-agent running

If you don't want to create another process, then

user@machine$ ssh-agent -s

SSH_AUTH_SOCK=/tmp/ssh-shtzxe4347/agent.4347; export SSH_AUTH_SOCK; SSH_AGENT_PID=4348; export SSH_AGENT_PID; echo Agent pid 4348;

you have to execute the commands in bold to update your env variables.

2.After any of the previous steps

user@machine$ ssh-add

to add your .ssh/id_rsa to the agent, if your key has a password, it will prompt for it

http://linux.die.net/man/1/ssh-agent http://linux.die.net/man/1/ssh-add


Modern Linux Desktops have GUI's for this , and will start an agent since login.

In Windows, you can use Pageant (part of Putty) instead of ssh-agent.

You must log in to answer this question.

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