简体   繁体   English

Bash脚本,只能从某个目录编写和执行文件

[英]Bash script that can write and execute files only from certain directory

I need a bash (or python) script which will edit and execute files only in a certain directory and its subdirectories but has no permissions to do so in other directories. 我需要一个bash(或python)脚本,它只在某个目录及其子目录中编辑和执行文件,但在其他目录中没有权限。 Any ideas how to set such permissions for a script? 有关如何为脚本设置此类权限的任何想法?

the Apache webserver does a similar thing by creating its own user on linux, ie the user apache can access /var/www without being root : Apache webserver通过在linux上创建自己的用户来做类似的事情,即用户apache可以访问/var/www而不是root:

https://support.rackspace.com/how-to/how-to-add-linux-user-with-document-root-permissions/ https://support.rackspace.com/how-to/how-to-add-linux-user-with-document-root-permissions/

so you can create a new user and give this user only permissions for the particular directory 因此,您可以创建新用户,并为该用户仅授予特定目录的权限

then any other user who needs to use the script can run it as the user you created : 那么任何需要使用该脚本的用户都可以以您创建的用户身份运行它:

https://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/ https://www.cyberciti.biz/open-source/command-line-hacks/linux-run-command-as-different-user/

how to run script as another user without password 如何将脚本作为另一个没有密码的用户运行

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM