HEX
Server: nginx/1.16.1
System: Linux ecs-04358622 4.19.90-2107.6.0.0100.oe1.bclinux.x86_64 #1 SMP Wed Dec 1 19:59:44 CST 2021 x86_64
User: nginx (994)
PHP: 8.0.0
Disabled: NONE
Upload Files
File: //opt/BCLinux/bse/option_set/s14_sshRootDenie
#!/bin/sh

#=======================================================
InsertSection "set ssh root denie"

if [ $DENY_ROOT_LOGIN -eq 1 ]; then

    cp -np /etc/ssh/sshd_config  /etc/ssh/sshd_config_bak


    #----------------Denie Telnet login---------------
    # ----  securetty is disabled in bclinux8 -------
    if [ ${OS_DISTRO} == "7" -o ${OS_DISTRO} == "6" ]; then
        cp -np /etc/securetty  /etc/securetty_bak

        IS_EXIST=`egrep -v '^#|^$' /etc/securetty | grep "pts/" |wc -l`
        if [ ${IS_EXIST} -gt 0 ] ; then
            sed -i '/pts\//d' /etc/securetty
        fi

        IS_EXIST=`egrep -v '^#|^$' /etc/securetty | grep "pts/" |wc -l`
        if [ ${IS_EXIST} -eq 0 ] ; then
            logtext "Has telnet deny set, seting ok"
            Display --indent 2 --text "- set the telnet deny... " --result FINISHED --color GREEN
        else
            logtext "No ssh telnet Denie, seting failed"
            Display --indent 2 --text "- No Telnet Denie set... " --result FAILED --color RED
        fi
    fi



    #-----------------Denie Root ssh login----------------
    IS_EXIST=`egrep -v '^#|^$' /etc/ssh/sshd_config | grep '^PermitRootLogin' |wc -l`
    if [ ${IS_EXIST} -gt 0 ] ; then
        sed -i 's/^PermitRootLogin.*/PermitRootLogin no/' /etc/ssh/sshd_config
    else
        echo "  " >> /etc/ssh/sshd_config
        echo "PermitRootLogin no" >> /etc/ssh/sshd_config
    fi



    IS_EXIST=`egrep -v '^#|^$' /etc/ssh/sshd_config | grep '^PermitRootLogin' |wc -l`
    if [ ${IS_EXIST} -eq 0 ] ; then
        #echo "c14" >> $RESULT_FILE
        #echo "" >> $RESULT_FILE
        logtext "No ssh Root Denie, seting failed"
        Display --indent 2 --text "- No ssh Root Denie set... " --result FAILED --color RED
        #AddHP 0 1
    else
        if [ $(egrep -v '^#|^$' /etc/ssh/sshd_config | grep '^PermitRootLogin' | grep no |wc -l) -eq 0 ];then
            #echo "c14" >> $RESULT_FILE
            #echo "" >> $RESULT_FILE
            logtext "Wrong ssh Root Denie, seting failed"
            Display --indent 2 --text "- Wrong ssh Root Denie set... " --result FAILED --color RED
            #AddHP 0 1
        else
            logtext "Has ssh root deny set, seting ok"
            Display --indent 2 --text "- set the ssh root deny... " --result FINISHED --color GREEN
            #AddHP 1 1
        fi
    fi

    logtext "restart the sshd service..."
    systemctl restart sshd
else

    Display --indent 2 --text "- Skip deny root login due to config file... " --result SKIPPING --color YELLOW

fi