Shell 提权 ¶
#Linux #Shell
请求 ROOT 权限以运行脚本
#!/bin/bash
[ $UID -ne 0 ] && {
exec sudo "$0" "$@"
exit $?
}
WorkDir=$(cd $(dirname $0);pwd)
pushd $WorkDir
systemctl reset-failed
systemd-run -p User=hsiaotien \
-p Group=hsiaotien \
-p NoNewPrivileges=yes \
-p ProtectSystem=full \
-p ReadOnlyPaths=/home/hsiaotien \
-p ReadWritePaths=$WorkDir \
-p ReadWritePaths=/home/hsiaotien/.config/copyparty \
-u copyparty \
.venv/bin/python $WorkDir/copyparty-sfx.py
关键点
- 用 exec 在当前环境中启动,同时执行完后退出,以免脚本被多次执行
评论
请登录后发表评论。
暂无评论。成为第一个评论者!