How To Use SSH Keys To Login On a Server Securely Without Password
Here we are going to learn how to use SSH Keys to login on a server Securely without password.
SSH Keys To Login On a Server Securely Without Password
Entering the server password can annoying if you need to access it multiple times. Enabling password option gives scope for possible brute force attacks. The public-private key pair is much faster, easier and secure.
Creating the Key:
On the client machine, use the command:
ssh-keygen
Enter any file name if want it to be different from the default and hit enter.
Skip the passphrase.
Now the keys are stored in the home directory of the user in .ssh folder. (The ‘.’ means that the folder is hidden and won’t be visible in the file explorer/finder if hidden files are turned off)
Copy the Key
Use ls and look for the key with .pub (which is the public key). Use cat <filename> to view its contents. Then copy the output.
cd /users/arpitgupta(your username here)/.ssh
Arpits-MacBook-Pro:.ssh arpitgupta$ ls id_rsa id_rsa.pub known_hosts
Arpits-MacBook-Pro:.ssh arpitgupta$ cat id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDzf8HQULVrxtP+nBEEwVvK3FRHmaqd3FL3vlxQmVJ0ZDXFIfvdG+T37g/aiAVppaBh06jGhdL6z7T0yh0GvWyezpe55V3VVggK0dHnkbAnbruQ/IAHbfs7s58DSM3qg5uBHkW/sC/s78aAY1Hnh3neWkzoBnsWKgFP0V/ck+UX0d0RiG7jcQOuDdvZMYldKJoIcXtU4AZ+NiZN07s++QGSRv3bUvKnI8Fm8Vuao5E2HQsE9ArcylBZ+KpzLGZxckJWS+576Ivl06+tVRslYAaiWs6RP2vX2evcxThK3SDCqqAt+cfB1tHbhylz8ZkDZNEwSciGjs02xCyDPbjlTahZ arpitgupta@Arpits-MacBook-Pro.local
Paste in Server
On the server side, go to the home directory again and paste the key in .ssh/authorized_keys
cd ~ mkdir .ssh touch authorized_keys nano authorized_keys
This will open a text editor in the terminal and you can paste the key in there
Press ctrl+x to exit and then y to save.
Permit Keylogin and Rootlogin
Use the following command to edit SSH configuration:
root@kali:~# nano /etc/ssh/sshd_config
Now search for the following parameters and remove the pound sign(#) from the starting of their lines.
You can also type them as it is.
PubkeyAuthentication yes
PermitRootLogin yes
That’s it!
You are done with the setup.
If you try to SSH into your machine now, you would not be prompted for a password!
Also, learn
Leave a Reply