rbash限制用户执行的命令
发布时间:2020-12-14 04:43:37 所属栏目:大数据 来源:网络整理
导读:rbash限制用户执行的命令 软连接 sudo ln -s /bin/bash /bin/rbashsudo bash -c 'echo "/bin/rbash" /etc/shells'sudo chsh -s /bin/rbash $ruser 建一个直接使用 /bin/rbash 的用户 useradd -s /bin/rbash $ruser ruser是需要限制的用户名 在这个用户目录下
rbash限制用户执行的命令软连接sudo ln -s /bin/bash /bin/rbash sudo bash -c 'echo "/bin/rbash" >> /etc/shells' sudo chsh -s /bin/rbash $ruser 建一个直接使用 ruser是需要限制的用户名 在这个用户目录下创建一个 编辑文件 示例 #!/bin/bash # rbash脚本 create_user() { if [ ! -f "/bin/rbash" ];then ln -s /bin/bash /bin/rbash fi count=`cat /etc/shells | grep /bin/rbash | wc -l` if [ $count -eq 0 ];then bash -c 'echo "/bin/rbash" >> /etc/shells' fi count=`cat /etc/passwd | grep $user | wc -l` if [ $count != 0 ];then # -n参数,不换行输出 echo -n "[ The user already exists,modify the shell? ] " read flag if [ $flag == "y" ];then chsh -s /bin/rbash $user fi else aa=`openssl passwd -1 $password` useradd -s /bin/rbash -p $aa -d /home/$user $user fi if [ ! -d "/home/$user/bin" ];then mkdir -p /home/$user/bin fi } # 添加相应的命令的软连接 add_command() { for i in $com;do count=`ls /home/$user/bin/ | grep "$i" | wc -l` if [ $count -eq 0 ];then path=`which $i` ln -s $path /home/$user/bin/$i fi done } bash_profile() { echo "export PATH=/home/$user/bin/" >> /home/$user/.bashrc } info() { echo "Restricted Rbash!" > /etc/motd } clear_history() { # 清空历史记录 echo "" > ~/.bash_history history -c } p_v() { if [ $UID != 0 ];then echo "You need to be root to perform this command." exit 1 fi if [ "$user" == "" ];then echo "Please enter user name." exit 1 fi if [ "$password" == "" ];then echo "Please enter user password." exit 1 fi } user=$1 password=$2 main() { # 允许的命令,用空格进行分隔 # cd命令在rbash上是受限的,建立软连接也不能执行 com="ifconfig ip ls" p_v # 如果用户已存在注释create_user和bash_profile create_user add_command bash_profile # info clear_history } main (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |