分页: 1 / 1

root如何用apache的用户身份运行脚本

发表于 : 2016-11-07 9:05
jiandan23
因为apache的默认shell是/sbin/nologin,所以用su - apache "ls"运行程序的话会提示“This account is currently not available”。
遇到这种情况有解决办法吗?
谢谢!

Re: root如何用apache的用户身份运行脚本

发表于 : 2016-11-07 9:19
vickycq
可以 -s 指定 shell

代码: 全选

# cat /etc/passwd | grep sshd
sshd:x:105:65534::/var/run/sshd:/usr/sbin/nologin
# su -c "ls" sshd
This account is currently not available.
# su -s /bin/bash -c "ls" sshd
Apps  bin  Desktop  Downloads  etc  incoming  mnt  tmp  Videos
参考 http://serverfault.com/questions/351046 ... ogin-shell

Re: root如何用apache的用户身份运行脚本

发表于 : 2016-11-07 10:35
jiandan23
还找到另外一个sudo的办法,总结一下:
方法一:su -s "/bin/sh" apache -c "whoami"
方法二:sudo -u apache whoami

试了一下,两种方法都是可以的 :Haha