Weblog entry #1 for dalitec
Comments on this Entry
[ Parent | Reply to this comment ]
However if you want to run a command as another user, and know their password you can use the "su" command instead (see -c option), so I'm not sure why anyone would use the "sudo" command with targetpw option set in sudoers for the situation you describe as it is overcomplicated (usually a bad idea where security is concerned).
The Apache user in Debian (www-data) probably shouldn't have a knowable password.
More common patterns with the Apache user are to run setuid executables (so a web page can access something which requires elevated privileges), or to create a database or filesystem entry with the Apache user and have a privileged user check that routinely (cron), or using a tool like incron, to take action on that request. The later approach is probably safer, since setuid scripts are notoriously hard to secure properly.
[ Parent | Reply to this comment ]
May be I am over complicating myself. All I basically want to do is upon a user clickin a button create a directory somedir and move that somedir directory to apache docroot directory which is owned by root. Since I already have a shellscipt called that successfully creates the directory, should I use incron to move that somedir directory to apache docroot ?
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]
sudo and su, apart from whose password is asked, is that the former allows a fine-grained definition of who is allowed to do what. In your case, you could instruct it to allow one user (www-data) to execute exactly one command (your script) as another user (the docroot owner) without asking any password at all:
www-data ALL = (docroot-owner) NOPASSWD: /path/to/script
[ Parent | Reply to this comment ]
[ Parent | Reply to this comment ]