File: //opt/BCLinux/bse/secure_set/s10_sshBanner
#!/bin/sh
#=====================================================================
InsertSection "Set the sshbanner..."
if [ $SET_SSH_LOGIN_BANNER -eq 1 ]; then
cp -np /etc/ssh/sshd_config /etc/ssh/sshd_config_bak
if [ -f /etc/sshbanner ] ; then
cp -np /etc/sshbanner /etc/sshbanner_bak
logtext "exist /etc/sshbanner file, rewrite it..."
echo $SSH_LOGIN_BANNER_VALUE > /etc/sshbanner
#Display --indent 2 --text "- Has the /etc/ssh/banner file,rewriting... " --result FINISHED --color GREEN
else
logtext "no /etc/sshbanner file, creating..."
touch /etc/sshbanner
chown bin:bin /etc/sshbanner
chmod 644 /etc/sshbanner
echo $SSH_LOGIN_BANNER_VALUE > /etc/sshbanner
fi
IS_EXIST=`egrep -v '^#|^$' /etc/ssh/sshd_config | grep 'Banner' | wc -l`
if [ "${IS_EXIST}" = "0" ] ; then
echo -e "Banner /etc/sshbanner\n\n" >> /etc/ssh/sshd_config
else
sed -i 's/^Banner.*/Banner \/etc\/sshbanner/' /etc/ssh/sshd_config
fi
#sed -i 's/^#Banner.*/Banner \/etc\/sshbanner/' /etc/ssh/sshd_config
#logtext "restart the sshd service..."
#systemctl restart sshd.service
if [ -f /etc/sshbanner ] ; then
TMP_V=`grep -ir banner /etc/ssh/sshd_config | grep -Ev '^$|^#' | wc -l`
if [ $TMP_V -gt 0 ];then
logtext "set the sshbanner successfully"
Display --indent 2 --text "- Set the sshbanner... " --result FINISHED --color GREEN
#AddHP 1 1
fi
else
#echo "c10" >> $RESULT_FILE
#echo "" >> $RESULT_FILE
logtext "create the sshdbanner failed"
Display --indent 2 --text "- Set the sshbanner... " --result FAILED --color RED
#AddHP 0 1
fi
else
Display --indent 2 --text "- Skip set ssh login banner due to config file... " --result SKIPPING --color YELLOW
fi