I was wondering it is safe or an acceptable practice to use sudo to run an application from another one. For example, Let's say I have an application that uses a configuration file to do its work and, somewhere in that file exists the following line (in this case, I'd like to create a DB):

/usr/bin/sudo -u postgres /usr/bin/psql < /home/userX/create.sql

is this acceptable in a sys admin perspective?


Yes, that's perfectly fine. A lot of common utilities do that. You should however have some fallback in case the application does not get sudo - but that's just good script writing.

Another way to do things like these, that I do not recommend, is to ask the user to run the application as root, which is bad. So this alternative is better. Also make sure that if the script takes some user input, that the user input is properly santizied.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.