// shall I write some keywords here to boost search engine ranking?

Sunday, April 19, 2009

Passwordless SSH login via Public Key Authentication

SSH login with password authentication is often a problem for shell script that run without human interaction. One of the option by simulating user input via some Expect script. While another option is to setup certification based authentication.

Below is the steps:

1. SSH to client host (said with username 'myuser')
2. Generate keys at client host, press 'Enter' while it prompt for key location and passphrase.:


$ ssh-keygen -t rsa

3. Upload the public key generated (~/.ssh/id_rsa.pub) to remote host home directory (said username 'remoteuser')
3. SSH to the remote host with same username ('remoteuser'), create the .ssh folder if not exist

$ cd ~
$ mkdir .ssh
$ chmod 700 .ssh

4. Import public key into authorized_keys

$ cat id_rsa.pub >> ~/.ssh/authorized_keys
$ chmod 600 ~/.ssh/*


Now when the 'myuser' at client host SSH to remote host with username 'remoteuser', it will not prompt for password anymore.

No comments: