Best practice to run Linux service as a different user

后端 未结 8 1339
甜味超标
甜味超标 2020-12-04 04:46

Services default to starting as root at boot time on my RHEL box. If I recall correctly, the same is true for other Linux distros which use the init scripts in

8条回答
  •  囚心锁ツ
    2020-12-04 05:24

    I needed to run a Spring .jar application as a service, and found a simple way to run this as a specific user:

    I changed the owner and group of my jar file to the user I wanted to run as. Then symlinked this jar in init.d and started the service.

    So:

    #chown myuser:myuser /var/lib/jenkins/workspace/springApp/target/springApp-1.0.jar
    
    #ln -s /var/lib/jenkins/workspace/springApp/target/springApp-1.0.jar /etc/init.d/springApp
    
    #service springApp start
    
    #ps aux | grep java
    myuser    9970  5.0  9.9 4071348 386132 ?      Sl   09:38   0:21 /bin/java -Dsun.misc.URLClassPath.disableJarChecking=true -jar /var/lib/jenkins/workspace/springApp/target/springApp-1.0.jar
    

提交回复
热议问题