#!/bin/bash
############### 一键修改ssh端口 ###############
#Author:大三胖
#Update:2022-02-07
####################### END #######################
port=$(cat /etc/ssh/sshd_config|grep 'Port ')
if [ "$port" == "#Port 22" ]
	then
		echo "当前端口为:22"
		declare -i newport
		read -p "请输入新的端口号:" newport
		sed -i "s/#Port 22/Port $newport/g" /etc/ssh/sshd_config
		service sshd restart
		echo '端口修改成功！'
	else
		port=${port/\#Port /}
		declare -i port=${port/Port /}
		echo "当前端口号为:"${port}
		declare -i newport
		read -p "请输入新的端口号:" newport
		sed -i "s/Port $port/Port $newport/g" /etc/ssh/sshd_config
		service sshd restart
		echo '端口修改成功！'
	fi