Created
November 25, 2010 03:26
-
-
Save 8ig8/714850 to your computer and use it in GitHub Desktop.
Automate uploading SSH key to a remote host
This file contains 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/sh | |
# | |
# Name : setremotekey | |
# Description : Automate uploading SSH key to a remote host | |
# Installation : Save this as 'setremotekey' to '/usr/local/bin/' | |
# and then make the file executable with 'chmod +x setremotekey' | |
# Usage : setremotekey username@host | |
# Source : http://hints.macworld.com/article.php?story=2007091814022049 | |
# Author : See source above. Modified by bpk/lfd. | |
KEY="$HOME/.ssh/id_rsa.pub" | |
if [ ! -f $KEY ];then | |
echo "Private key not found at $KEY." | |
echo "Please create it with \"ssh-keygen -t rsa\"." | |
echo "Once created, re-run this script." | |
exit | |
fi | |
if [ -z $1 ];then | |
echo "Usage: $0 username@host" | |
exit | |
fi | |
echo "Putting your key on $1... " | |
ssh -q $* "umask 0077; mkdir -p ~/.ssh ; echo "`cat $KEY`" >> ~/.ssh/authorized_keys" | |
echo "Success. You can now access this server without a password." |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment