Skip to content

Instantly share code, notes, and snippets.

@thejhh
Created January 6, 2012 12:07
Show Gist options
  • Select an option

  • Save thejhh/1570293 to your computer and use it in GitHub Desktop.

Select an option

Save thejhh/1570293 to your computer and use it in GitHub Desktop.
Script to install pubkey on remote SSH server
#!/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