在 Linux 上,是否可以以另一个用户的身份进行一次性登录,并覆盖其默认 shell?

在 Linux 上,是否可以以另一个用户的身份进行一次性登录,并覆盖其默认 shell?

作为 root,我想以服务用户(jenkins - CI 服务器)身份登录并使用其用户、组和 umask 设置来操作文件。

通常我会(以 root 身份)执行sudo -i -u jenkins,甚至su - jenkins。但是 jenkins 的默认 shell 是 /bin/false,它会立即退出。

有没有办法以 Jenkins 身份登录但指定使用其他 shell?我真的必须更改 jenkins 的 shell 吗/etc/passwd/

答案1

--shellLinux 上的 su 支持使用选项设置 shell

su jenkins --shell=/bin/bash

您需要以 root 身份执行 su 才能使此功能正常运行。从手册页中:

       If the target user has a restricted shell (i.e. the shell field of
       this users entry in /etc/passwd is not listed in /etc/shell), then
       the --shell option or the $SHELL environment variable wont be taken
       into account, unless su is called by root.

答案2

您是否已阅读该命令的手册页(或--help输出)su

su -s /bin/bash -

答案3

怎么样:
su - jenkins -c /bin/bash

或者

sudo -u jenkins /bin/bash

相关内容