February 23, 2018

Running Commands As Apache User

I have some django apps that run as apache user.
And I frequently need to run some commands as an apache user from my regular user shell.

The following function in ~/.bashrc is awesome for such use cases

run_as_apache_user() {
    su -s "/bin/bash" -c "$1" apache
}

Usage:

$ run_as_apache_user 'svn up'
$ run_as_apache_user 'ls'
  • LinkedIn
  • Tumblr
  • Reddit
  • Google+
  • Pinterest
  • Pocket