✍️Don't miss this opportunity to learn how to establish a connection and data transfer from one server to another using the SSH and SCP Protocols.

·

5 min read

✍️Don't miss this opportunity to learn how to establish a connection and data transfer from one server to another using the SSH and SCP Protocols.

Activating SSH Key Authentication and generating key pair

🚫Private Key to authenticate, Data Transfer, and Information Share🚫

✍️What is SSH key authentication?

SSH key authentication is a method of logging into a remote server using a cryptographic key pair instead of a password. The key pair consists of a private key that is kept on the client computer and a public key that is placed on the server.

✏️How do I generate an SSH key pair?

To generate an SSH key pair on Debian, follow these steps:

  1. Open a terminal window on your local machine.

  2. Type the following command: ssh-keygen -t rsa

  3. You will be prompted to enter a filename for the key pair. Press Enter to accept the default location and filename.

  4. You will then be prompted to enter a passphrase for the key. This is optional, but highly recommended for added security.

  5. Your key pair will be generated and saved in the ~/.ssh directory on your local machine.

✍️Concept of SSH [Key-Pair]✍️

Suppose machine 1 is your local machine and machine 2 is your server. I need to authenticate the local machine with the server machine.
I need to have a key that I can use to authenticate with this server machine, and this key is not a single key, it is a key-pair.
The server machine has a public key and the other server we want to connect to has a private key.
SSH is a protocol, a set of rules by which one server can connect to another server.
Now see, there are two things in Key-Pair, one is a Private key and one is a Public key.

✍️Client-Server Concept✍️

🕸️Now, We have 2 machines.
1 :- Test-Server.
2 :- Cloud-Server-Machine

👨🏻‍💻Task🛠️🚧👨‍💻

✍️Now what I have to do is to connect the Test-Server to the Cloud-Server-Machine. So, I open the test server first and this Test-Server connects to my local machine terminal.

ssh is the tool which we have to connect to the machine.

-i is the path to your private key file and What is the private key file, that is your "test-server.pem"

ubuntu is the username you want to connect to.

@ec2-54-227-206-43.compute-1.amazon.com This is your DNS, which means Domain Name Server. username is the name you have given.

🚫Now, I have accessed my test-server on my local machine. I have accessed the AWS server on my local machine PowerShell Terminal.

✍️ Key-Generation✍️

✏️ I have to connect one server to another server.
Now I will generate the key on the test-server-machine.

🎯Go to public key directory

id_rsa :- This is my Private Key.
id_rsa.pub :- This is my Public Key.

🎯I want to authorize the public key id_rsa.pub**Copy this public key id_rsa.pub

🎯🎯Now I will paste this copied public key into the authorized key with shift + A.

I have authorized the public key which I generated through ssh-key and now my server has the public key.

If I want to connect to a cloud-server-machine, then that server must have a private key.

There are two ways to do this, either download this file somehow or copy and paste it.

This is your local machine or this is your test-server machine. So understand that if you have to download anything from the server to your local machine then the private key of the server must be in your local machine.
I copied the file of the test-server into the local-machine using the private key of my test-server.

I have the .pem file of the test server into my local. I have placed that file inside /Documents.
I'll use this key and then copy some files, the same way.

🎯To Check in Local Machine :-

✍️Using SCP Command🎯

SCP (secure copy) command in Linux system is used to copy file(s) between servers securely. The SCP command or secure copy allows the secure transferring of files between the local host and the remote host or between two remote hosts.

✏️Now go to AWS and go to SSH client and copy the ssh command and paste it to the local machine terminal.

✏️ Now replace SSH with SCP. Always remember that the SCP command is run wherever your private files are kept, which means local machine or whatever server you want to connect to.

✏️Now check your file's path....

✏️ Now SCP, after that, this is your path, after that, this is your server and after that, the path of the file is kept inside the server. And lastly, slash the name of the file whatever you want (id_rsa).
And where do I want to store it, I want to store it in this document folder, so I will put a dot (.) .

✏️ SCP is just like copy command ubuntu@ec2-54- is your source and . this is your destination.
A private key file has been added to the SCP. If I have to copy something from the server then what will be the source, server, and file path of the server and the destination will be a local machine.
✏️ Can you see this, I have downloaded a file from the server.

🎯Now my next task is to transfer it from the local machine to the cloud-server machine. I have to transfer the file of id_rsa to the cloud-server machine.

🎯 Now I have to send id_rsa to the cloud-server machine, so what will be my source? It will be the local machine where the file of id_rsa is kept. This is my source. And my destination will be cloud-server. So I will copy and paste the name of the cloud-server machine or DNS.

📝 Now go to the cloud-server machine and check.

🎯🎯Generally, this process is also known as Jump Server🎯🎯

✏️ Now, we can connect the cloud-server machine to the test-server machine.

📚📖📝Feel free to ask me, if you need any help regarding this docker project📚📖📝

❄Thank you for reading! I hope you find this article helpful❄

❄❄❄❄❄❄❄❄❄❄❄❄❄The End❄❄❄❄❄❄❄❄❄❄❄❄❄❄