在root用戶下添加編輯 ~/.bashrc node
userlogin=`echo $SSH_CONNECTION | awk '{print $1}'` #獲取登陸用戶的ip地址 nodenyuser=192.168.10.111 #容許登陸的ip地址 nodenyuser1=192.168.10.123 if [ $userlogin != $nodenyuser ] ; then #判斷是否爲禁止的ip地址 if [ $userlogin != $nodenyuser1 ] ; then echo "deny" userclient=`w | grep -v grep | grep $userlogin | awk '{print $2}'` echo $userclient ps -ef | grep $userclient | grep -v grep | grep sshd | awk '{print $2}' | xargs -I {} kill -9 {} # 若是是禁止的ip地址直接結束會話 fi fi
userlogin=`echo $SSH_CONNECTION | awk '{print $1}'` #獲取登陸用戶的ip地址
nodenyuser=192.168.10.111 #容許登陸的ip地址
nodenyuser1=192.168.10.123
if [ $userlogin != $nodenyuser ] ; then #判斷是否爲禁止的ip地址
if [ $userlogin != $nodenyuser1 ] ; then
echo "deny"
userclient=`w | grep -v grep | grep $userlogin | awk '{print $2}'`
echo $userclient
ps -ef | grep $userclient | grep -v grep | grep sshd | awk '{print $2}' | xargs -I {} kill -9 {} # 若是是禁止的ip地址直接結束會話
fi
fi shell