Use the specified user to execute commands under linux

1. su ( preferred )

[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"

Two, sudo

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

Three, chroot way 

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 &

Guess you like

Origin blog.csdn.net/JineD/article/details/111517698