连接先看报错:

There were 11 failed login attempts since the last successful login.

先前有上百上千失败login,被攻击了,把短时间尝试登录失败的ip加入黑名单

写个脚本:

#! /bin/bash
cat /var/log/secure|awk '/Failed/{print $(NF-3)}'|sort|uniq -c|awk '{print $2"="$1;}' > /root/black.txt
DEFINE="10"
for i in `cat /root/black.txt`
do
IP=`echo | awk '{split("'${i}'", array, "=");print array[1]}'`
NUM=`echo | awk '{split("'${i}'", array, "=");print array[2]}'`
if [ $NUM -gt $DEFINE ];then
grep $IP /etc/hosts.deny > /dev/null
if [ $? -gt 0 ];then
echo "sshd:$IP:deny" >> /etc/hosts.deny
fi
fi
done 

然后定时执行

crontab -e
*/ * * * *  sh /root/secure_ssh.sh

一分钟执行一次

攻击解决了,但是还是慢

其中xintd安装失败,yum镜像连不上所以换了

    -- :: cp /etc/yum.repos.d/CentOS-Base.repo /etc/yum.repos.d/CentOS-Base.repo.backup
-- :: cd /etc/yum.repos.d/
-- :: wget http://mirrors.163.com/.help/CentOS6-Base-163.repo
-- :: yum makecache
-- :: yum -y update
-- :: vi
-- :: yum install xinetd.x86_64
-- :: service xinetd start
-- :: /bin/systemctl start xinetd.service

各种修改/etc/resolv.conf

#nameserver 183.60.83.19
nameserver 8.8.8.8
nameserver 114.114.114.114
#nameserver 183.60.82.98
#search localdomain
#options timeout: rotate

重启网络

/etc/init.d/network restart

不起作用

把网上流行做法,都做了

systemcts status systemd-logind

因为确实有login超时

也顺便

systemctl restart dbus

了一下,没用

费力气安装stract,用它来查看栈信息

strace -o ~/starce_ssh.txt -T ssh localhost
tail -f ~/starce_ssh.txt

但是看不懂。。。。。。

下面的肯定先做了

vim /etc/ssh/sshd_config

UseDNS no
#service sshd restart

修改GSSAPIAuthentication参数为 no,默认是yes

#service sshd restart

显然是没用,采用上上面的方法

也调试日志了

ssh  -vvv root@*.*.*.*

输入密码后,在这里等待

debug1: Next authentication method: password
root@*********'s password:
debug3: packet_send2: adding (len padlen extra_pad )
debug2: we sent a password packet, wait for reply
debug3: Wrote bytes for a total of
debug1: Authentication succeeded (password).
debug1: channel : new [client-session]
debug3: ssh_session2_open: channel_new:
debug2: channel : send open
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug3: Wrote bytes for a total of

很久以后

debug1: Entering interactive session.
debug3: Wrote bytes for a total of
debug1: client_input_global_request: rtype hostkeys-@openssh.com want_reply
debug2: callback start
debug2: client_session2_setup: id
debug2: channel : request pty-req confirm
debug2: channel : request shell confirm
debug2: fd setting TCP_NODELAY
debug2: callback done
debug2: channel : open confirm rwindow rmax
debug3: Wrote bytes for a total of
debug2: channel_input_status_confirm: type id
debug2: PTY allocation request accepted on channel
debug2: channel : rcvd adjust
debug2: channel_input_status_confirm: type id
debug2: shell request accepted on channel
Last failed login: Thu Jun :: CST from 112.85.42.201 on ssh:notty
There were failed login attempts since the last successful login.
Last login: Thu Jun :: from 124.204.55.194
[root@VM_128_5_centos ~]#

分析了很久很多停顿时候以及前后的打印信息,对比

这些客户端信息正常

查看服务器日志:

tail -f /var/log/messages

登录时认证很快,并创建session

Jun  :: localhost systemd: Started Session  of user root.
Jun :: localhost systemd-logind: New session of user root.
Jun :: localhost systemd: Starting Session of user root.

详细日志

Jun  :: localhost sshd[]: Accepted password for root from 124.204.55.194 port  ssh2
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd-logind: New session of user root.
Jun :: localhost systemd: Starting Session of user root.
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd: Starting Session of user root.
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd: Starting Session of user root.
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd: Starting Session of user root.
Jun :: localhost sshd[]: Failed password for root from 123.59.209.10 port ssh2
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd: Starting Session of user root.
Jun :: localhost sshd[]: Received disconnect from 123.59.209.10 port :: Normal Shutdown, Thank you for playing [preauth]
Jun :: localhost sshd[]: Disconnected from 123.59.209.10 port [preauth]
Jun :: localhost systemd: Started Session of user root.
Jun :: localhost systemd: Starting Session of user root.

前面并没有这么多凭空的session产生,现在为什么这么多?

线索:https://www.depesz.com/2010/12/13/a-tale-of-slow-ssh-connections/

https://major.io/2015/07/27/very-slow-ssh-logins-on-fedora-22/

https://serverfault.com/questions/707377/slow-ssh-login-activation-of-org-freedesktop-login1-timed-out#

https://bugs.debian.org/cgi-bin/bugreport.cgi?bug=793814

ssh 连接慢问题的更多相关文章

  1. Linux实战教学笔记05:远程SSH连接服务与基本排错(新手扫盲篇)

    第五节 远程SSH连接服务与基本排错 标签(空格分隔):Linux实战教学笔记-陈思齐 第1章 远程连接LInux系统管理 1.1 为什么要远程连接Linux系统 在实际的工作场景中,虚拟机界面或物理 ...

  2. 树莓派3B的食用方法-1(装系统 网线ssh连接)

    首先要有一个树莓派3B , 在某宝买就行, 这东西基本上找到假货都难,另外国产和英国也没什么差别,差不多哪个便宜买哪个就行. 不要买店家的套餐,一个是配的东西有些不需要,有的质量也不好. 提示:除了G ...

  3. REDHAT一总复习1 ssh配置 禁用root用户SSH连接

    生成SSH公钥 $ ssh-keygen 生成的公钥安装到指定的服务器上,这里安装到desktop0上的student账户 $ ssh-copy-id desktop0 $ su - 禁用root用户 ...

  4. 虚拟机利用Host-only实现在不插网线的情况下,虚拟机与主机实现双向通信,实现ssh连接以及samba服务实现共享

    为了不影响其他的虚拟网卡,我们在VMware下在添加一块虚拟网卡: 然后点击Next,选择连接方式: 点击Finish即可. 重新启动虚拟机,如果这是你手动添加的第一块虚拟网卡,那么应该是eth1. ...

  5. ssh连接失败,排错经验

    一.场景描述 ssh连接服务器,发现连接失败,但是对应服务器的ip能够ping通. 场景: [root@yl-web ~]# ssh root@10.1.101.35 ssh_exchange_ide ...

  6. 如何在断开ssh连接后仍然保持服务器正常运行程序

    问题描述:当SSH远程连接到服务器上,然后运行一个Python程序(bpr.py),然后把终端开闭(切断SSH连接)之后,发现该程序执行中断. 解决方法:使用nohup命令让程序在关闭窗口(切换SSH ...

  7. ssh连接linux服务器只显示-bash-4.1#不显示路径解决方法

    ssh连接linux服务器只显示-bash-4.1#不显示路径时,我们只需要修改  ~/.bash_profile文件,如果不存在这个文件,那么新建一个,增加内容  export PS1='[\u@\ ...

  8. Linux:ssh连接服务器很慢

    ssh连接服务器,如果很慢,可以进行如下处理: vi /etc/ssh/sshd_config#UseDNS yes改成:UseDNS no/etc/init.d/sshd restart ----- ...

  9. 云主机不能外网ssh连接,只能内网ssh连接的问题处理

    某台服务器外网无法ssh,内网可以ssh连接,ping值延时比较大 安装iftop查看流量 yum install -y iftop iftop界面含义如下 第一行:带宽显示 中间部分:外部连接列表, ...

  10. 【linux】——FreeBSD 建立 SSH 连接慢的解决方法

    一般在编写 linux 程序的时候,会使用 SecureCRT 或者 xshell 等工具远程登录到 linux 服务器上.最近发现在建立 SSH 连接的时候,非常慢,但是建立连接成功之后可以正常使用 ...

随机推荐

  1. “全栈2019”Java第一百零二章:哪些作用域可以声明局部内部类?

    难度 初级 学习时间 10分钟 适合人群 零基础 开发语言 Java 开发环境 JDK v11 IntelliJ IDEA v2018.3 文章原文链接 "全栈2019"Java第 ...

  2. spring管理hibernate session的问题探究

    我们再用spring管理hibernate的时候, 我们会继承HibernateDaoSupport 或者HibernateTemplate类. 我们不知道这两个类之间有什么关系. 也没有去关闭ses ...

  3. AWS 推出长期支持的 OpenJDK 免费分发版本 —— Amazon Corretto

    简评:听说 Oracle JDK 要收费了,Oracle 要限制 Java 的商业或生产用途,针对这个问题,AWS 将会推出 Amazon Corretto. Java 是 AWS 用户使用的最流行的 ...

  4. P4383 [八省联考2018]林克卡特树lct

    题目链接 题意分析 一句话题意就是 : 让你选出\((k+1)\)条不相交的链 使得这些链的边权总和最大 (这些链可以是点) 我们考虑使用树形\(DP\) \(dp[i][j][0/1/2]\)表示以 ...

  5. 启动多个appium服务(同时运行多台设备)

    准备: 一台真机一台模拟器(使用的是“夜神模拟器”) 先查看是否检测到设备  adb devices    由上图可看出没有检测到模拟器(夜神模拟器已开启) 可通过以下配置完成: 第一步:找到adb的 ...

  6. Access network

    1       State transfering A•Mobility:开机-搜寻PLMN/CELL来发现自己在网络中的位置•Attach request•Auth request•Auth res ...

  7. 不好意思啊,我上周到今天不到10天时间,用纯C语言写了一个小站!想拍砖的就赶紧拿出来拍啊

    花10天时间用C语言做了个小站 http://tieba.yunxunmi.com/index.html 简称: 云贴吧 不好意思啊,我上周到今天不到10天时间,用纯C语言写了一个小站!想拍砖的就赶紧 ...

  8. vs2013 调试libevent 源码

    自己内功的提升,无非是向前辈学习和修炼自身,对于编码也是如此,学习优秀的库只有从 源代码学起,才能深刻理解库实现的来龙去脉,加深自己的理解,提升自己的功力. 今天就介绍一下vs2013 下面调试lib ...

  9. 删除eclipse无效的工作空间路径

    eclipse会记录我们使用过的工作空间的路径,方便下面使用.也可以根据自己的需要删除无用的工作空间路径.

  10. 深入理解java集合框架之---------Linked集合 -----构造函数

    linked构造函数 1.LinkedList(): 构造一个空列表的集合 /** * 序列化 */ private static final long serialVersionUID = 1090 ...