我想跑
restore php ) 该脚本将有几行代码,像
dropdb <database name> psql -c "create database <database name> with encoding 'unicode';" -U edutemplate1 psql -d <database name> -f edu.hourly.sql
restore的sudo命令语法是什么? sudoers的语法是什么,以允许php用户运行restore脚本作为postgres用户?
Sudo版本1.7.2p7
问题的第一部分已经在SO sudoers-syntax-to-run-shell-script-as-php-user
我添加了php ALL=(postgres) NOPASSWD: /usr/bin/id到/ etc / sudoers然后做了su php ,然后sudo -su postgres /usr/bin/id但是我要求postgres的密码。 如果我在用户根下发出相同的sudo命令,我会得到正确的输出'uid = 26(postgres)gid = 26(postgres)groups = 26(postgres)'
更新sudoers到php ALL=(postgres) NOPASSWD: ALL使它工作…
对于类似的情况也请参见这个答案 。
这进入/etc/sudoers :
php ALL=(postgres) NOPASSWD: /the/restore/script
而你让PHP发出这样的命令: sudo -u postgres /the/restore/script
你可以从根目录“su $ USERNAME -c”命令“”无论如何你可以做到这一点威盛sudo,如果你可以请描述你想要做的到底是什么? 例如从哪个用户? 是否需要密码? (你可以在/ etc / sudoers中定义它)通过“php user”你的意思是www-data,或者没有人或其他用户?