April 27, 2020 · Don't Forget linux mac

Insecure transfer of public authorized keys

(or: how do I transfer my ssh public keys to a sshd server running PasswordAuthentication=no)

If you don't already have an ssh keypair, type ssh-keygen on your computer and follow the instructions to generate one.

Wherever you are running your ssh service (and assuming you've just enabled it and have no other configurations setup):

mkdir -pm700 ~/.ssh
nc -l 1234 > ~/.ssh/authorized_keys

(the last command will hang; this is expected). On your computer, then type ( replacing 192.0.2.1 with the correct IP):

nc 192.0.2.1 1234 < ~/.ssh/id_rsa.pub

If successful, the last command on your server will now succeed.