##Note: The video below here demonstrates blog in Telugu, recommend watching the video in separate tab and blog in separate tab for easy practice.
click here to navigate to YouTube
- How to generate SSH key pair
- How to place public key in server that we need to authenticate
- How to authenticate to server using private key
SSH is known as secure shell or secure socket shell and to put it in simple words, SSH is used to authenticate using key-pairs and establishes secure connection. with this we can avoid authentication using passwords.
SSH authentication requires public key and private key. private key will be present with the user and public key will be put inside the server.
the same public key can be put in any number of servers. and to authenticate these servers. only the private key linked to public key can grant access.
let us understand this concept in detail with demo by practising.
For Demo, take two AWS EC2 instances
run this below command in aws ec2 to generate key-pair, public key and private key
ssh-keygen
cd /home/ubuntu/.ssh
now if you view the files here, you will be able to find two keys here,id_ed25519 and id_ed25519.pub. it can also be id_rsa and id_rsa.pub in your case. public key ends with .pub and other key is our private key
Now we need to keep priavte key safe and confidential with us and public key should be placed in server we want to authenticate using this private key
Now copy the contents of public key by simple view the public key by cat command
cat id_ed55219.pub
copy this by simple select and copy. once copied, login to server you want to authenticate using this private key
sudo vi /home/ubuntu/.ssh/authorized_keys
paste the public key that we copied from server IP 172.31.40.140 by "insert" key to be able to edit file and paste normally left mouse click and paste
sudo su - root
sudo su - ubuntu
ssh -i /home/ubuntu/.ssh/id_ed25519 ubuntu@172.31.36.16
Now you can see from below screenshot, we are in the Ip 172.31.40.140 and we are able to connect to 172.31.36.16(the Ip in which we have placed our public key). This shows our authentication is successfull
when you create an AWS EC2 instance with key-pair. this works the same way. private key is given to you and public key is placed inside AWS EC2 server.
Comments
Post a Comment