直接上代码:
#!/bin/bash
rm $0
echo "请输入新的SSH端口:"
read ssh
echo "您输入的端口为$ssh,确认请输入yes,否则回车退出!"
read statu
if [[ $statu == yes ]]
then
echo
else
echo "欢迎下次使用!"
exit 0;
fi
sed -i "s/#Port 22/Port $ss/g" /etc/ssh/sshd_config
sed -i "s/Port 22/Port $ss/g" /etc/ssh/sshd_config
service sshd restart
iptables -I INPUT -p tcp -m tcp --dport $ss -j ACCEPT
iptables-save
echo "OK"
rm $0
echo "请输入新的SSH端口:"
read ssh
echo "您输入的端口为$ssh,确认请输入yes,否则回车退出!"
read statu
if [[ $statu == yes ]]
then
echo
else
echo "欢迎下次使用!"
exit 0;
fi
sed -i "s/#Port 22/Port $ss/g" /etc/ssh/sshd_config
sed -i "s/Port 22/Port $ss/g" /etc/ssh/sshd_config
service sshd restart
iptables -I INPUT -p tcp -m tcp --dport $ss -j ACCEPT
iptables-save
echo "OK"
直接把上面代码保存为文件,运行即可。