Saturday, February 27, 2010

ssh scp without password

Issue: How to login (ssh or scp) from your homepc to your remote server without password.

Solution:
1, in your homepc




bob@homepc ~ $ ssh-keygen -t dsa
Generating public/private dsa key pair.
Enter file in which to save the key (/home/user/.ssh/id_dsa):     # Press 'enter' here
Enter passphrase (empty for no passphrase):     # Press 'enter' here
Enter same passphrase again:     # Press 'enter' here
Your identification has been saved in /home/user/.ssh/id_dsa.
Your public key has been saved in /home/user/.ssh/id_dsa.pub.

# Entering a password when asked during the key generation processes when prompted would require you to enter a  password each time you SSH/SCP to the server which defeats the purpose of this document.

DO NOT enter the password



You will find two files generated:
greg


@cm-test:~/.ssh$ ls

id_dsa  id_dsa.pub  known_hosts



Then scp  

id_dsa.pub to you remote server
scp  ~/.ssh/id_dsa.pub bob@yourserver.com:~/.ssh/


2, in your remote server
a, go to .ssh folder
cd ~/.ssh

b, add public key into this file  authorized_keys
run:
cat id_dsa.pub >> authorized_keys


If authorized_keys not exist, this command will create it.


c, change file permission
chmod 700 authorized_keys


You should be able to login to your server without password.




There are some tricks about the account:
In the home box, if your user name is bob, the public key and private key is on /home/bob/.ssh/ folder


If you want to log to remote server using account greg, then copy public key to remote server folder /home/greg/.ssh/


This case only allow home pc bob logon to remote server using greg account.








No comments:

Post a Comment