Creating an SSH Connection to Remote Server
Hello devs in this tutorial i will discuss about how to ssh into a server using terminal. You know that SSH is an amazing way to make secure connections to servers.
It stands for Secure Shell and it's a network protocol between two computers
SSH gives us a secure connection between two network protocol. In today's article, I am going to show you how to set up an SSH connection to a server..
The basic command will look like this:
ssh email@example.com // or ssh firstname.lastname@example.org
We could do it with a password we set on the server, however in this case i don't want to do that.
Generating the SSH key
Before we can do anything we need an SSH key to connect to the server. So we have to generate it. So let's open up the terminal and run the following command to generate a new SSH key.
ssh-keygen -t ed25519 -C "email@example.com"
This will prompt the following options. See the below image and try it
Ok, Now we should have the public and private keys.
Setting the Authorized keys
Our server should have a
~/.ssh/ directory, if not you have to make it. Inside we should have or add the file:
No do the below step
pbcopy < ~/.ssh/server_1.pub
Where server_1 is the name you gave your key. It will copy a string like that to your keyboard.
ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIH4TBYa16+8t9LJmqCuMjq+4PSxca81L8sN8OSgT5YW9 firstname.lastname@example.org
Connecting to the server with the SSH key
We have to add our new key with the following command
ssh-add -K ~/.ssh/server_1
Now time to test out our SSH key.
Change the user and IP according to your server. Hope it can help you.