[Python-Dev] Expect in python

Gustavo Niemeyer niemeyer@conectiva.com
Sun, 24 Nov 2002 15:27:47 -0200


[...]
> The application is an ssh key installer for dummies; you give it a
> remote hostname and (optionally) the username to log in as. First, it
> It walks the user through generating and populating a local .ssh with
> keypairs if they're not already presennt.  It then handles all the
> fiddly bits of making sure there's a remote .ssh directory, checking
> permissions, copying public keys from the local .ssh to the remote
> one, etc.
> 
> The idea is to allow a novice user to type
> 
> 	ssh-installkeys remotehost@somewhere.com
> 
> and have the Right Thing happen.  This is worth automating because 
> there are a bunch of obscure bugs you can run into if you get it
> even slightly wrong.  ssh -d diagnostics deliberately don't pass back
> warnings about bad file and directory permissions, for example, because
> that might leak sesnsitive information about the remote system.  I plan
> to give this script to the openssh guys for their distribution.
[...]

If you get anything better than the hackish script I made, please let me
know (and include an attached copy ;-).

[niemeyer@ibook ~]% cat ~/.shell/ssh-install-keys 
#!/bin/sh
USERHOST=$1
RSA1KEY=~/.ssh/identity.pub
RSA2KEY=~/.ssh/id_rsa.pub
DSA2KEY=~/.ssh/id_dsa.pub
SSHTMPDIR=~/.ssh-install-keys
if [ -z "$USERHOST" ]; then
	echo "Usage: ssh-install-keys [<user>@]<host>"
	exit 1
fi
KEYS=""
echo "Searching for available keys..."
for KEY in $RSA1KEY $RSA2KEY $DSA2KEY; do
	if [ -f $KEY ]; then
		KEYS="$KEYS $KEY"
	fi
done
echo "Creating temporary .ssh directory with found keys..."
umask 077
rm -rf $SSHTMPDIR
mkdir -p $SSHTMPDIR/.ssh
cat $KEYS > $SSHTMPDIR/.ssh/authorized_keys
echo "Copying temporary .ssh directory to $USERHOST..."
scp -pqr $SSHTMPDIR/.ssh $USERHOST:~/
echo "Removing temporary .ssh directory..."
rm -rf $SSHTMPDIR
echo "Done!"

-- 
Gustavo Niemeyer

[ 2AAC 7928 0FBF 0299 5EB5  60E2 2253 B29A 6664 3A0C ]