问题现象:
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