在Linux上,是否可以作为另一个用户进行一次性login,覆盖默认的shell?

作为根,我想作为服务用户(jenkins – CI服务器)login,并使用其用户,组和umask设置来操作文件。

通常我会(作为根)做sudo -i -u jenkins ,甚至su - jenkins 。 然而jenkins的默认shell是/ bin / false,它立即退出。

有没有办法login为jenkins,但指定一个不同的shell使用? 我真的不得不在/etc/passwd/更改jenkins的shell吗?

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

 su jenkins --shell=/bin/bash 

你将需要su作为这个工作的根。 从手册页:

  If the target user has a restricted shell (ie 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. 

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

 su -s /bin/bash - 

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

要么

sudo -u jenkins /bin/bash