Skip to content

DevOps VN

DevOps là phải lười ~_~

  • NETWORK
  • Hệ thống
  • Cơ sở dữ liệu
  • Code
  • Trick
  • Home
  • 2019
  • Tháng Tám
  • 26
  • Xử lý lỗi SSH chậm của centos

Xử lý lỗi SSH chậm của centos

hansamu 08/26/2019

Nếu SSH tới  máy chủ quá chậm, kể cả SSH trong LAN, hay đối với máy chủ vừa mới cài xong, đôi khi mỗi lần SSH phải đợi tầm 5-10s mới login thành công. Nguyên nhân do sshd cố phân giải IP sang  hostname hoặc domain name đối với mọi IP truy cập tới. Để tắt việc này, sửa file sau đó restart service sshd

1
2
3
/etc/ssh/sshd_config
#change usrDNS ==> no
useDNS no

Nếu vấn đề vẫn k giải quyết, có thể debug như sau:
SSH tới máy chủ với option -vv xem nó chậm ở đâu
Ví dụ:

1
ssh -vv 10.186.32.13

Output như ở dưới

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
[root@web01 tmp]# ssh -vv 10.186.32.13
OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to 10.186.32.13 [10.186.32.13] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: identity file /root/.ssh/identity type -1
debug1: identity file /root/.ssh/identity-cert type -1
debug1: identity file /root/.ssh/id_rsa type -1
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: identity file /root/.ssh/id_dsa type -1
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3
debug1: match: OpenSSH_5.3 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit:
debug2: kex_parse_kexinit: first_kex_follows 0
debug2: kex_parse_kexinit: reserved 0
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 129/256
debug2: bits set: 495/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host '10.186.32.13' is known and matches the RSA host key.
debug1: Found key in /root/.ssh/known_hosts:17
debug2: bits set: 525/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /root/.ssh/identity ((nil))
debug2: key: /root/.ssh/id_rsa ((nil))
debug2: key: /root/.ssh/id_dsa ((nil))
debug2: key: /root/.ssh/id_ecdsa ((nil))
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Next authentication method: gssapi-keyex
debug1: No valid Key exchange context
debug2: we did not send a packet, disable method
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address
 
debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address
 
debug1: Unspecified GSS failure.  Minor code may provide more information
 
 
debug1: Unspecified GSS failure.  Minor code may provide more information
Cannot determine realm for numeric host address

Đến đây là thấy chậm, chúng ta tìm được nguyên nhân do GSSAPIAuthentication, vào tắt cấu hình này đi trong file /etc/ssh/sshd_config

1
GSSAPIAuthentication no

Posted in Hệ thống, Linux
Tagged centos ssh too slow, Solution for slow SSH login in CentOS
Previous Post: Thông báo khi có user SSH thành công qua email
Next Post: Create large ~1 GB random dataset in PostgreSQL

Primary Sidebar

Chuyên mục

  • Cơ sở dữ liệu (10)
    • Elasticsearch (1)
    • Mysql (1)
    • Oracle (2)
    • Posgresql (4)
  • Code (12)
    • BashShell (4)
    • batch (1)
    • Powershell (2)
    • Python (6)
  • Hệ thống (69)
    • Ảo hoá (7)
    • Container (6)
    • Linux (35)
    • Mail server (1)
    • Web server (2)
    • Windows (11)
  • NETWORK (10)
    • F5 ADC (1)
    • Firewall Juniper SRX (1)
  • Trick (28)

Lưu trữ

  • Tháng Năm 2022 (2)
  • Tháng Hai 2022 (1)
  • Tháng Bảy 2021 (1)
  • Tháng Sáu 2021 (2)
  • Tháng Năm 2021 (3)
  • Tháng Tư 2021 (1)
  • Tháng Một 2021 (1)
  • Tháng Mười Hai 2020 (1)
  • Tháng Mười 2020 (1)
  • Tháng Chín 2020 (1)
  • Tháng Sáu 2020 (2)
  • Tháng Năm 2020 (2)
  • Tháng Tư 2020 (3)
  • Tháng Ba 2020 (5)
  • Tháng Hai 2020 (1)
  • Tháng Một 2020 (2)
  • Tháng Chín 2019 (2)
  • Tháng Tám 2019 (13)
  • Tháng Bảy 2019 (7)
  • Tháng Sáu 2019 (4)
  • Tháng Năm 2019 (5)
  • Tháng Tư 2019 (1)
  • Tháng Hai 2019 (3)
  • Tháng Một 2019 (8)
  • Tháng Mười Hai 2018 (1)
  • Tháng Mười Một 2018 (2)
  • Tháng Mười 2018 (8)

Copyright © 2023 DevOps VN. Powered by WordPress and Stargazer.