지정된 사용자를 사용하여 Linux에서 명령 실행

1. su ( 선호 )

[root@redhat6 ~]# su - admin -c "id"
uid=500(admin) gid=500(admin) groups=500(admin)
[root@redhat6 ~]#
输出的时 admin 在执行命令 "id" 显示的结果 ,而且执行后并没有切换到"admin" 的console 下 .


# 选删掉swoft所有进程
ps -ef|grep swoft|grep -v grep|awk '{print $2}'|xargs kill -9
# 再用apache启动swoft进程
su - apache -c "/usr/local/bin/php /data/www/vhosts/pixcutapi.wondershare.com/httpdocs/bin/swoft http:start -d"

두 sudo를

sudo -H -u www bash -c 'nohup / home / web / ke / upfileserver /home/web/ke/up/conf.json &' 

셋, chroot 방식 

chroot --userspec "kibana : kibana" "/"sh -c "/ usr / share / kibana / bin / kibana -c /etc/kibana/kibana.yml">> /var/log/kibana/kibana.stdout 2 >> /var/log/kibana/kibana.stderr &

추천

출처blog.csdn.net/JineD/article/details/111517698