How to use public key authentication in ssh

ssh is one of the most effective tool for remote connection with server, but password is not enough for security because passwords can be easily guess or can be easily bruteforce .So there is a good and a secure way to access servers without compromising security which is Publicy key authentication .So in this blog I will explain how can we enable public key authentication on a linux server .

1st of all there is a file name sshd_config through we can manage ssh settings of openssh.

This file is located in


in which we need to uncomment the public key line in order to use the key authentication feature

after which we have to define the location where we want to put the authentication file

by default the location is ~/.ssh/authorized_keys

You can provide custom location where you want to put the authetication file.For now I am not changing anything and then from the user through which you want to use the Public key ,run this command

# ssh-keygen

then provide the location where you want to put the file by default its in


then you have to enter a good passphrase for double security or you can just hit enter for no passphrase

then on the location of your public key change the to the name you have define in the /etc/ssh/sshd_config

now for the changes you made in the default setting ,you need to restart the ssh service to use them properly,use this command with root privileges

systemctl restart sshd.service

Now you have your server with public key authentication ,the only thing left is to provide keys to client .So you need to provide id_rsa key to your clients and for proper working change the permission of authentication key to 600.In order to change the permission run this command on client hand

# chmod 600 [Your key location]

Now all work is done ,you can use public key authentication on ssh.

cyber security student | boy from future