Deshabilitar la Asignación de una TTY

Normalmente, cuando nos conectamos via SSH-1 el servidor abre una seudoterminal. Esto no es asi si se ejecuta un comando no interactivo. La variable de entorno SSH_TTY contiene el nombre de la terminal asignada. La asignación ocurre incluso si se ha configurado un comando forzado Por ejemplo, si en authorized_keys tenemos:

command="echo SSH_TTY is [$SSH_TTY]" ssh-rsa AAA...
Tenemos:
someone@localhost:~$ ssh -l user machine.domain.es
SSH_TTY is [/dev/pts/5]
Connection to orion closed.
someone@localhost:~$ ssh -l user machine.domain.es echo "tutu"
SSH_TTY is []
Use la opción no-pty para deshabilitar la asignación de TTY. Esto funciona incluso si el cliente utiliza la opción -t para requerir una TTY.

Casiano Rodríguez León
2010-03-22
orte@europa:/tmp$ cd acme-svn/ lgforte@europa:/tmp/acme-svn$ vi Makefile.PL lgforte@europa:/tmp/acme-svn$ svn commit -m 'lgforte modification' Enviando Makefile.PL Transmitiendo contenido de archivos . Commit de la revisión 6. lgforte@europa:/tmp/acme-svn$ svn log Makefile.PL ------------------------------------------------------------------------ r6 | lgforte | 2009-04-23 11:54:54 +0100 (jue, 23 abr 2009) | 1 line lgforte modification ------------------------------------------------------------------------ r4 | casiano | 2009-03-05 15:56:20 +0000 (jue, 05 mar 2009) | 1 line sally in trunk: list of final comments ------------------------------------------------------------------------ r3 | casiano | 2009-03-05 15:56:02 +0000 (jue, 05 mar 2009) | 1 line sally in trunk: list of comments ------------------------------------------------------------------------ r1 | casiano | 2009-03-05 15:53:05 +0000 (jue, 05 mar 2009) | 1 line branches ------------------------------------------------------------------------

Véase también:



Subsecciones
Casiano Rodríguez León
2010-04-19
Soft:~/.ssh$ keychain ~/.ssh/id_dsa KeyChain 2.6.8; http://www.gentoo.org/proj/en/keychain/ Copyright 2002-2004 Gentoo Foundation; Distributed under the GPL * Initializing /home/lusasoft/.keychain/LusaSoft-sh file... * Initializing /home/lusasoft/.keychain/LusaSoft-csh file... * Initializing /home/lusasoft/.keychain/LusaSoft-fish file... * Starting ssh-agent * Initializing /home/lusasoft/.keychain/LusaSoft-sh-gpg file... * Initializing /home/lusasoft/.keychain/LusaSoft-csh-gpg file... * Initializing /home/lusasoft/.keychain/LusaSoft-fish-gpg file... * Starting gpg-agent * Adding 1 ssh key(s)... Identity added: /home/lusasoft/.ssh/id_dsa (/home/lusasoft/.ssh/id_dsa) Salva las variables de entorno en ~/.keychain/${HOSTNAME}-sh,
lusasoft@LusaSoft:~$ tree .keychain/
.keychain/
|-- LusaSoft-csh
|-- LusaSoft-csh-gpg
|-- LusaSoft-fish
|-- LusaSoft-fish-gpg
|-- LusaSoft-sh
`-- LusaSoft-sh-gpg
Estos ficheros contienen los comandos para establecer las variables de entorno. Por ejemplo:
$ cat -n .keychain/europa-sh
     1  SSH_AUTH_SOCK=/tmp/ssh-ctTDo22823/agent.22823; export SSH_AUTH_SOCK;
     2  SSH_AGENT_PID=22824; export SSH_AGENT_PID;
De este modo las subsiguientes llamadas no interactivas a ssh - por ejemplo, cron jobs - pueden hacer un source del correspondiente guión y conectarse con el único agente obviando asi la necesidad de solicitar las claves.
$ source ~/.keychain/europa-sh
$ ssh orion
Linux orion 2.6.8-2-686 #1 Tue Aug 16 13:22:48 UTC 2005 i686 GNU/Linux
Si abrimos otra terminal deberemos hacer de nuevo la llamada a source ~/.keychain/europa-sh. Por supuesto, lo mejor es poner la llamada a keychain y a source ~/.keychain/europa-sh en nuestro fichero de arranque ~/.bashrc o bash_profile.

/usr/bin/keychain ~/.ssh/id_dsa
source ~/.keychain/europa-sh

Cuando el Agente no Conoce la Clave

Cuando se ejecuta, keychain verifica que la clave especificada es conocida por el agente. Si no es así nos solicitará la passphrase.

Véase la siguiente secuencia de comandos. Primero ponemos una passphrase a la identidad por defecto:

lusasoft@LusaSoft:~$ ssh-keygen -p
Enter file in which the key is (/home/lusasoft/.ssh/id_rsa): /home/lusasoft/.ssh/id_dsa
Key has comment '/home/lusasoft/.ssh/id_dsa'
Enter new passphrase (empty for no passphrase): ***************
Enter same passphrase again: ***************
Your identification has been saved with the new passphrase.
A continuación limpiamos los agentes:
lusasoft@LusaSoft:~$ keychain --clear

KeyChain 2.6.8; http://www.gentoo.org/proj/en/keychain/
Copyright 2002-2004 Gentoo Foundation; Distributed under the GPL

 * Found existing ssh-agent (6927)
 * Found existing gpg-agent (6951)
 * ssh-agent: All identities removed.
 * gpg-agent: All identities removed.

Cargamos de nuevo keychain con la identidad por defecto:

lusasoft@LusaSoft:~$ keychain ~/.ssh/id_dsa

KeyChain 2.6.8; http://www.gentoo.org/proj/en/keychain/
Copyright 2002-2004 Gentoo Foundation; Distributed under the GPL

 * Found existing ssh-agent (6927)
 * Found existing gpg-agent (6951)
 * Adding 1 ssh key(s)...
Identity added: /home/lusasoft/.ssh/id_dsa (/home/lusasoft/.ssh/id_dsa)
Ahora se nos solicita la passphrase (por defecto mediante ssh-askpass). Después de escribirla la identidad es añadida al agente.

lusasoft@LusaSoft:~$ keychain --nogui ~/.ssh/id_dsa

KeyChain 2.6.8; http://www.gentoo.org/proj/en/keychain/
Copyright 2002-2004 Gentoo Foundation; Distributed under the GPL

 * Found existing ssh-agent (6927)
 * Found existing gpg-agent (6951)
 * Adding 1 ssh key(s)...
Enter passphrase for /home/lusasoft/.ssh/id_dsa: *********************
Identity added: /home/lusasoft/.ssh/id_dsa (/home/lusasoft/.ssh/id_dsa)

Tipos de Agentes

keychain soporta también gpg-agent. Por defecto arranca todos los agentes disponibles. Se puede limitar los agentes arrancados usando la opción --agents. Por ejemplo --agents 'gpg,ssh'

Agentes en Mal Estado

La llamada a keychain creará un nuevo agente si el fichero /home/pp2/.keychain/europa-sh queda obsoleto (por ejemplo, si SSH_AUTH_SOCK referencia un socket que no existe o no existe un proceso con pid el referenciado en SSH_AGENT_PID). Véase la siguiente sesión de comandos:

pp2@europa:~$ ps -fA | grep agent
casiano   6976  6911  0 10:57 ?        00:00:00 /usr/bin/ssh-agent x-session-manager
pp2      22824     1  0 12:42 ?        00:00:00 ssh-agent
pp2      22848     1  0 12:42 ?        00:00:00 gpg-agent --daemon
pp2      32569 30843  0 13:06 pts/13   00:00:00 grep agent
pp2@europa:~$ kill -9 22824
pp2@europa:~$ ps -fA | grep agent
pp2       3165 30843  0 13:07 pts/13   00:00:00 grep agent
casiano   6976  6911  0 10:57 ?        00:00:00 /usr/bin/ssh-agent x-session-manager
pp2      22848     1  0 12:42 ?        00:00:00 gpg-agent --daemon
pp2@europa:~$ keychain

KeyChain 2.6.8; http://www.gentoo.org/proj/en/keychain/
Copyright 2002-2004 Gentoo Foundation; Distributed under the GPL

 * Initializing /home/pp2/.keychain/europa-sh file...
 * Initializing /home/pp2/.keychain/europa-csh file...
 * Initializing /home/pp2/.keychain/europa-fish file...
 * Starting ssh-agent
 * Found existing gpg-agent (22848)

pp2@europa:~$ ps -fA | grep agent
pp2       3198     1  0 13:07 ?        00:00:00 ssh-agent
pp2       3225 30843  0 13:08 pts/13   00:00:00 grep agent
casiano   6976  6911  0 10:57 ?        00:00:00 /usr/bin/ssh-agent x-session-manager
pp2      22848     1  0 12:42 ?        00:00:00 gpg-agent --daemon

La opción -eval de keychain

La opción -eval de keychain hace que keychain envíe a stdout el contenido del script. Así podemos arrancar el agente y añadirle la clave en un paso con:

pp2@europa:~/Lbook$ eval `keychain -eval ~/.ssh/id_dsa`

Véase También



Subsecciones
Casiano Rodríguez León
2010-04-20