在CentOS上使用bash脚本更改SSH端口

在CentOS上使用bash脚本更改SSH端口,bash,ssh,port,centos6,Bash,Ssh,Port,Centos6,因此,我编写了一个脚本,可以在CentOS上更改SSH端口,但由于某些原因,我遇到了以下错误: sshchangecOS6.sh:第36行:语法错误:文件意外结束 以下是脚本: #! /bin/bash # This script changes the ssh port for logins on CentOS 5 and 6 if [[ $EUID -ne 0 ]]; then echo "This script must be run as root" exit 2 read -r

因此,我编写了一个脚本,可以在CentOS上更改SSH端口,但由于某些原因,我遇到了以下错误:

sshchangecOS6.sh:第36行:语法错误:文件意外结束

以下是脚本:

#! /bin/bash
# This script changes the ssh port for logins on CentOS 5 and 6
if [[ $EUID -ne 0 ]]; then
echo "This script must be run as root"
   exit 2
read -r -p "Would you like to change the ssh port? [Y/N] " response
if [[ $response =~ ^([yY][eE][sS]|[yY])$ ]]
then    
   read -p "What would you like to change the port to? (Chose between 1024-65535) " sshportconfig
   if (( ("$sshportconfig" > 1024) && ("$sshportconfig" < 65535) )); then
    echo "Port $sshportconfig" >> /etc/ssh/sshd_config
    echo "--------------------------------------------------------------------"
    echo ""
    echo ""
    echo "SSH port has been changed to: $sshportconfig. Written by Sincere the Minotaur."
    echo ""
    echo ""
    echo "--------------------------------------------------------------------"
   else
    echo "Port chosen is incorrect."
    exit 1
   fi
else 
   sshPort=$(grep "Port" /etc/ssh/sshd_config) | head -n 1
   echo "--------------------------------------------------------------------"
   echo ""
   echo ""
   echo "SSH is still: $sshPort"
   echo "Written by Sincere the Minotaur."
   echo ""
   echo "---------------------------------------------------------------------"
   exit 1
fi
exit 0
#/bin/bash
#此脚本更改CentOS 5和6上登录的ssh端口
如果[$EUID-ne 0]];然后
echo“此脚本必须以root用户身份运行”
出口2
读取-r-p“是否要更改ssh端口?[Y/N]”响应
如果[[$response=~^([yY][eE][sS]|[yY])$]]
然后
阅读-p“您希望将端口更改为什么?(在1024-65535之间选择)”sshportconfig
如果(((“$sshportconfig”>1024)和(“$sshportconfig”<65535));然后
echo“Port$sshportconfig”>>/etc/ssh/sshd\u config
echo“--------------------------------------------------------------”
回声“”
回声“”
echo“SSH端口已更改为:$sshportconfig.writed by the Minotaur。”
回声“”
回声“”
echo“--------------------------------------------------------------”
其他的
echo“选择的端口不正确。”
出口1
fi
其他的
sshPort=$(grep“Port”/etc/ssh/sshd_-config)|头-n 1
echo“--------------------------------------------------------------”
回声“”
回声“”
echo“SSH仍然是:$sshPort”
“回声”由牛头怪写的
回声“”
echo“--------------------------------------------------------------”
出口1
fi
出口0

有人能解释一下错误在哪里吗?

第一个if
if[$EUID-ne 0]]没有
fi
;然后
。您需要使用
fi

关闭每个
if
,谢谢!我知道我错过了什么。