目錄css
本文參考於https://www.cnblogs.com/fwdxl/p/6723820.html,在其基礎上略作整理。html
/etc/ssh/sshd_config
常常出現ssh鏈接緩慢,讓人誤覺得是ssh鏈接不上。緣由是由於server的sshd會去DNS查找訪問
client IP的hostname,若是DNS不可用或者沒有相關記錄,就會耗費大量時間。vim
vim /etc/ssh/sshd_config UseDNS no GSSAPIAuthentication no GSSAPICleanupCredentials no
配置文件中[UseDNS yes]被註釋,但默認開關就是yes...(SSH服務默認啓用了DNS反向解析的功能)api
/etc/nsswitch.conf
hosts: files dns
去掉dns服務器
這行的含義是對於訪問的主機進行域名解析的順序,是先訪問file,也就是/etc/hosts文件,若是hosts中沒有記錄域名,則訪問dns,進行域名解析;若是dns也沒法訪問,就會等待訪問超時後返回,所以等待時間比較長。那若是將這一行屏蔽掉是否是也能夠達到一樣的效果呢?應該是能夠的,可是若是本機要經過域名訪問其餘服務器,則確定沒法訪問,所以這行理論上應該須要保留。這個問題也提示咱們,dns若是不可用,會帶來的一些反作用的。session
/etc/hosts
若是還慢的話,檢查ssh服務端上/etc/hosts文件中,127.0.0.1對應的主機名是否和 uname -n的結果同樣,或者把本機ip和hostname(uname -n結果)加入到/etc/hosts裏。ssh
ssh -v
[root@ansible ~]# ssh -v root@192.168.75.136 OpenSSH_7.4p1, OpenSSL 1.0.2k-fips 26 Jan 2017 debug1: Reading configuration data /etc/ssh/ssh_config debug1: /etc/ssh/ssh_config line 58: Applying options for * debug1: Connecting to 192.168.75.136 [192.168.75.136] port 22. debug1: Connection established. debug1: permanently_set_uid: 0/0 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_rsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_dsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ecdsa-cert type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519 type -1 debug1: key_load_public: No such file or directory debug1: identity file /root/.ssh/id_ed25519-cert type -1 debug1: Enabling compatibility mode for protocol 2.0 debug1: Local version string SSH-2.0-OpenSSH_7.4 debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3 debug1: match: OpenSSH_5.3 pat OpenSSH_5* compat 0x0c000000 debug1: Authenticating to 192.168.75.136:22 as 'root' debug1: SSH2_MSG_KEXINIT sent debug1: SSH2_MSG_KEXINIT received debug1: kex: algorithm: diffie-hellman-group-exchange-sha256 debug1: kex: host key algorithm: ssh-rsa debug1: kex: server->client cipher: aes128-ctr MAC: umac-64@openssh.com compression: none debug1: kex: client->server cipher: aes128-ctr MAC: umac-64@openssh.com compression: none debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16 debug1: kex: diffie-hellman-group-exchange-sha256 need=16 dh_need=16 debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<3072<8192) sent debug1: got SSH2_MSG_KEX_DH_GEX_GROUP debug1: SSH2_MSG_KEX_DH_GEX_INIT sent debug1: got SSH2_MSG_KEX_DH_GEX_REPLY debug1: Server host key: ssh-rsa SHA256:U+p+ybfgROyI0fCuyLffRhMMBeDIuzR4AdVWfNO7MhY The authenticity of host '192.168.75.136 (192.168.75.136)' can't be established. RSA key fingerprint is SHA256:U+p+ybfgROyI0fCuyLffRhMMBeDIuzR4AdVWfNO7MhY. RSA key fingerprint is MD5:a5:98:06:58:84:35:d3:f4:4c:f8:43:a1:a5:12:f5:8e. Are you sure you want to continue connecting (yes/no)? yes 保存祕鑰的交互信息 Warning: Permanently added '192.168.75.136' (RSA) to the list of known hosts. debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_NEWKEYS sent debug1: expecting SSH2_MSG_NEWKEYS debug1: SSH2_MSG_NEWKEYS received debug1: rekey after 4294967296 blocks debug1: SSH2_MSG_SERVICE_ACCEPT received debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password debug1: Next authentication method: gssapi-keyex debug1: No valid Key exchange context debug1: Next authentication method: gssapi-with-mic debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Unspecified GSS failure. Minor code may provide more information No Kerberos credentials available (default cache: KEYRING:persistent:0) debug1: Next authentication method: publickey debug1: Trying private key: /root/.ssh/id_rsa debug1: Trying private key: /root/.ssh/id_dsa debug1: Trying private key: /root/.ssh/id_ecdsa debug1: Trying private key: /root/.ssh/id_ed25519 debug1: Next authentication method: password root@192.168.75.136's password: 輸入root用戶登陸密碼 debug1: Authentication succeeded (password). Authenticated to 192.168.75.136 ([192.168.75.136]:22). debug1: channel 0: new [client-session] debug1: Requesting no-more-sessions@openssh.com debug1: Entering interactive session. debug1: pledge: network debug1: Sending environment. debug1: Sending env LANG = en_US.UTF-8 Last login: Tue Jun 18 22:35:15 2019 from 192.168.75.145