I am trying to run a daemonised webserver as www-data user but I have reduced the problem down to the fact I can't even run the simplest of commands using su
.
root@ubuntu:/var/www/hello# ls -la
total 8
drwxr-xr-x 2 www-data www-data 4096 Apr 22 11:39 .
drwxr-xr-x 8 www-data www-data 4096 Apr 22 11:38 ..
-rw-r--r-- 1 www-data www-data 0 Apr 22 11:39 hello.txt
root@ubuntu:/var/www/hello# sudo -u www-data 'ls'
hello.txt
root@ubuntu:/var/www/hello# su - www-data -c "ls"
root@ubuntu:/var/www/hello# echo $? # Unknown problem as no error text to stout from previous command
1
root@ubuntu:/var/www/hello# su -c "ls" www-data
root@ubuntu:/var/www/hello# echo $? # Unknown problem as no error text to stout from previous command
1
root@ubuntu:/var/www/hello# su -c "ls" root
hello.txt
root@ubuntu:/var/www/hello# su --help
Usage: su [options] [LOGIN]
Options:
-c, --command COMMAND pass COMMAND to the invoked shell
-h, --help display this help message and exit
-, -l, --login make the shell a login shell
-m, -p,
--preserve-environment do not reset environment variables, and
keep the same shell
-s, --shell SHELL use SHELL instead of the default in passwd
Two questions:
- How to get better error messages from
su
- How to fix the fundamental problem of the command erroring when run as www-data user.