I just got fed up with having to enter the password for ssh connections time and again. Of course, it's a simple matter of copying a few files and setting a few permissions, but I just can't remember the exact things to do. So here you go: just create a key with
ssh-keygen -t dsa
and run this script:
#!/bin/sh
# rhive.sh - create remote hive (well, RSA authentication).
# $1 needs to be 'user@host'. Need to enter password two or three times.
echo 'Creating remote .ssh directory...'
ssh $1 'mkdir -p ~/.ssh && chmod 700 ~/.ssh'
if [ -f ~/.ssh/identity.pub ] ; then
echo 'Transferring identity.pub -> known_hosts...'
scp ~/.ssh/identity.pub $1:~/.ssh/known_hosts
fi
if [ -f ~/.ssh/id_dsa.pub ] ; then
echo 'Transferring id_dsa.pub -> authorized_keys2...'
scp ~/.ssh/id_dsa.pub $1:~/.ssh/authorized_keys2
fi
echo 'Setting permissions on public keys...'
ssh $1 'chmod 600 ~/.ssh/*'
if [ -f ~/.ssh/identity.pub ] ; then
echo 'Transferring identity.pub -> known_hosts...'
scp ~/.ssh/identity.pub $1:~/.ssh/known_hosts
fi
I think you mean identity.pub ->
if [ -f ~/.ssh/id_dsa.pub ] ; then
echo 'Transferring id_dsa.pub -> authorized_keys2...'
scp ~/.ssh/id_dsa.pub $1:~/.ssh/authorized_keys2
fi
Ow, you just blatted the ssh public key that was already there from elsewhere. Try:
cat ~/.ssh/id_dsa.pub | ssh $1 "sh -c 'touch.ssh/authorized_keys2 ; chmod 600 .ssh/authorized_keys2 ; cat >> .ssh/authorized_keys'"