106

I've installed jenkins and I'm trying to get into a shell as Jenkins to add an ssh key. I can't seem to su into the jenkins user:

[root@pacmandev /]# sudo su jenkins
[root@pacmandev /]# whoami
root
[root@pacmandev /]# echo $USER
root
[root@pacmandev /]# 

The jenkins user exists in my /etc/passwd file. Runnin su jenkins asks for a password, but rejects my normal password. sudo su jenkins doesn't seem to do anything; same for sudo su - jenkins. I'm on CentOS.

4
  • user exists... but likely has no shell, see superuser.com/questions/566041/…
    – thekbb
    Aug 6, 2013 at 0:58
  • You needn't sudo when you're root. Though it doesn't hurt.
    – thekbb
    Aug 6, 2013 at 1:01
  • 14
    sudo usermod -s /bin/bash jenkins
    – jgb
    Aug 6, 2013 at 5:58
  • 1
    don't add a shell to jenkins - it's missing one by design. Generally you don't want service accounts to be able to log in interactively.
    – thekbb
    Aug 6, 2013 at 12:59

6 Answers 6

258

jenkins is a service account, it doesn't have a shell by design. It is generally accepted that service accounts shouldn't be able to log in interactively.

I didn't answer this one initially as it's a duplicate of a question that has been moved to server fault. I should have answered rather than linked to the answer in a comment.

if for some reason you want to login as jenkins, you can do so with: sudo su -s /bin/bash jenkins

6
  • 8
    Thanks! I understand adding a shell to jenkins seems like a bad idea; I was just doing it because there were commands in my build process that I had no problem running from my shell but the build was failing because it couldn't run them. I wanted to get in as jenkins and see if there were permissions issues.
    – sfendell
    Aug 11, 2013 at 21:59
  • edited the answer to incorporate @mrg 's exactly correct info about needing sudo.
    – thekbb
    Sep 24, 2014 at 3:04
  • 1
    is there a default password that it asks for because I don't remember setting up a password on installation.
    – Joe Lloyd
    Jul 22, 2015 at 8:50
  • @mrg What password did you use?
    – Nabin
    Jul 29, 2015 at 2:03
  • @JoeLloyd Did you figure out the default password? What is the password?
    – Nabin
    Jul 29, 2015 at 2:03
6

Use the below command:

su -s /bin/bash jenkins
1

When we installed a Jenkins its created a Jenkins user with = "/bin/false"

You will that information from cat /etc/password file.

cat /etc/passwd | grep jenkins
jenkins:x:995:993:Jenkins Automation Server:/var/lib/jenkins:/bin/false

the best way is already mentioned above in answer by @thekbb

su - jenkins -s /bin/bash

we can also switch with any other shell mentioned in /etc/shells file.

cat /etc/shells
/bin/sh
/bin/bash
/usr/bin/sh
/usr/bin/bash
/bin/tcsh
/bin/csh

to make the changes permanently you can modify the /etc/passwd, but it's highly not recommended because its a service/application user like Apache,MySQL,Nginx.

jenkins:x:995:993:Jenkins Automation Server:/var/lib/jenkins:/bin/bash
0
-1

If you using jenkins inside docker. Then you should try the following.

  • First you need to run the jenkins container "docker start (container-name or container-id)"

  • Then run this command "docker exec -it (container-name or container-id) bash"

Now hopefully you will be using as a jenkins user.

-2

Below mentioned command worked for me

"sudo su jenkins"

-11

as root, enter su - jenkins

Also, check in /etc/passwd that user jenkins is allowed to logon: there should be something like /bin/bash or /bin/sh, certainly not /bin/false at the end of the line.

Hint: You don't use su and sudo at the same time.

1
  • 1
    that's exactly the command the OP tried... you're correct as to why jenkins can't log in - but I disagree with your solution.
    – thekbb
    Aug 6, 2013 at 13:04

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.