How To Setup Key Based Ssh Authentication
How to Setup key-based (SSH) authentication on your Server#
-
Create the key pair on client
ssh-keygen -t rsaConvention over configuration keep the default location
-
Install the public key on remote server
ssh-copy-id -i $HOME/.ssh/id_rsa.pub user@fixes.co.zaNot if you don’t have the private key you need to use the
-foption:ssh-copy-id -f -i $HOME/.ssh/id_rsa.pub user@fixes.co.zaor
scp $HOME/.ssh/id_rsa.pub user@fixes.co.za:~/.ssh/authorized_keysNo
ssh-copy-idinstalled?#First create .ssh directory on server ssh user@fixes.co.za umask 077; test -d .ssh || mkdir .ssh cat local id.rsa.pub file and pipe over ssh to append the public key in remote server cat $HOME/.ssh/id_rsa.pub | ssh user@fixes.co.za cat >> .ssh/authorized_keys -
Test
ssh -T user@fixes.co.za or scp foo.txt user@fixes.co.za:/tmpGet rid of password:
eval $(ssh-agent)add passphrase for private key maintained by ssh agent
ssh-addTry login you shouldn’t be prompted for password
ssh user@fixes.co.za
Now to Disable Password Authentication on your server#
sudo vim /etc/ssh/sshd_config
Set:#
PasswordAuthentication no
Restart SSH
sudo service ssh restart