SSH: Getting the public key using netcat

  • If you can't ssh (say it's already public key authentication only, but not for a key you have, or you're installing on to a machine on the local network, and have not yet installed/configured ssh), you can use netcat.

  • If you're going through a firewall, create a rule to allow connections from an unused port (say 43621), on the local machine.

  • At the command prompt, on the local machine, type cat ~/.ssh/ | netcat -p -l 43621, where 43621 is an unused port (which must be allowed through your firewall).

  • At the command prompt on the remote machine, while in the home directory, type netcat external-ip-of-local-machine 43621 >, where external-ip-of-local-machine is the ip address by which the remote machine sees the local machine (e.g. on a router, the WAN IP of the local machine).

  • Once the transfer is complete (it should be nearly instantaneous, even on dial-up), press Ctrl-C on either machine.