限制用户只能使用ping/traceroute 命令

限制用户只能使用ping/traceroute 命令

脚本如下:

#!/bin/bash
User="ping"
useradd $User
echo "123456"|passwd --stdin $User &> /dev/null
Command="ping traceroute"
ln -s /bin/bash /bin/rbash
User_alive=`cat /etc/passwd | grep "$User" |wc -l`
if [ $User_alive -eq 1 ]
then
    sed -i "/$User/s/\/bin\/bash/\/bin\/rbash/" /etc/passwd
    mkdir /home/$User/bin
    touch /home/$User/.bash_profile
    if [ -f /home/$User/.bash_profile ]
    then
        chown root. /home/$User/.bash_profile 
        chmod 755 /home/$User/.bash_profile
        echo > /home/$User/.bash_profile
cat >> /home/$User/.bash_profile <<EOF 
# .bash_profile
  
# Get the aliases and functions
if [ -f ~/.bashrc ]; then
        . ~/.bashrc
fi
  
# User specific environment and startup programs
  
PATH=\$HOME/bin
EOF
    else
        echo "profile is not exist"
        exit "6"
    fi
else
    echo "User is not exist"
    exit 5
fi
for i in $Command
do
    dir=`whereis $i | awk "{print $2}"`
    ln -s $dir /home/$User/bin
done

猜你喜欢

转载自blog.csdn.net/jingxinguofeng/article/details/126795088