1.首先打开debug,看看慢在哪里

[root@BC-NFS1 ~]# ssh -v root@192.168.102.41 -p 22
OpenSSH_6.6.1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 56: Applying options for *
debug1: Connecting to 192.168.102.41 [192.168.102.41] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
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: identity file /root/.ssh/id_ed25519 type -1
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_6.6.1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.6.1
debug1: match: OpenSSH_6.6.1 pat OpenSSH_6.6.1* compat 0x04000000
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: kex: curve25519-sha256@libssh.org need=16 dh_need=16
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA 52:28:48:e7:49:2a:c3:56:78:c1:ea:78:58:56:ab:27
debug1: Host '192.168.102.41' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
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: FILE:/tmp/krb5cc_0) debug1: Unspecified GSS failure. Minor code may provide more information
No Kerberos credentials available (default cache: FILE:/tmp/krb5cc_0) debug1: Next authentication method: publickey
debug1: Offering RSA public key: /root/.ssh/id_rsa
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
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.102.41's password:

2.修改配置文件

在被远程登录的服务器上执行以下操作
vi /etc/ssh/sshd_config
UseDNS no
看到我的debug信息有这些,说明还需要修改/etc/ssh/sshd_config
debug1: Next authentication method: gssapi-with-mic
debug1: Unspecified GSS failure. Minor code may provide more information
vi /etc/ssh/ssh_config
GSSAPIAuthentication no

3.重启服务

systemctl restart sshd

有的人的问题出在输入密码之后要等待10-20s

root@x.x.x.x's password:
debug1: Authentication succeeded (password).
Authenticated to x.x.x.x ([x.x.x.x]:xx).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.

通过日志可以发现,密码的验证没有损耗时间,已经正确验证通过Authentication succeeded (password)
哪么到底是什么原因导致的速度这么慢?

打开服务器的系统日志,查看

tail -f /var/log/auth.log
sshd[12642]: pam_systemd(sshd:session): Failed to create session: Connection timed out
dbus[617]: [system] Failed to activate service 'org.freedesktop.login1': timed out
sshd[12642]: Received disconnect from x.x.x.x port 52856:11: disconnected by user
sshd[12642]: Disconnected from x.x.x.x port 52856
sshd[12642]: pam_unix(sshd:session): session closed for user root
sshd[12689]: userauth_pubkey: key type ssh-dss not in PubkeyAcceptedKeyTypes [preauth]
sshd[12689]: Accepted password for root from x.x.x.x port 52866 ssh2
sshd[12689]: pam_unix(sshd:session): session opened for user root by (uid=0)
sshd[12689]: pam_systemd(sshd:session): Failed to create session: Connection timed out
dbus[617]: [system] Failed to activate service 'org.freedesktop.login1': timed out

从日志中可以看到[system] Failed to activate service 'org.freedesktop.login1': timed out

的错误,查了下资料,大致意思如下:
dbus的服务重启后,systemd-logind服务没有重启导致,可以查看systemctl status systemd-logind的状态,解决方法就是重启该服务 systemctl restart systemd-logind
重启systemd-logind服务后,发现ssh可以秒连接了

解决ssh登录过慢问题的更多相关文章

  1. 解决SSH登录用户执行的命令部分环境变量参数不生效的问题

    问题概况 linux机器在/etc/profile配置完成环境变量后,SSH到目标机器执行命令,但是获取不到已配置的环境变量值. 例如场景: 在/etc/profile配置了http代理 export ...

  2. 解决ssh登录Host key verification failed

    使用SSH登录某台机器,有时因为server端的一些变动,会出现以下信息: @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @    WARNING: R ...

  3. 如何解决SSH登录Solaris主机速度慢的问题

    SSH登录速度慢可能有多种原因. 1. 与DNS有关 缺省情况下,当客户端用SSH登录solaris服务器时,服务器会试图反向解析客户端的IP 地址(即把IP地址解析成机器名).如果Solaris系统 ...

  4. 解决 ssh 登录到ubuntu server 慢的问题

    最近在服务器上使用ubuntu系统,服务器上开启sshd服务,在客户端处使用ssh登录到服务器的时候出现卡顿的现象. 在网上搜索了解决方案,主要是: 1. 修改服务器的 /etc/ssh/sshd_c ...

  5. 解决ssh登录慢,等待时间长的问题

    有时候在ssh远程登录到其他主机上时发现登录时间太长,经过亲自测试,发现主要有两个问题会导致ssh登录慢: 1.使用了dns反查,这样的话当ssh某个IP时,系统会试图通过DNS反查相对应的域名,如果 ...

  6. 解决ssh登录很慢的问题以及jumpserver登录主机出现:Authentication timeout

    一.问题 登录ssh输入用户名后,等待很长时间20-30秒左右才显示输入密码提示框,从而导致通过jumpserver堡垒机登录主机时,报错:Authentication timeout Opt> ...

  7. 解决ssh登录后闲置时间过长而断开连接

     ++++++++++++++++++++++++++++ #!/usr/bin/env bash password_5="Uxxx7"host_5="129.x.x.1 ...

  8. Mac 解决SSH登录服务器终端乱码

    一.Mac自带的终端 ssh 连接Linux 乱码,可用如下方法解决 终端 --> 偏好设置 --> 描述文件 --> 高级  --> 设为GBK 即可 二.secureCRT ...

  9. [转]解决ssh登录后闲置时间过长而断开连接

    本文转自: 转载自博客园wanghetao的博客 我们通过终端连接服务器时,当鼠标和键盘长时间不操作,服务器就会自动断开连接,我们还的需要重新连接,感觉很麻烦,总结一下解决此问题的方法 方法一 修改/ ...

随机推荐

  1. ZOJ 2532 Internship 求隔边

    Internship Time Limit: 5 Seconds      Memory Limit: 32768 KB CIA headquarter collects data from acro ...

  2. Tomcat7项目迁移到Tomcat8中文乱码问题

    我打算开始使用Tomcat8了,先解决中文乱码问题,在解决其它的问题! 个人推荐:修改server.xml方式 对于SpringMVC报的错误我稍后在补充问题 1.问题描述 Tomcat 7下项目切换 ...

  3. mysql按月统计六个月内不同类型订单的成交金额

    mysql按月统计六个月内不同类型订单的成交金额 创建数据库 CREATE DATABASE test; 创建订单表 CREATE TABLE `t_order` ( `id` ) NOT NULL ...

  4. [Leetcode] LRU 算法实现

    Design and implement a data structure for Least Recently Used (LRU) cache. It should support the fol ...

  5. sql生成一个日期表

    SET ANSI_NULLS ONGOSET QUOTED_IDENTIFIER ONGO-- =============================================-- Auth ...

  6. 确保web安全的https、确认访问用户身份的认证(第七章、第八章)

    第七章 确保web安全的https 1.http的缺点: (1)通信使用明文,内容可能会被窃听 (2)不验证通信方的身份,因此有可能遭遇伪装 (3)无法证明报文的完整性,因此有可能已遭篡改. 2.通信 ...

  7. 洛谷 3029 [USACO11NOV]牛的阵容Cow Lineup

    https://www.luogu.org/problem/show?pid=3029 题目描述 Farmer John has hired a professional photographer t ...

  8. 组合数学--约瑟夫环问题 Josephus

    约瑟夫斯问题(有时也称为约瑟夫斯置换),是一个出现在计算机科学和数学中的问题.在计算机编程的算法中,类似问题又称为约瑟夫环. 有n个囚犯站成一个圆圈,准备处决.首先从一个人开始,越过k-2个人(因为第 ...

  9. [洛谷P1822] 魔法指纹

    洛谷题目连接:魔法指纹 题目描述 对于任意一个至少两位的正整数n,按如下方式定义magic(n):将n按十进制顺序写下来,依次对相邻两个数写下差的绝对值.这样,得到了一个新数,去掉前导0,则定义为ma ...

  10. 【设计模式】 模式PK:策略模式VS桥梁模式

    1.概述 我们先来看两种模式的通用类图. 两者之间确实很相似.如果把策略模式的环境角色变更为一个抽象类加一个实现类,或者桥梁模式的抽象角色未实现,只有修正抽象化角色,想想看,这两个类图有什么地方不一样 ...