Generate ssh key

ssh-keygen -t rsa -b 4096 -C "[email protected]"

Install ssh server

sudo apt install openssh-client

sudo apt install openssh-server

Add public key

Add public key from laptop you want to login (cat .ssh/ to server you want to ssh with key.

To do that on server open: .ssh/authorized_keys (if it doesn’t exist create new file)

vim ~/.ssh/authorized_keys

Paste in there the content of your laptop’s .ssh/ & save

note: there are 2 online tools dead drop & msg drop that will make your life easier if you want to transfer public key from one laptop to another

Disable password login

then edit /etc/ssh/sshd_config

sudo vim /etc/ssh/sshd_config

and make sure PasswordAuthentication is to no

PasswordAuthentication no

in all past Ubuntu versions the value was commented with # and set to yes as default #PasswordAuthentication yes. Make sure you don’t have # in front of PasswordAuthentication no

save and run

sudo systemctl restart sshd.service

Now if you try to ssh to that server without that key you will see:

[email protected]: Permission denied (publickey).