How do I set up SSH so I don't have to type my password when connecting to a host?
Generate a SSH key (if you don't have one)If you happen to use GNOME, the seahorse application ("Passwords and Encryption Keys") can do it for you: File -> New -> Secure Shell Key. If you prefer terminal, run
The program will ask you for a passphrase and a location where to save the new key. Using the suggested default path is recommended because all other tools will look for it there. Upload the public key to the remote serverAgain, seahorse can often do that for you - in My Personal Keys, right-click on your SSH key and choose Configure key for secure shell. And the terminal way, step by step:
Load the key into the ssh agentIf you load your private key into a ssh agent, it will hold the decrypted key in memory. We want this to avoid re-entering the password whenever we shell into a server. First, the agent must be started or the path of a launched communication socket be loaded into a variable. Running ssh-agent on a terminal will generate commands for assigning and setting the agent variables. These commands can be saved in a file for use in a different terminal. Alternatively, one could run these commands and forget about re-using the same agent in another terminal. e.g: Loading the key is a simple matter of executing If you are using GNOME, gnome-keyring-daemon usually provides the same SSH agent functionality as ssh-agent, so you should not need to start anything. GNOME will automatically load and unlock the key on login, too. Shell into the remote server without a passwordIf everything was done correctly, using Anything that uses ssh for communication will work without entering the user account password when the correct key is loaded in the agent. Programs such as scp, sftp and rsync make use of this. Notes:
Examples:
|
|||||||||||||||||||
|
|
You didn't specify what Unix you're on, what Unix you're connecting to, what shell you're using, what SSH variant you're using, etc. So some of this might need to be adjusted slightly; this is based on reasonably recent versions of OpenSSH, which is used on a lot of unix variants. This is all from your local desktop system.
Make sure to use the default for the keyname. I suggest that you do set a passphrase on that key, otherwise it's a security problem. "-t rsa" wouldn't be a bad idea, but probably isn't needed.
That will ask you for the password you'd use to log in, and sets up the authorized_keys stuff for you. (no need to do it by hand) Then, this:
or maybe this:
or:
That will start up an SSH agent that can hold your key. On many modern Unix variants, if you're logged in graphically, this will already have taken place. The first variant (with the backticks) puts an ssh-agent into the background and sets up the environment variables to talk to it. The second two have the agent run a shell for you, so that when you exit the shell, the agent exits. Many modern Unix variants will already have an agent running for you, especially if you logged in graphically. You might try " Then, finally:
It will ask for a passphrase; give it the one you gave ssh-keygen. There's also ways to make it ask graphically. And you can put the ssh-agent and ssh-add stuff into your login scripts (setup is different depending on shell you use) to automate this, but some Unix variants (current Ubuntu Linux, for instance) do most of that automatically, so that all you really need to do is create a key and use ssh-copy-id to set it up on the remote host. Now, " |
||||
|
|
|
It's possible to do this in PuTTY on Windows as well. Once you have the public/private key pair all set up (as other answers here show) run PuttyGen. In there, load the existing private key that you've already set up, and then save it as a PuTTY private key (ppk). Then in PuTTY, just click on the saved session you want to auto-login to and click Load. From here go into Connection -> Data in the left pane, and in "Auto-login username" type in the username for that remote server:
After that go into Connection -> SSH -> Auth, and browse for the ppk you made in PuttyGen:
Then go back to the session page and save the session you loaded earlier. |
|||||||
|
|
For KDE users, this is an excellent resource for achieving the same on KDE. http://www.unicom.com/blog/entry/612 I have tested this on Fedora and it works like a song. |
||||
|
|
|
From a very similar question on ServerFault, I'd recommend using ssh-copy-id, which does all the steps involved with setting up authentication keys for you:
All you need to do is simply this:
Type in your password once, and you're good to go! |
||||
|
|
|
Apart from all already been told on how to set ssh keys, I recommend Keychain as a ssh-agent console frontend which allows you to handle one only per system process instead of per login. I know there are already GNOME and KDE tools that do the same but if you are the console junkie type this is great (and can be used on most Unix systems). To use it, simply append the following to your
|
||||
|
|
|
http://linuxproblem.org/art_9.html
|
|||||||||
|
|
|||||||||||||||||
|
|
One might argue if using such keys does not require a password. To avoid that anyone who gets hold of your private key can actually abuse it, one can protect the key by a password of itself. Of course, one can leave that password blank, but there's many cases where that wouldn't be recommended. |
||||
|
|
|
I guess it was a good idea to quote ssh-keygen for I add public key authentication here again for regular reference. |
||||
|
|
|
It looks like the solution involves using authentication keys. Here's a guide to setting it up. |
|||||||||||||||||||||
|
|
If you want to do it all in the terminal in Linux: On the host
The items in the {} are options, use rsa or dsa and choose the bit size (bigger is more secure) Then you need to add the permissions to the authorized_keys and authorized_keys2 files.
Then download the id_AribtraryName file to the box you want to ssh from. If the connecting box is unix based, a config file may be necessary (in putty, someone above covered that). On the Connecting Box In your config file - vim ~/.ssh/config
The config file needs permissions of 600. The SSh folder needs 700. Hope that helps if you run into the config issue that is omitted a lot. |
||||
|
|
|
You can create a shortcut on your desktop like this:
|
||||
|
|
|
I wrote this very very short tutorial after getting REALLY REALLY frustrated with REALLY REALLY long tutorials cos really it's so simple :)
|
||||
|
|

