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

use*_*ser 3 linux login

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

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

有没有办法以 Jenkins 身份登录但指定要使用的不同 shell?我真的必须改变詹金斯的外壳/etc/passwd/吗?

the*_*ive 6

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

su jenkins --shell=/bin/bash
Run Code Online (Sandbox Code Playgroud)

您需要以 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.
Run Code Online (Sandbox Code Playgroud)


Jac*_*zny 5

您是否已阅读--helpsu命令的手册页(或输出)?

su -s /bin/bash -
Run Code Online (Sandbox Code Playgroud)