Setting up SSH Authentication in Remote Server

What is SSH authentication and why do you need it?
SSH Authentication is a type of authentication to any accessible server or files with the help of private and public encrypted key pairs. The private key from the user device validates with the public key pair in the remote server to authenticate and access the remote server.
Preference for SSH authentication is primarily focused on security as it provides better cryptographic strength than passwords. Furthermore, it allows users to implement single sign-on across the SSH servers they connect to.
Setting up SSH authentication:
In the remote server
- First login to your server manually using the password and then generate the ssh keys pair:
ssh-keygen -t rsa

2. Copy the public key pair in the authorized_keys file
mv new_ssh_key new_ssh_key.pub .ssh //if required
cd .ssh
cat new_ssh_key.pub >> authorized_keys
In local device (from which you want to access the server):
- Pull private key from the server using SCP into your .ssh folder
scp <ubuntu_user>@<ip_address>:<full_address_to_ssh_key> ./.ssh
2. Add details in the config file:
Get inside the .ssh folder and create a config file.
cd .ssh
touch config
nano config
Include this in your config file:
# Remote Server
Host <remote_server_name>
HostName <server_ip_address>
User <server_user>
IdentityFile ~/.ssh/new_ssh_key
Hint: server_ip_address = 192.168.1.1 and server_user = develop
3. Set up the file permission for the private key so that the key cannot be accessed by other users on your system.
chmod 600 new_ssh_key
4. Check to verify if the ssh keys are properly set up
ssh <remote_server_name>
Additional tip: You can also disable the password-based authentication in the server and only use ssh authentication to make it more secure. Also, it is wiser to remove the private key from the server to prevent any sort of unauthorized access in the future.