Created
August 6, 2013 12:55
-
-
Save rjaeckel/6164222 to your computer and use it in GitHub Desktop.
Put the public ssh key file to various remote hosts to use certificate based authentication
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/bin/bash | |
if [ $# -eq 0 ]; then | |
me=$(basename $0) | |
echo "-> copy the personal rsa key to other machines for certificate based authentication" | |
echo Usage: | |
echo "$me [user@]machine [[user@]machine [...]]" | |
fi | |
cert_var=_ssh_key_file | |
cert_var=$USER$cert_var | |
cert_ext=.pub | |
cert=${!cert_var} | |
if [ ! "$cert" ]; then | |
cert=~/.ssh/id_rsa | |
echo "using default key $cert" | |
echo "export $cert_var=/path/to/key/file to override" | |
fi | |
pubkey=$cert$cert_ext | |
if [ ! -f $cert ];then | |
echo Key-Pair $cert does not exist. Creating... | |
ssh-keygen -N "" -f $cert | |
fi | |
for arg in "$@"; do | |
echo Machine $arg: | |
ssh-copy-id -i $pubkey "$arg" | |
echo -------------------------------- | |
done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment