一、简述

  当我们在使用Linux时,经常需要在root权限下执行某些命令,或者在/etc/rc.d/rc.local中写一些角本。而如果某些角本必须使用非root用户时,直接su是不行的,比如Elasticsearch就必须在非root用户下运行。需要使用如下方案执行:

二、方法

  方法一,使用su +用户名 -c加角本:  

su <new user> -c "<sh file path or command>"

  方法二,使用su xxx<<! 角本   exit !  :

#!/bin/bash
su elasticsearch<<!
cd /opt/elasticsearch-6.2.3
./bin/elasticsearch -d
exit
!
echo "elasticsearch is started."

 

相关文章:

  • 2022-12-23
  • 2021-10-09
  • 2021-06-05
  • 2021-06-19
  • 2022-12-23
  • 2021-10-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-01-24
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-13
相关资源
相似解决方案