解决sshd连接缓慢
Linux系统
脚本
#!/bin/bash
#更改ssh连接缓慢问题
echo "请输入要更改的主机名,回车跳过"
read i
if [[ "$i" != "" ]]
then
echo "$i">/etc/hostname
#获取当前网卡IP
ip=$(ip a show dev ens33|grep -w inet|awk '{print $2}'|sed 's/\/.*//')
#获取username
hostname=$(hostname)
echo "-----当前ens33网卡IP为$ip-----"
echo "-----当前主机名$hostname-----"
#配置hosts
echo "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 devmng" > /etc/hosts
echo "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6" >> /etc/hosts
echo "$ip $hostname" >> /etc/hosts
#注释掉server上/etc/resolv.conf中所有行或清空
echo >/etc/resolv.conf
#修改sshd 并重启查看状态
echo "UseDNS no" >> /etc/ssh/sshd_config
echo "-----正在重启SSH服务-----"
systemctl restart sshd
status=$(systemctl status sshd|grep Active)
#判断是否启动成功
status1=$(echo $status|grep "running")
if [[ "$status1" != "" ]]
then
echo "-----ssh重启成功-----"
else
echo "-----ssh重启失败-----"
fi
echo "-----脚本执行完毕 by:炫酷无敌石头-----"
else
echo "-----已跳过正在执行下一步-----"
#获取当前网卡IP
ip=$(ip a show dev ens33|grep -w inet|awk '{print $2}'|sed 's/\/.*//')
#获取username
hostname=$(hostname)
echo "-----当前ens33网卡IP为$ip-----"
echo "-----当前主机名$hostname-----"
#配置hosts
echo "127.0.0.1 localhost localhost.localdomain localhost4 localhost4.localdomain4 devmng" > /etc/hosts
echo "::1 localhost localhost.localdomain localhost6 localhost6.localdomain6" >> /etc/hosts
echo "$ip $hostname" >> /etc/hosts
#注释掉server上/etc/resolv.conf中所有行或清空
echo >/etc/resolv.conf
#修改sshd 并重启查看状态
echo "UseDNS no" >> /etc/ssh/sshd_config
echo "-----正在重启SSH服务-----"
systemctl restart sshd
status=$(systemctl status sshd|grep Active)
#判断是否启动成功
status1=$(echo $status|grep "running")
if [[ "$status1" != "" ]]
then
echo "-----ssh重启成功-----"
else
echo "-----ssh重启失败-----"
fi
echo "-----脚本执行完毕 by:炫酷无敌石头-----"
fi
windows 系统
报错内容
本机电脑的问题,在本地PC输入 ssh-keygen -R 192.144.181.42(云服务器IP)