【问题标题】:Changing SSH port with a bash script on CentOS在 CentOS 上使用 bash 脚本更改 SSH 端口
【发布时间】:2013-08-08 14:26:15
【问题描述】:

所以我写了一个脚本,可以更改 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

谁能解释错误在哪里?

【问题讨论】:

    标签: bash ssh port centos6


    【解决方案1】:

    如果if [[ $EUID -ne 0 ]]; then,则第一个没有fi。您需要使用fi 关闭每个if

    【讨论】:

    • 谢谢!我知道我错过了什么。
    猜你喜欢
    • 2014-04-08
    • 1970-01-01
    • 1970-01-01
    • 2013-10-01
    • 1970-01-01
    • 1970-01-01
    • 2014-07-28
    • 2013-10-24
    • 2016-08-11
    相关资源
    最近更新 更多