|
How To -
SSH
|
|
Written by Christian Foronda
|
|
Thursday, 07 January 2010 11:58 |
|
Using SSH keys is very handy for not always having to enter your password when logging into SSH. I'll show you how to set this up.
- Generate the key by running:
ssh-keygen -t rsa
- Press enter to accepted the default location of ~/.ssh/id_rsa
- Enter your passphrase. Make it as secure as possible.
- On my server, I have SSH running under a different port from the default, so I modified ~/.ssh/config as follows, obviously with different values:
Hosts example.com
Port 22000
- To fix the permissions, execute:
chmod 600 ~/.ssh/config
- Transfer ~/.ssh/id_rsa.pub to the remote server:
scp ~/.ssh/id_rsa.pub
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
:~
- Then, SSH to the remote server:
ssh
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
- Add the public key to the list of authorized keys:
cat ~/id_rsa.pub >> ~/.ssh/authorized_keys
- Fix the permissions:
chmod 600 ~/.ssh/authorized_keys
- Delete id_rsa.pub:
rm -f ~/id_rsa.pub
- Now you can exit the remote server:
exit
- Now, run ssh-agent so you only have to enter the key once:
ssh-agent -s > ~/.ssh-agent
- Bring the environment variables from ~/.ssh-agent into the current shell:
source ~/.ssh-agent
- Add the key to ssh-agent:
ssh-add
When prompted, enter your passphrase, as you entered in step 1.
- Now, you should be able to run:
ssh
This e-mail address is being protected from spambots. You need JavaScript enabled to view it
Without being prompted for your password.
Ref: http://www.perpetualseeker.com/?p=489
|