Created
January 6, 2012 12:07
-
-
Save thejhh/1570293 to your computer and use it in GitHub Desktop.
Script to install pubkey on remote SSH server
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/sh | |
| # Copyright 2008 Jaakko Heusala <jheusala@iki.fi> | |
| # Sat, 17 May 2008 17:36:40 +0300 | |
| id_rsa_pub_file=".ssh/id_rsa.pub" | |
| for host in "$@"; do | |
| if test -f "$host"; then | |
| id_rsa_pub_file="$host" | |
| continue | |
| fi | |
| echo "$host: Installing $id_rsa_pub_file..." | |
| ssh "$host" 'cat > tmp.id_rsa.pub \ | |
| && mkdir -p .ssh \ | |
| && chmod 700 .ssh \ | |
| && touch .ssh/authorized_keys \ | |
| && chmod 600 .ssh/authorized_keys \ | |
| && cat tmp.id_rsa.pub >> .ssh/authorized_keys \ | |
| && rm tmp.id_rsa.pub' < $id_rsa_pub_file || exit 1 | |
| echo "$host: Installed" | |
| done |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment