shell脚本 修复ssh登录慢

问题现象:

        xshell连接服务器会话很慢

解决:

        具体脚本如下,执行即可生效

#!/bin/bash
 
set -e
function init(){
	echo "初始化"
}
 
#初始化
init
 
 
function check(){
	if [ ""$2 == "" ];
	then
		echo "$1的属性不在配置文件中"
		exit 1
	fi
}
 
function exec_method(){
	#确保属性的值都是指定值,查不到属性需要退出
	
	#GSSAPIAuthentication no
	flag=$(cat /etc/ssh/sshd_config|grep GSSAPIAuthentication|awk NR==1'{print $2}')
	check GSSAPIAuthentication ${flag}
	if [ ${flag}"" != "no" ];
	then
		row=$(cat -n /etc/ssh/sshd_config|grep GSSAPIAuthentication|awk NR==1'{print $1}')
		sed -i "${row}s/.*/GSSAPIAuthentication\ no/g" /etc/ssh/sshd_config
	fi
 
	
	#UseDNS no
	flag=$(cat /etc/ssh/sshd_config|grep UseDNS|awk  NR==1'{print $2}')
	check UseDNS ${flag}
	if [ ${flag}"" != "no" ];
	then
		row=$(cat -n /etc/ssh/sshd_config|grep UseDNS|awk  NR==1'{print $1}')
		sed -i "${row}s/.*/UseDNS\ no/g" /etc/ssh/sshd_config
	fi
	
	#IgnoreRhosts yes
	flag=$(cat /etc/ssh/sshd_config|grep IgnoreRhosts|awk  NR==1'{print $2}')
	check IgnoreRhosts ${flag}
	if [ ${flag}"" != "yes" ];
	then
		row=$(cat -n /etc/ssh/sshd_config|grep IgnoreRhosts|awk  NR==1'{print $1}')
		sed -i "${row}s/.*/IgnoreRhosts\ yes/g" /etc/ssh/sshd_config
	fi
	
	systemctl restart sshd
	
	#hosts:files
	flag=$(cat /etc/nsswitch.conf|grep hosts|grep -v \#|grep dns|awk '{print $1}')
	if [ ${flag}"" != "" ];
	then
		row=$(cat -n /etc/nsswitch.conf|grep hosts|grep -v \#|grep dns|awk '{print $1}')
		check hosts ${row}
		sed -i "${row}s/.*/hosts:files/g" /etc/nsswitch.conf
	fi
}
 
#执行
exec_method
 
function delete(){
	rm -rf $0
}
 
#自动清理
delete

  • 11
    点赞
  • 8
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值