目录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