Created
February 7, 2012 21:03
-
-
Save decthomas/1761938 to your computer and use it in GitHub Desktop.
Configure ssh host
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
# creates an SSH key and uploads it to the given host | |
configure_ssh_host() | |
{ | |
username=$1 | |
hostname=$2 | |
identifier=$3 | |
keyfile=$4 | |
if [[ "$identifier" == "" ]] || [[ "$username" == "" ]] || [[ "$hostname" == "" ]] || [[ "$keyfile" == "" ]] | |
then | |
echo "usage: configure_ssh_host <username> <hostname> <identifier> <keyfile>" | |
else | |
ssh-keygen -f ~/.ssh/$keyfile.id_rsa -C "$USER $(date +'%Y/%m%/%d %H:%M:%S')" | |
echo -e "Host $identifier\n\tHostName $hostname\n\tUser $username\n\tIdentityFile ~/.ssh/$keyfile.id_rsa" >> ~/.ssh/config | |
ssh $identifier 'mkdir -p .ssh && cat >> ~/.ssh/authorized_keys' < ~/.ssh/$keyfile.id_rsa.pub | |
tput bold; ssh -o PasswordAuthentication=no $identifier true && { tput setaf 2; echo 'Success!'; } || { tput setaf 1; echo 'Failure'; }; tput sgr0 | |
ssh_load_autocomplete | |
fi | |
} | |
# adds ~/.ssh/config to the ssh autocomplete | |
ssh_load_autocomplete() | |
{ | |
complete -W "$(awk '/^\s*Host\s*/ { sub(/^\s*Host /, ""); print; }' ~/.ssh/config)" ssh | |
} | |
# adds ~/.ssh/config to the ssh autocomplete | |
ssh_load_autocomplete |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment