How to make ssh connection between servers using public-key authentication
- by Rafael
I am setting up a continuos integration(CI) server and a test web server. I would like that CI server would access web server with public key authentication. In the web server I have created an user and generated the keys
sudo useradd -d /var/www/user -m user
sudo passwd user
sudo su user
ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/var/www/user/.ssh/id_rsa):
Created directory '/var/www/user/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /var/www/user/.ssh/id_rsa.
Your public key has been saved in /var/www/user/.ssh/id_rsa.pub.
However othe side, CI server copies the key to the host but still asks password
ssh-copy-id -i ~/.ssh/id_rsa.pub user@webserver-address
user@webserver-address's password:
Now try logging into the machine, with "ssh 'user@webserver-address'", and check in:
.ssh/authorized_keys
to make sure we haven't added extra keys that you weren't expecting.
I checked on the web server and the CI server public key has been copied to web server authorized_keys but when I connect, It asks password.
ssh 'user@webserver-address'
user@webserver-address's password:
If I try use root user rather than my created user (both users are with copied public keys). It connects with the public key
ssh 'root@webserver-address'
Welcome to Ubuntu 11.04 (GNU/Linux 2.6.18-274.7.1.el5.028stab095.1 x86_64)
* Documentation: https://help.ubuntu.com/
Last login: Wed Apr 11 10:21:13 2012 from *******
root@webserver-address:~#