Using ssh-copy-id to Push SSH key to Authorized Keys

f44d3-6a00e551c39e1c88340162fcbcab43970d-piEverywhere I have ever worked we have always used complex scripts to push out id files to enable passwordless authentication from a bastion host. Today I stumbled across ssh-copy-id which is about as easy to use as it gets.

Check out the section below for usage and substitute your servers hostname where you see <yourhost>

# ssh-copy-id -i ~/.ssh/id_rsa.pub <yourhost>

You will get output similar to what is shown below.

Now try logging into the machine, with “ssh ‘<yourhost>'”, and check in:

  .ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

Checkout the link below for more info

http://www.thegeekstuff.com/2008/11/3-steps-to-perform-ssh-login-without-password-using-ssh-keygen-ssh-copy-id/#more-268

Below is a little wrapper script that I use to make using ssh-copy-id even easier. Please feel free to borrow it for a bit.

[code language=”css”]
#!/bin/bash

echo "Please Enter Server Name :"
read servername
ssh-copy-id -i ~/.ssh/id_rsa.pub $servername
[/code]