Logowanie przez ssh powolne przez DNS Timeout

Z Thomas-Krenn-Wiki
Przejdź do nawigacji Przejdź do wyszukiwania

W tym artykule omówiono możliwe rozwiązania wolnego logowania SSH.

Problem

Podczas próby zalogowania się przez SSH w systemie Linux, pojawienie się zapytania o hasło trwa zbyt długo (ok. 10 sekund). Następnie sesja SSH funkcjonuje normalnie.

Przyczyny

Serwer SSH próbuje wykonać reverse DNS Lookup dla IP, z którego jest tworzone połączenie SSH. Jeżeli na systemie docelowym nie jest skonfigurowany funkcjonujący DNS (np. w /etc/resolv.conf jest podany błędny adres IP serwera DNS) to musi upłynąć 10 sekund zanim zostanie osiągnięty timeout dla reverse DNS Lookup. Dopiero wtedy pojawia się zapytanie o hasło.

Informacje podczas korzystania z ssh -v (verbose mode):

[admin@tpw admin]$ ssh -v root@192.168.1.154
OpenSSH_5.1p1, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug1: Connecting to 192.168.1.154 [192.168.1.154] port 22.
debug1: Connection established.
debug1: identity file /home/admin/.ssh/identity type -1
debug1: identity file /home/admin/.ssh/id_rsa type -1
debug1: identity file /home/admin/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-cbc hmac-md5 none
debug1: kex: client->server aes128-cbc hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '192.168.1.154' is known and matches the RSA host key.
debug1: Found key in /home/admin/.ssh/known_hosts:153
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received

Po upływie 10 sekund dalsza kontynuacja:

debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/admin/.ssh/identity
debug1: Trying private key: /home/admin/.ssh/id_rsa
debug1: Trying private key: /home/admin/.ssh/id_dsa
debug1: Next authentication method: password
root@192.168.1.154's password:

Po wprowadzeniu hasła dalszy przebieg:

debug1: Authentication succeeded (password).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.utf8
Linux debian5 2.6.9-023stab048.6-smp #1 SMP Mon Nov 17 18:41:14 MSK 2008 x86_64

The programs included with the Debian GNU/Linux system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Debian GNU/Linux comes with ABSOLUTELY NO WARRANTY, to the extent
permitted by applicable law.
Last login: Wed Jun 17 13:20:19 2009 from 192.168.1.52
debian5:~#

Rozwiązanie

Podać w systemie cel (w /etc/hosts) adresu IP komputera, z którego będzie tworzone połączenie lub upewnić się, że konfiguracja DNS w systemie docelowym działa.

Dodanie IP w /etc/hosts

Adres IP może zostać wprowadzony w /etc/hosts np. w następujący sposób:

root@debian5:/# echo "192.168.1.52 laptop" >> /etc/hosts
root@debian5:/# cat /etc/hosts
127.0.0.1  debian5 localhost localhost.localdomain

::1     localhost ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
ff02::3 ip6-allhosts
192.168.1.52 laptop
root@debian5:/#

Kontrola konfiguracji DNS

W przykładzie skonfigurowany był w systemie celu Debianie 5 błędny serwer DNS. Konfiguracja jest następująco korygowana.

root@debian5:/# cat /etc/resolv.conf
nameserver 10.10.18.1
root@debian5:/# echo "nameserver 192.168.1.254" > /etc/resolv.conf
root@debian5:/# cat /etc/resolv.conf
nameserver 192.168.1.254
root@debian5:/#

Dalsze informacje

Powiązane artykuły

Zabezpieczenie loginu SSH w Debianie z fail2ban