Mostrando las entradas con la etiqueta ssh. Mostrar todas las entradas

Maintain known_hosts file with a puppet class

Each time an ssh client gets connected to another ssh remote host, a known_hosts file is generated or updated based on the remote host public key.

The purpose of this file is well explaines on the following link: http://en.wikibooks.org/wiki/OpenSSH/Client_Configuration_Files#.7E.2F.ssh.2Fknown_hosts

Let's say that we have a network with 100 servers and each time we add another server to this network all the machines need to update the known_hosts file with the new public key. 

First step: ask the new machine for it's public key with ssh-keyscan:

# ssh-keyscan localhost/remotehost
# localhost SSH-2.0-OpenSSH_5.3
localhost ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAygRKDjzHw1a1L79f5rNaGlqPUDndZv9KhtZPG2MYrUrU/9NiBOiVDWwllUwWXQkLY3fhdTVncjGfzn4oc09876J3uXZJaNWr0PZpD8S7Y6+50iZWYVA0fTM0j32WdD3MMfJjCtrXo+/gDx9+XiQPXlWqkuy5L5PRIvjIzVeZwL6BDDalmQXx3Jw5QcfQn9Bc7m+Bw7ZO80mxnFnKH5zZa8jdjd6XPSLXN0Q+5UlvZ5o5hxaFA+4ywtvKbF6avlQj5rm9+6kGUkVLIZRVw+lkkGqSixsTMGC3mZURH2s38UB1OjHXQSW8DP/mImcAAQWB3V5JDHbswee99C8CU6ekcw==

And manually append the output to your ssh_known_hosts/known_hosts file in the proper format (man ssh-keyscan):

     Output format for rsa1 keys:

     host-or-namelist bits exponent modulus

     Output format for rsa and dsa keys:

     host-or-namelist keytype base64-encoded-key

     Where keytype is either “ssh-rsa” or “ssh-dss”.


Distribute this file with a puppet class on your nodes and you won't be prompted again to add this new key into your known_hosts/ssh_known_hosts file at the first login attempt. 

For sure this is far from perfect, but solves the problem in a short time. 

Terminal Shells, Secure SHells improvement

Tengo un par de ligas por leer a detalle el día lunes para hacerme la vida mas placentera al sentar las nalgas en la terminal:
  1. loading local shell aliases to ssh session dynamicaly
  2. SSH Can Do That? Productivity Tips for Working with Remote Servers
Luego les explicaré los resultados.

sshd[11366] Authentication refused

sshd[11366]: Authentication refused: bad ownership or modes for directory 

Si la autenticación por llave anda fallando, pues hay que revisar en los logs del servidor remoto
De paso también hacer un ssh -vvv hostRemoto para ver que tanto sale

Finalmente el problema con esto era lo siguiente:


chmod go-w ~/
chmod 700 ~/.ssh
chmod 600 ~/.ssh/authorized_keys

Ejecutar comandos remotos sin conectarse del todo

Un tip:

Es posible ejecutar comandos remotos por medio de ssh sin necesidad de abrir una sesión formal.

$ ssh {host remoto} {comando}

De esta manera el host te pedirá usuario y password, cosa que se puede evitar si utilizas autenticación por llaves. De manera que puedes calendarizar chequeos de filesystems, envío de alertas, o lo que se te ocurra.