Thursday, June 7, 2007

ssh public key authentication

1) Generate a key if necessary
$ mkdir -p ~/.ssh
$ chmod 700 ~/.ssh
$cd ~/.ssh
$ssh-keygen -t dsa
*******hit enter to accept the default /home/user/id_dsa****** this is important
****** Leave password blank for password less login******


2) Copy the public key to the remote host
$ scp -p id_dsa.pub remoteuser@remotehost:
password: *******


3) Log into the remote host and install the public key
$ ssh -l remoteuser remotehost
Password: ******

remotehost$ mkdir -p ~/.ssh
remotehost$ chmod 700 ~/.ssh
remotehost$ cat id_dsa.pub >> ~/.ssh/authorized_keys
remotehost$ chmod 600 ~/.ssh/authorized_keys
remotehost$ mv id_dsa.pub ~/.ssh
remotehost$ logout


4) Log back in via public-key authentication
$ ssh -1 remoteuser remotehost
Enter passphrase for key '/home/user/.ssh/id_dsa': ********

Notes:
To connect to remote host via ssh
$ ssh username@remotehost
password:******

No comments: