Aunque generar las claves publica/privada y subirlas a un servidor remoto SSH para que nos permita conectar directamente a la máquina sin necesidad de que nos pida la password es muy sencillo, nunca ésta de más tener un simple script que nos simplifique éstos pasos. Para ello podemos usar sshput, que nos permite generar las claves y despues indicando el usuario y dirección del servidor ssh, ya se encarga de subir la clave pública para que las siguientes veces que queramos acceder a ése servidor (y si tenemos los correspondientes permisos a la máquina) ya no tengamos que meter la password.
Sintaxis: sshput usuario_remoto@maquina_remota
#!/bin/sh
# sshput <remotehost>
#
# Puts your local DSA public key into the .ssh/authorized_keys
# on a remote machine. This should allow you to login without
# needing a password.
#
# This software comes with no guarantees whatsoever, and is yours to
# do with as you will. I'd be grateful if you feed any generally-useful
# improvements back to me, for the benefit of others.
#
# Quentin Stafford-Fraser http://www.qandr.org/quentin
PUBKEY="${HOME}/.ssh/id_dsa.pub"
if [ $# -ne 1 -o "$1" = "-h" ]
then
echo
echo Syntax:
echo "$0 [user@]<remotehost>"
echo
exit 1
fi
if [ ! -r ${PUBKEY} ]
then
echo
echo Public key ${PUBKEY} not found.
echo You can generate this by running
echo " ssh-keygen -t dsa"
echo Then come back and run $0 again.
echo
exit 1
fi
echo If you are prompted for a password, enter your password on the
echo remote machine.
cat ${HOME}/.ssh/id_dsa.pub | \
ssh $1 'mkdir -p -m 0700 ${HOME}/.ssh && \
cat >> $HOME/.ssh/authorized_keys && \
chmod 0600 $HOME/.ssh/authorized_keys'
if [ $? -eq 0 ]
then
echo Public key installed on remote machine.
echo You should now be able to connect with
echo " ssh $1"
exit 0
else
echo Sorry, an error occurred!
exit 1
fi
Enlace | sshput
Comentarios recientes