I have two servers. Both servers are in CentOS 5.6. I want to SSH from Server 1 to Server 2 using a private key I have (OpenSSH SSH-2 Private Key).
I don't know how to do it over unix. But what I did on windows using Putty was to feed my OpenSSH private key to putty-gen and generate a private key in PPK format.
However, I would be creating a bash script from server 1 that will execute some commands on server 2 via SSH.
How do I SSH to Server 2 using my private key file from Server 1?
Best Answer
You need your SSH public key and you will need your ssh private key. Keys can be generated with
ssh-keygen
. The private key must be kept on Server 1 and the public key must be stored on Server 2.This is completly described in the manpage of openssh, so I will quote a lot of it. You should read the section 'Authentication'. Also the openSSH manual should be really helpful: http://www.openssh.org/manual.html
Please be careful with ssh because this affects the security of your server.
From
man ssh
:This means you can store your private key in your home directory in .ssh. Another possibility is to tell ssh via the
-i
parameter switch to use a special identity file. Also fromman ssh
:This is for the private key. Now you need to introduce your public key on Server 2. Again a quote from
man ssh
:The easiest way to achive that is to copy the file to Server 2 and append it to the authorized_keys file:
Authorisation via public key must be allowed for the ssh daemon, see
man ssh_config
. Usually this can be done by adding the following statement to the config file: