使用的时候,命令传入用户密码(sh /x.sh password)
查看所有用户命令:cat /etc/passwd
查看磁盘挂载:lsblk
开启:
#!/bin/sh
home=/home/debugger
#delete read permission from
chmod o-rw /
chmod o+x /
chmod o-rw /home
#add user and passwd
useradd debugger
echo $1 | passwd debugger --stdin
#change user config file Privilege to debugger:debugger in case error happens
chown debugger:debugger $home/.
chown debugger:debugger $home/.bash*
#mount
mkdir -p $home/dav
mount /dev/sda9 $home/dav
chown -R debugger $home/dav
systemctl start sshd
关闭:
#!/bin/sh
USER=debugger
home=/home/$USER
systemctl stop sshd
ps_debugger=`ps -eo user,pid | grep $USER`
echo $ps_debugger
#要将$a分割开,先存储旧的分隔符
OLD_IFS="$IFS"
#设置分隔符
IFS=" "
#如下会自动分隔
arr_ps=($ps_debugger)
#恢复原来的分隔符
IFS="$OLD_IFS"
#setp 1
#kill all alive connections of the user
for s in ${arr_ps[@]}
do
if [ "$s" != "$USER" ]
then
kill -9 $s
fi
done
#setp 2
#change all owner to root
chown -R root $home/dav
#setp 3 umount all disk
umount -l $home/dav
#setp 4 delete user
userdel $USER
#setp 5 add read for other user
#add read permission from /
chmod o+r /
chmod o+r /home