sshput: Configurar el login sin password para servidores remotos SSH

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

01 #!/bin/sh
02 # sshput <remotehost>
03 #
04 # Puts your local DSA public key into the .ssh/authorized_keys
05 # on a remote machine.  This should allow you to login without
06 # needing a password.
07 #
08 # This software comes with no guarantees whatsoever, and is yours to
09 # do with as you will. I'd be grateful if you feed any generally-useful
10 # improvements back to me, for the benefit of others.
11 #
12 #                Quentin Stafford-Fraser  http://www.qandr.org/quentin
13
14 PUBKEY="${HOME}/.ssh/id_dsa.pub"
15
16 if [ $# -ne 1 -o "$1" = "-h" ]
17 then
18 echo
19 echo Syntax:
20 echo "$0 [user@]<remotehost>"
21 echo
22 exit 1
23 fi
24
25 if [ ! -r ${PUBKEY} ]
26 then
27 echo
28 echo Public key ${PUBKEY} not found.
29 echo You can generate this by running
30 echo "  ssh-keygen -t dsa"
31 echo Then come back and run $0 again.
32 echo
33 exit 1
34 fi
35
36 echo If you are prompted for a password, enter your password on the
37 echo remote machine.
38
39 cat ${HOME}/.ssh/id_dsa.pub | \
40 ssh $1 'mkdir -p -m 0700 ${HOME}/.ssh && \
41 cat >> $HOME/.ssh/authorized_keys && \
42 chmod 0600 $HOME/.ssh/authorized_keys'
43
44 if [ $? -eq 0 ]
45 then
46 echo Public key installed on remote machine.
47 echo You should now be able to connect with
48 echo "    ssh $1"
49 exit 0
50 else
51 echo Sorry, an error occurred!
52 exit 1
53 fi

 

Fuente: sshput | ubuntulife

¿Quién está en línea?

Hay 46926 invitados y ningún miembro en línea