How do I set up SSH so I don't have to type my password when connecting to a host?
|
feedback
|
First, generate a SSH key (if you don't have one)If you happen to use GNOME, the If you prefer terminal, run If you just press Enter in Second, upload the public key to the remote server.Again, And here's the terminal way, step by step:
Short version: Third, load the key into
|
run "ssh-add -l" : I did this and it says "The agent has no identities"... now what? – Jason S Jul 18 '09 at 18:44 |
|||
|
ah, you have to say "ssh-add {path-to-private-key-file}" and then it will ask you for your passphrase. Please make this more explicit in your post. You should also add "Fourth, run ssh". Part of the problem with the documentation with this stuff is that it glosses over seemingly obvious steps that are NOT obvious for someone new to the process who has no idea what's going on and how these programs work together. – Jason S Jul 18 '09 at 18:47 |
||
|
Jason: ssh-add -l is to check if an agent is running. ssh-add without arguments will add the key from the default location (which is ~/.ssh/id_rsa). Anyway, updated. – grawity Jul 18 '09 at 19:05 |
||
|
there's a command ssh-copy-id that copies the public key to the target host and sets permissions automatically. – hasen j Jul 25 '09 at 4:54 |
||
Great answer! It is missing a bit about the file permissions of the key files - I just had a problem relating to that today. The private key file should only be accessible by me, and the public key file should only be writable by me. – ripper234 Oct 28 '10 at 8:42 |
|
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, " | ||||
|
feedback
|
|
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. | |||||||
feedback
|
|
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! | ||||
|
feedback
|
|
http://linuxproblem.org/art_9.html
| |||||||
feedback
|
| |||||||||||||||||
feedback
|
|
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. | ||||
|
feedback
|
|
I guess it was a good idea to quote ssh-keygen for I add public key authentication here again for regular reference. | ||||
|
feedback
|
|
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
| ||||
|
feedback
|
|
It looks like the solution involves using authentication keys. Here's a guide to setting it up. | |||||||||||||||||||||
feedback
|

