bash 如何成为 Jenkins 用户?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/21434064/
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-09-18 09:24:31  来源:igfitidea点击:

How to become a Jenkins user?

bashshelljenkinscontinuous-integrationcontinuous-deployment

提问by Exploring

I have installed Jenkins and during installation an user named jenkinshas been created. I can see from the documentation:

我已经安装了 Jenkins,并且在安装过程中jenkins创建了一个名为的用户。我可以从文档中看到:

The 'jenkins' user is created to run this service.

'jenkins' 用户被创建来运行这个服务。

Now I need to become this jenkinsuser. I have in the following ways:

现在我需要成为这个jenkins用户。我有以下几种方式:

[root@hostname ~]# sudo su - jenkins
[root@hostname ~]# id
uid=0(root) gid=0(root) groups=0(root)

[root@hostname tmp]# su - jenkins
[root@hostname tmp]# whoami
root

Why switch user to the jenkins user is not working?

为什么将用户切换到 jenkins 用户不起作用?

I am on RHEL.

我在 RHEL 上。

cat /etc/*release
Red Hat Enterprise Linux Server release 6.3 (Santiago)

回答by Exploring

Basically for this Jenkins user jenkinsbash was not configured.

基本上对于这个 Jenkins 用户jenkinsbash 没有配置。

jenkins:x:496:492:Jenkins Continuous Build server:/var/lib/jenkins:/bin/false

So we need to set the bash for this user and that resolved the issue. I used the following command:

所以我们需要为这个用户设置 bash 并解决了这个问题。我使用了以下命令:

sudo usermod -s /bin/bash jenkins

See below:

见下文:

jenkins:x:496:492:Jenkins Continuous Build server:/var/lib/jenkins:/bin/bash

And now I can perform su and can use bash.

现在我可以执行 su 并且可以使用 bash。

回答by Vincent Van der Kussen

It is also possible to run:

也可以运行:

su - jenkins -s /bin/bash

回答by André Stannek

It's more like a queastion for superuserbut:

这更像是超级用户的问题,但是:

You don't need sudowhen switching the user. suwill ask for the users password anyway:

sudo切换用户时不需要。su无论如何都会询问用户密码:

su - jenkins

You can also use sudoto execute a single command as another user with the -uoption. If that command is a shell, you'll get a shell. E.g.:

您还可以使用sudo-u选项以另一个用户身份执行单个命令。如果该命令是一个 shell,您将获得一个 shell。例如:

sudo -u jenkins /bin/bash