运行包含两部分的命令会失败,sudo
但不会su
。
root@hello:/var/www/hello# sudo -u root "echo hello"
sudo: echo hello: command not found
root@hello:/var/www/hello# sudo -u root "echo"
root@hello:/var/www/hello# su -c "echo hello" root
hello
我正在尝试以 www-data 用户身份运行一个守护进程的网络服务器,但我已将问题减少到我什至无法使用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
两个问题:
su