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.

mohan08p
  • 5,002
  • 1
  • 28
  • 36
sfendell
  • 5,415
  • 8
  • 25
  • 26
  • user exists... but likely has no shell, see http://superuser.com/questions/566041/cannot-switch-to-jenkins-user-redhat-linux/566042#566042 – thekbb Aug 06 '13 at 00:58
  • You needn't sudo when you're root. Though it doesn't hurt. – thekbb Aug 06 '13 at 01:01
  • 14
    `sudo usermod -s /bin/bash jenkins` – jgb Aug 06 '13 at 05: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 06 '13 at 12:59

6 Answers6

259

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

Community
  • 1
  • 1
thekbb
  • 7,668
  • 1
  • 36
  • 61
  • 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 '13 at 21:59
  • edited the answer to incorporate @mrg 's exactly correct info about needing `sudo`. – thekbb Sep 24 '14 at 03: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 '15 at 08:50
  • @mrg What password did you use? – Nabin Jul 29 '15 at 02:03
  • @JoeLloyd Did you figure out the default password? What is the password? – Nabin Jul 29 '15 at 02:03
  • There is no password - by design you cannot interactively log in to the account with a password. – thekbb Jul 29 '15 at 03:39
6

Use the below command:

su -s /bin/bash jenkins
shuberman
  • 1,416
  • 6
  • 21
  • 38
Sudipto Das
  • 71
  • 1
  • 3
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
mahendra rathod
  • 1,438
  • 2
  • 15
  • 23
-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.

ashik ahmed
  • 37
  • 2
  • 8
-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.

rotscher
  • 47
  • 3
  • 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 06 '13 at 13:04