Command to send public key to remote host
You might be looking for this command:
cat ~/.ssh/id_rsa.pub | ssh user@hostname 'cat >> .ssh/authorized_keys'
It appends your public key to the servers authorized keys.
Source
If your server is already set up to not accept password-based login, you might get a Permission denied (publickey)
error.
This is another method to send the key, using netcat
, so you don't have to authenticate. It will only work over a local network, but you can use port forwarding to do this over the internet.
On the server:
$ nc -l 55555 >> ~/.ssh/authorized_keys
On the client (replace HOSTNAME
with the hostname or IP of the server):
$ nc HOSTNAME 55555 < ~/.ssh/id_rsa.pub
You can replace 55555
with an open port of your choice.
source: chat over lan from linux to linux?
Appendix for total newbies: I don't think anyone's mentioned this yet, but if you get ERROR: failed to open ID file '/home/username/.pub': No such file
, you need to generate a key first. The Ubuntu help pages have a great guide on Generating RSA Keys.
You are looking for ssh-copy-id
. All this command does is create .ssh
and .ssh/authorized_keys
and set their permissions appropriately if they don't exist. Then it appends your public key to the end of .ssh/authorized_keys
.