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

sh/bash/dash/ksh/zsh等Shell脚本
回复
头像
jiandan23
帖子: 86
注册时间: 2010-12-17 22:31
系统: Mint 19.2

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

#1

帖子 jiandan23 » 2016-11-07 9:05

因为apache的默认shell是/sbin/nologin,所以用su - apache "ls"运行程序的话会提示“This account is currently not available”。
遇到这种情况有解决办法吗?
谢谢!
头像
vickycq
帖子: 4507
注册时间: 2011-03-20 13:12
系统: Debian
来自: 山东省寿光县
联系:

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

#2

帖子 vickycq » 2016-11-07 9:19

可以 -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
Debian 中文论坛 - forums.debiancn.org
欢迎所有 Debian GNU/Linux 用户
头像
jiandan23
帖子: 86
注册时间: 2010-12-17 22:31
系统: Mint 19.2

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

#3

帖子 jiandan23 » 2016-11-07 10:35

还找到另外一个sudo的办法,总结一下:
方法一:su -s "/bin/sh" apache -c "whoami"
方法二:sudo -u apache whoami

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