Simplify distribution of ssh public keys

The following command can be used to simplify the distribution of Public Keys for SSH.

cat .ssh/ | ssh <user>@<host> "cat >> .ssh/authorized_keys"

The command:

  • Displays the current public key for the machine running the command on
  • Pipes this to the ssh command logging in as <user> on <host>
  • Which runs the command cat redirecting the piped through output to the .ssh/authorized_keys file

Couple of notes:

  • This assumes that the ssh-keygen command has been run on the local machine to generate the Public/Private Key Pair
  • Make sure the >> redirector is used so the current authorized_keys file is added to, not overwritten
  • If you are running this to a host for the first time the confirmation to accept the fingerprint is asked for and a password prompt for the user will be asked for.
Back to GNU/Linux OS Configuration Tips