UPDATE (15/09/2024): Just found an even cleaner shell command on Ubuntu Documentation:
By default, the public key is saved in the file ~/.ssh/id_rsa.pub
, while ~/.ssh/id_rsa
is the private key. Now copy the id_rsa.pub
file to the remote host and append it to ~/.ssh/authorized_keys
by running:
ssh-copy-id username@remotehost
I keep forgetting this quick one-liner, so I thought I'd add it to my list of useful tricks. I usually just Google it, but How-To Geek is an awesome resource (link)
ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'