Linux 安装 Jenkins 后无法 su 到用户 jenkins

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/18068358/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-07 00:28:20  来源:igfitidea点击:

Can't su to user jenkins after installing Jenkins

linuxunixjenkins

提问by sfendell

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:

我已经安装了 jenkins 并且我正在尝试以 Jenkins 的身份进入 shell 以添加 ssh 密钥。我似乎无法进入 jenkins 用户:

[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 jenkinsasks for a password, but rejects my normal password. sudo su jenkinsdoesn't seem to do anything; same for sudo su - jenkins. I'm on CentOS.

jenkins 用户存在于我的 /etc/passwd 文件中。Runninsu jenkins要求输入密码,但拒绝了我的普通密码。sudo su jenkins似乎什么都不做;对于sudo su - jenkins. 我在 CentOS 上。

采纳答案by thekbb

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.

jenkins 是一个服务帐户,它的设计没有外壳。人们普遍认为,服务帐户不应该能够以交互方式登录。

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.

我最初没有回答这个问题,因为它是一个已移至 server fault 的问题副本。我应该回答而不是链接到评论中的答案。

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

如果由于某种原因您想以 jenkins 身份登录,您可以这样做: sudo su -s /bin/bash jenkins

回答by rotscher

as root, enter su - jenkins

以 root 身份输入su - jenkins

Also, check in /etc/passwdthat user jenkins is allowed to logon: there should be something like /bin/bashor /bin/sh, certainly not /bin/falseat the end of the line.

另外,检查/etc/passwd允许用户 jenkins 登录:应该有类似/bin/bash/bin/sh 的内容,当然不是/bin/false在行的末尾。

Hint: You don't use suand sudoat the same time.

提示:不要同时使用susudo

回答by ashik ahmed

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

如果您在 docker 中使用 jenkins。那么你应该尝试以下方法。

  • 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"

  • 首先你需要运行jenkins容器docker start (container-name or container-id)”

  • 然后运行这个命令“docker exec -it (container-name or container-id) bash”

Now hopefully you will be using as a jenkins user.

现在希望您将作为 jenkins 用户使用。