shell - 在 Ubuntu 中编写只能由 sudo 用户运行的 shell 脚本

标签 shell ubuntu scripting sudo

我正在编写一个应该由用户仅在 sudo 用户列表中运行的 shell 脚本,这样做的适当方法是什么?

我在想的是在 shell 脚本中,尝试在系统目录中创建一个虚拟文件,例如/var/run/并将其删除,因此不在 sudo 列表中的用户将收到权限错误,但我相信必须有一个更合适的方法,感谢您的帮助

最佳答案

将脚本的执行权限更改为只能由用户执行,并将脚本的所有权更改为root .那应该这样做。

关于shell - 在 Ubuntu 中编写只能由 sudo 用户运行的 shell 脚本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2069960/

相关文章:

powershell - 我可以从脚本或命令行将文件复制到网上邻居吗?

linux - 用户正在使用 bash 运行的进程数

shell - (Shell函数)VBA中需要文件路径吗?

node.js - 在 gocd 管道上运行 nodejs 命令

bash - 如何根据 svn 评论中的字符串获取颠覆 URL(主干/分支)中的所有修订?

php - add-apt-repository ondrej/php 用于旧的 ubuntu 版本 (14) 和 php 7.0

bash - Terminator/config 不在 .config 文件中

rest - Powershell:Out-File - 访问路径被拒绝

linux - 与猫一起阅读 : Stop when not receiving data

ubuntu - NVRM : RmInitAdapter failed: Xid: 79, GPU 已经脱离总线