Sto usando Ubuntu 14.04 e voglio bloccare l'accesso SSH in base al paese usando GeoIP (da https://www.axllent.org/docs/view/ssh-geoip/),
Si prega di trovare l'output del comando:
$ spawn
spawn: command not found
Così ho installato expect pacchetto ma non funziona ancora:
apt-get install expect
expect is already the newest version
Voglio eseguire il seguente script:
cat /etc/hosts.allow
sshd: ALL: spawn /usr/local/bin/sshfilter.sh %a
Hai qualche idea in merito allo stesso?
Risposta accettata:
In questo caso, sembra che spawn
si riferisce allo spawn
estensione a hosts.allow
sintassi, come descritto in RUNNING OTHER COMMANDS
sezione della pagina man 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.
Il fatto che spawn
restituisce un errore quando si tenta di eseguirlo al di fuori di quel contesto (ad esempio come comando nella shell) non è necessario che ti preoccupi, se si verificano problemi con il corretto funzionamento dello script di filtro GeoIP, questo è un problema separato.
Per dimostrare il corretto funzionamento di hosts.allow spawn
estensione su Ubuntu 14.04 senza impigliarsi in GeoIP, puoi creare uno script eseguibile minimo /usr/local/bin/sshfilter.sh che registra semplicemente l'indirizzo IP e quindi restituisce 0, ad es.
#!/bin/sh
logger "$0: connection from $1"
exit 0
Quindi con le seguenti righe aggiunte ai file hosts:
Correlati:Ubuntu bloccato nella schermata di accesso?In hosts.deny:
sshd: ALL
In hosts.allow:
sshd: ALL: spawn /usr/local/bin/sshfilter.sh %a
Quindi esegui
tail -f /var/log/syslog
in una finestra del terminale e, in un'altra, tentare di accedere tramite SSH:
ssh localhost
Dovresti vedere un messaggio nella coda del syslog come
Jul 25 08:03:59 T61p logger: /usr/local/bin/sshfilter.sh: connection from 127.0.0.1
Puoi confermare che funziona anche con aclexec
al posto di spawn
, come suggerito nell'articolo che hai collegato. In effetti in questo caso dovresti usare aclexec
dal momento che spawn
non utilizza il codice di uscita del processo generato per determinare se consentire la connessione, quale aclexec
fa .