How to establish SSH connection to your remote machines via ssh keys.

How to establish SSH connection to your remote machines via ssh keys.

Hey guys!

Welcome back to my blog.

Today we will learn a simple thing where in you will connect two machines via SSH.

Let's Begin!

Pre-requisite:-

Download MobaXterm

MobaXterm?

->It is a toolbox for remote computing.

After Instaling it ,

  • Click Session->click ssh->enter the remote host details(I will enter the public address of my Ec2-server I created on AWS)->check the Checkbox(near specify user name)

  • Enter the username necessarily as ec2-user.

  • Click Advance SSH settings

  • Upload the key pair, You generated it while creating an instance on AWS.

Below Attached is the Image showing all the details I explained above.

  • Click OK

See Your server is started

Yay!

Finally, Connect AWS Linux servers using SSH Client.

1st step is done guys, Congratulations!

Next, we will make one more instance on AWS.

-> After creating instance, make sure you connect that too with ssh using Mobaxterm.

Now those servers will look something like this,

Now all the gameplay will be of Commands...

Let's start(use these commands in 1st server)

  • type ssh ec2-user@ipaddress(use the ip adddress of the linux machine you want to connect with this)

  • click yes

    (after this Some errors will be generated, correct?)

  • type ssh-keygen

    It will automatically create two keys public and private. Let's learn more about them.

    Private keys:-private key is located on the client machine and is secured and kept secret.

    Public keys:- public key can be given to anyone or placed on any server you wish to access.

    When you attempt to connect using a key-pair, the server will use the public key to create a message for the client computer that can only be read with the private key.

    (Now you got some idea what to do!)

Now the important thing here is

Go to the next server where you want the connection.(Use commands in 2nd server)

  • Now write the command sudo su - to become a root user.

  • write the command vi /etc/ssh/sshd_config

  • Update Password Authentication to Yes

  • now as a root user, change the password of the user

  • enter the command passwd ec2-user

  • Your password will be updated successfully

After this write

  • service sshd reload

Now come back to your 1st server

  • type ssh-copy-id user@<target-server>

  • Enter your Password(Recently Updated)

  • To check if your keys are copied

  • go to .ssh folder (cd .ssh)

  • type ls -a

  • then write command cat id_rsa.pub

  • Go to the 2nd server and hit the following commands(Please see the screenshots)

Finally, The final command

  • ssh ec2-user@<targetipaddress>
  • Boom it will definitely work!!!

  • see You will have full access to your 2nd instance

    Let me show you some screenshots to understand it more efficiently.

  • So in the first server I made a text file(Please see screenshots thoroughly)

  • Now let me show you the same file in the second server

Guys, You have done this, Yay!!

See this was very easy right :)

If you have any confusion, or find any sort of suggestions, Do let me know :)

All suggestions are welcomed!

More DevOps content is Ahead!!

Apart from this to know How to build a Docker image for any Application!

You can read this blog https://riddhisharma.hashnode.dev/devops-project