群友需求,自动禁止root用户ssh登陆系统
- #!/bin/bash
- #SSH_IP=`ifconfig eth0|awk '/inet addr/'|awk '{print $2}'|cut -d ":" -f2`
- 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
本文转自it你好 51CTO博客,原文链接:http://blog.51cto.com/itnihao/753206,如需转载请自行联系原作者