安装 Jenkins 之后不能向用户 Jenkins 提供 su

我已经安装了 Jenkins,我正试图进入一个以 Jenkins 身份设置的 shell,以添加一个 ssh 键。我好像不太喜欢詹金斯的用户:

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

Jenkins 用户存在于我的/etc/passwd 文件中。Runnin su jenkins要求输入密码,但拒绝输入正常的密码。sudo su jenkins似乎没有任何作用; sudo su - jenkins也是如此。我在 CentOS 上。

115747 次浏览

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.

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

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.

Use the below command:

su -s /bin/bash jenkins

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

Below mentioned command worked for me

"sudo su jenkins"