Centos下禁止root的ssh登录脚本

脚本 Story 86浏览 0评论

之前分享过一篇禁止root登录的文章,传送门。今天有时间又整理了个脚本

#!/bin/bash

SSH_ROOT_NO=`awk '/PermitRootLogin/' /etc/ssh/sshd_config | awk '{if($1=="'PermitRootLogin'") print $1,$2}'`

SSH_ROOT_YES=`awk '/PermitRootLogin/' /etc/ssh/sshd_config | awk '{if($1=="#PermitRootLogin") print $1,$2}'`

if [ "$SSH_ROOT_YES" == "#PermitRootLogin yes" ]; then
    sed -i "s/#PermitRootLogin yes/PermitRootLogin no/g" /etc/ssh/sshd_config && echo "set deny root to ssh ......" &&
    service sshd restart
          elif
             [ "$SSH_ROOT_NO" == "PermitRootLogin no" ]; then
                     echo "ssh for root is already deny,nothing to do......"
           fi
fi

转载请注明:成长的对话 » Centos下禁止root的ssh登录脚本