Estoy usando Ubuntu 14.04 y quiero bloquear el país de inicio de sesión de SSH usando GeoIP (de https://www.axllent.org/docs/view/ssh-geoip/),
Encuentre la salida del comando:
$ spawn
spawn: command not found
Entonces instalé expect paquete pero sigue sin funcionar:
apt-get install expect
expect is already the newest version
Quiero ejecutar el siguiente script:
cat /etc/hosts.allow
sshd: ALL: spawn /usr/local/bin/sshfilter.sh %a
¿Tienes alguna idea sobre lo mismo?
Respuesta aceptada:
En este caso, parece que spawn
se refiere al spawn
extensión a hosts.allow
sintaxis, como se describe en RUNNING OTHER COMMANDS
sección de la página de manual de hosts_options (5) (man hosts_options
):
RUNNING OTHER COMMANDS
aclexec shell_command
Execute, in a child process, the specified shell command, after
performing the %<letter> expansions described in the
hosts_access(5) manual page. The command is executed with
stdin, stdout and stderr connected to the null device, so that
it won't mess up the conversation with the client host. Example:
smtp : ALL : aclexec checkdnsbl %a
executes, in a background child process, the shell command
"checkdnsbl %a" after replacing %a by the address of the remote
host.
The connection will be allowed or refused depending on whether
the command returns a true or false exit status.
spawn shell_command
Execute, in a child process, the specified shell command, after
performing the %<letter> expansions described in the
hosts_access(5) manual page. The command is executed with
stdin, stdout and stderr connected to the null device, so that
it won't mess up the conversation with the client host. Example:
spawn (/usr/sbin/safe_finger -l @%h | /usr/bin/mail root) &
executes, in a background child process, the shell command
"safe_finger -l @%h | mail root" after replacing %h by the name
or address of the remote host.
El hecho de que spawn
devuelve un error cuando intenta ejecutarlo fuera de ese contexto (es decir, como un comando en el shell) no debe preocuparle; si tiene problemas con el funcionamiento adecuado del script de filtrado GeoIP, ese es un problema aparte.
Para demostrar el funcionamiento exitoso de hosts.allow spawn
extensión en Ubuntu 14.04 sin enredarse en GeoIP, puede crear un script ejecutable mínimo /usr/local/bin/sshfilter.sh que simplemente registra la dirección IP y luego devuelve 0, por ejemplo,
#!/bin/sh
logger "$0: connection from $1"
exit 0
Luego, con las siguientes líneas agregadas a los archivos de hosts:
Relacionado:¿Ubuntu atascado en la pantalla de inicio de sesión?En hosts.deny:
sshd: ALL
En hosts.permitir:
sshd: ALL: spawn /usr/local/bin/sshfilter.sh %a
Entonces corre
tail -f /var/log/syslog
en una ventana de terminal y, en otra, intente iniciar sesión a través de SSH:
ssh localhost
Debería ver un mensaje en la cola de syslog como
Jul 25 08:03:59 T61p logger: /usr/local/bin/sshfilter.sh: connection from 127.0.0.1
Puede confirmar que también funciona con aclexec
en lugar de spawn
, como se sugiere en el artículo que vinculó. De hecho, en este caso deberías usar aclexec
desde spawn
no utiliza el código de salida del proceso generado para determinar si se permite la conexión, lo cual aclexec
hace .