群友需求,自動禁止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