Centos下禁止root的ssh登录脚本

2016年6月24日15:38:47 评论 225

之前分享过一篇禁止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
weinxin
聂扬帆博客
一个分享IT运维相关工作经验和实战技巧的个人博客

发表评论

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen: