+1 (717) 461-8095 /+263 (775) 937-458 /+263 (777) 337 348 enquiries@bibliotechzw.com

Server to Server Access Via Command Line Using SSH Keys – Ubuntu 16

Consider this scenario – you have two servers, Server 1 and Server 2 (with user1 and user2 respectively), that you want to connect to each other via the command line using SSH keys and not passwords. Because you are using the command line, you won’t be able to use an SSH client like Putty. The following tutorial will show you how to SSH into Server 1 from Server 2 using SSH keys, and vice-versa.

To Connect To Server 2, from Server 1

Create SSH keys for the user1 on Server 1

On Server 1:

ssh-keygen -t rsa
ssh-copy-id user1@server1
ssh user1@server1

Copy the public key for Server 1 and append it to the the authorized keys for Server 2

On Server 1:

scp -p ~/.ssh/your_pub_key.pub user2@server2:

You will be prompted for the password for user2 on Server2
Now, ssh into Server 2 using the following command:

ssh user2@server2

then append/copy the public key from Server 1 to the authorized keys list for Server 2

cat your_pub_key>> ~/.ssh/authorized_keys

To Connect To Server 1, from Server 2

Create SSH keys for the user2 on Server 2

On Server 2:
ssh-keygen -t rsa
ssh-copy-id user2@server2
ssh user2@server2

Copy the public key for Server 2 and append it to the the authorized keys for Server 1

On Server 1:

scp -p ~/.ssh/your_pub_key.pub user2@server2:

You will be prompted for the password for user2 on Server2
Now, ssh into Server 2 using the following command:

ssh user2@server2

then append/copy the public key from Server 1 to the authorized keys list for Server 2

cat your_pub_key>> ~/.ssh/authorized_keys

To test, attempt to access Server 2 from Server 1

ssh -i .ssh/id_rsa user2@server2_ipaddress

That’s it! Now you can connect from either Server 1 to Server 2, or Server 2 to Server 1, using user1 or user2 respectively, in Ubuntu 16 via the command line without having to use passwords. Questions? Comments? Let us know below!

Subscribe To Our Newsletter

Join our mailing list to receive the latest special offers and news updates from our team.

You have Successfully Subscribed!

Share This