SSH(Secure Shell) & SCP (Server Copy)
SSH is known as Secure Shell. It is a protocol or a set of rules that defines how to take server access from a local machine. When you create a server on AWS and while creating the server you need to create Key Pair for the server so that your private key will be authenticated. So the private key (.pem) will be downloaded on your local machine and the server public key will be stored in /home/.ssh.
When you run ls command you will see an authorized_key file.This authorized_key file is your public key. If you want to ssh your server from your local machine then you can do it in 2 ways. One way you need to install Git Bash for windows and another way you can use Putty software. You can use these 2 alternatives method if you are using Windows. If you are using Linux or MacOS bydefault SSH is enabled on Linux.
In my session I have used Git Bash. It looks like a Linux terminal. You can run Linux commands on that terminal. You need to open a Bash terminal. Then check whether the SSH client is installed. You can run the command ssh. If it is not installed, then you need to install the SSH Client. Go the path where your private key file is downloaded. Make sure your private key file should not be publicly viewable. You can run this command chmod 400 <private-key-filename.pem>.
Then run this command ssh -i <private-key-filename.pem> username@<public-ip-address-of-instance>. In this syntax, the 'i' flag refers the path of your private key file.
Also if you want to transfer the file from server to local and vice versa then you can use scp command. SCP is known as Secure Copy or Server Copy. If you want to connect one server to another server then you need to use this concept.
Consider there are 2 servers. I need to take access of Sever 1 from Server 2. I néed to connect the Server 2 instances from browser using EC2 Instance Connect. Then generate the key using "ssh-keygen". It will create a public and private key pair. You need to copy the .pub file inside an authorised_key file in Server 2. And download the private key file of Server 2 on your local machine. Open bash terminal on your local machine. Run this command "scp -i <server 2 private key file> <server 2 DNS Name>:/home/Ubuntu/.ssh/ ."
Here I have put dot (at last) on my above command because I need to store the private file in my current path. Once I downloaded in my local machine, then I need to transfer the same private key file on Server 1. Use the command scp -i <server 1 private key file.pem> <name of your private key file for the Server 1> <server 1 DNS Name>:/home/Ubuntu/.ssh/>.