I need than a deployer (member of group deploy) can run some scripts with root priviegies. But I dont want that deployers can run anythig. I try this.
With a root user I do:
~$ echo "touch /opt/expe/\$file_name.txt" > create_file.sh ~$ echo "chown \$USER /opt/expe/\$file_name.txt" >> create_file.sh ~$ cat create_file.sh touch /opt/expe/$file_name.txt chown $USER /opt/expe/$file_name.txt ~$ sudo mv create_file.sh /opt/expe/create_file.sh ~$ sudo chgrp deploy /opt/expe/create_file.sh ~$ sudo chmod g+x /opt/expe/create_file.sh ~$ sudo visudo %deploy ALL=(root) NOPASSWD:/opt/expe/create_file.sh
With a deploy not-root user I do:
~$ groups deploy ~$ /opt/expe/create_file.sh touch: cannot touch '/opt/expe/my_text.txt': Permission denied chown: cannot access '/opt/expe/my_text.txt': No such file or directory
Why the touch command did not executed as root?
How can I do a script that excute commands as root for a non root user?