When I wanted to change the Jenkins user I first checked /etc/init.d/jenkins script.  There I found two important variables $JENKINS_CONFIG(=/etc/sysconfig/jenkins) and $JENKINS_USER. So if you want, you can change the JENKINS_USER variable in the /etc/init.d/jenkins file; but it is not the correct way to do.

To change the jenkins user, open the /etc/sysconfig/jenkins (in debian this file is created in /etc/default) and change the JENKINS_USER to whatever you want. Make sure that user exists in the system (you can check the user in the /etc/passwd file ).
$JENKINS_USER="manula"
Then change the ownership of the Jenkins home, Jenkins webroot and logs.
chown -R manula:manula /var/lib/jenkins 
chown -R manula:manula /var/cache/jenkins
chown -R manula:manula /var/log/jenkins
Then restarted the Jenkins jenkins and check the user has changed using a ps command
/etc/init.d/jenkins restart
ps -ef | grep jenkins
48

View comments

  1. Thanks a lot! This tutorial helped me a lot!

    ReplyDelete
  2. Yes Thanks!!! This is what I was missing!

    ReplyDelete
  3. Perfect! Thanks for the easy solution.

    ReplyDelete
  4. I want to run jenkins as user Jenkins, but be able to start/stop/restart it as user jenkins and not as user root. The OS is Linux. Is it possible?

    ReplyDelete
  5. Thank you so much Manula! You saved me! :D

    ReplyDelete
  6. Yes. it worked for me... Thanks.........

    ReplyDelete
  7. Cool, it works perfectly.....

    ReplyDelete
  8. Getting Service unavailable 503 error after this change. Not finding logs. What could have broken this?

    ReplyDelete
    Replies
    1. The only change is changing permission and user. So Check you have the correct permission.

      Delete
  9. Thanks for the response. I could able to clone in command line with no issues. When i gave root it worked fine. But my id doesnt work. Is other any other place where i could get the logs. I couldnt find it in /var/logs/jenkins/

    ReplyDelete
  10. Thanks a lot Manula, this really helped and saved my many days!

    ReplyDelete
  11. Very helpful - thank you!
    I am using an account:group bundlemaker:bundlemaker
    When i yum update jenkins, it changes the group back to jenkins for the three directories listed above. Is this something you've seen as well?

    ReplyDelete
    Replies
    1. I haven't update Jenkins after changing the configuration. So I haven't seen this. I think package manager does this without reading the configuration.

      Delete
  12. Thanks Manula, This doc was very useful. I am new to Jenkins and this helped to meet my deadline. Thanks again.

    ReplyDelete
  13. It works like a charms.
    Thanks a lot!

    ReplyDelete
  14. This comment has been removed by the author.

    ReplyDelete
  15. Thank You Manula, saved the day for me.

    ReplyDelete
  16. This helped me a lot too!

    I was having trouble setting up jenkins permisions and stuff.... but after I read this, it was only a matter of running jenkins as myself!

    Thanks!

    ReplyDelete
  17. I don't have root access nor having sudo to the system I'm using. Is there another way to change Jenkins user?

    In my situation, I login into Jenkins with my ID. Jenkins know that I am executing the job. However, during the job execution Jenkins use a different ID. Any help with this situation?

    ReplyDelete
  18. Thanks Manula. It helped me a lot.

    ReplyDelete
  19. This saved me a lot of headache with ssh keys!

    ReplyDelete
  20. Thanks, this saves me a lot of trouble with permission thank you !

    ReplyDelete
  21. How can I give permission if I have Jenkins deployed as docker image

    ReplyDelete
  22. How can I give permission if I have Jenkins deployed as docker image

    ReplyDelete
  23. Very helpful instructions.

    ReplyDelete
  24. Sir, you just nailed it. You have saved my life after 2 days of suffering. Thanks alot and i will keep following for other updates.

    ReplyDelete
  25. Thanks a bunch. I have seen lots of suggestions but yours is the best and the simplest.

    ReplyDelete
  26. thanks a lot for this valuable commands, its worked for me.

    ReplyDelete
  27. Good tip. But can you tell me how I can use the public key of the present user to accept web hooks from a private repository?

    ReplyDelete
  28. I tried this on ubuntu LTS version , but failed while restart

    ReplyDelete
  29. I'm having the below issue after chown to non-jenkins user. While it sounds like permission issue, I'm not clear which permission is required to start jenkins using a different user
    $ /sbin/service jenkins start
    Starting Jenkins runuser: cannot set groups: Operation not permitted
    [FAILED]

    ReplyDelete
  30. I'm having the below issue after chown to non-jenkins user. While it sounds like permission issue, I'm not clear which permission is required to start jenkins using a different user
    $ /sbin/service jenkins start
    Starting Jenkins runuser: cannot set groups: Operation not permitted
    [FAILED]

    ReplyDelete
  31. I try above steps what you suggest and when i start jenkins it is running as jenkins user , and i create job it was creating with jenkins user , can you please help me any to run jenkins server on oracle user in oracle cloud

    ReplyDelete
  32. i tried the above step but its not working for me after restart jenkins service it gives me below error
    jenkins.model.InvalidBuildsDir: ${ITEM_ROOTDIR}/builds does not exist and probably cannot be created
    at jenkins.model.Jenkins.checkRawBuildsDir(Jenkins.java:3378)
    at jenkins.model.Jenkins.loadConfig(Jenkins.java:3300)
    Caused: java.io.IOException
    at jenkins.model.Jenkins.loadConfig(Jenkins.java:3303)
    at jenkins.model.Jenkins.access$1200(Jenkins.java:340)
    at jenkins.model.Jenkins$12.run(Jenkins.java:3398)
    at org.jvnet.hudson.reactor.TaskGraphBuilder$TaskImpl.run(TaskGraphBuilder.java:175)
    at org.jvnet.hudson.reactor.Reactor.runTask(Reactor.java:305)
    at jenkins.model.Jenkins$5.runTask(Jenkins.java:1158)
    at org.jvnet.hudson.reactor.Reactor$2.run(Reactor.java:222)
    at org.jvnet.hudson.reactor.Reactor$Node.run(Reactor.java:121)
    at jenkins.security.ImpersonatingExecutorService$1.run(ImpersonatingExecutorService.java:68)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1149)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:624)
    at java.lang.Thread.run(Thread.java:750)
    Caused: org.jvnet.hudson.reactor.ReactorException

    ReplyDelete
    Replies
    1. I have the exact same problem. Did you ever find a resolution to this?

      Delete
Popular Posts
Popular Posts
Blog Archive
Labels
Loading
Dynamic Views theme. Powered by Blogger. Report Abuse.