#!/bin/bash # A script to establish keys on a local and remote system and allow # access between the two systems # # usage: setup-ssh [ -u username ] hostname # # $Header: /home/hugh/sources/misc/setup-ssh,v 1.3 2005/04/23 01:18:36 hugh Exp hugh $ # set -x if [ $# -eq 0 ] then echo "usage: $0 [-u username] [-lp phrase] [-rp phrase] targetsystem" echo " -u username username on remote system if not the same" echo " -lp phrase passphrase to use on local system (no spaces)" echo " -rp phrase passphrase to use on remote system (no spaces)" exit 1 fi username="" lphrase="''" rphrase="''" while [ $# -gt 0 ] do case $1 in -u) shift username=$1;; -lp) shift lphrase=$1;; -rp) shift rphrase=$1;; *) hostname=$1;; esac shift done cd ~ rm -f /tmp/ss-temp /tmp/hmextract cat > /tmp/hmextract <<-EOF if [ ! -d .ssh -o ! -f .ssh/id_rsa ] then ssh-keygen -q -P ${rphrase} -t rsa -f ~/.ssh/id_rsa fi cd .ssh cat /tmp/tmp-id_rsa.pub >> authorized_keys chmod 700 authorized_keys rm -rf /tmp/tmp-id_rsa.pub cat id_rsa.pub cd .. EOF chmod +x /tmp/hmextract if [ ! -d .ssh -o ! -f .ssh/id_rsa ] then ssh-keygen -q -P ${lphrase} -t rsa -f ~/.ssh/id_rsa fi echo 'cat > /tmp/tmp-id_rsa.pub <<-EOF' >> /tmp/ss-temp cat .ssh/id_rsa.pub >> /tmp/ss-temp echo 'EOF' >> /tmp/ss-temp cat /tmp/hmextract >> /tmp/ss-temp if [ -n "$username" ] then string="`cat /tmp/ss-temp | ssh $hostname -l $username `" else string="`cat /tmp/ss-temp | ssh $hostname `" fi string="`echo $string | sed -e 's/^.*ssh-rsa/ssh-rsa/'`" echo $string >> ~/.ssh/authorized_keys chmod 700 ~/.ssh/authorized_keys rm -f /tmp/hmextract /tmp/ss-temp