debian - Gitlab-ci, image debian :jessie. 无法使用 su 命令更改用户

标签 debian gitlab gitlab-ci su debian-jessie

我在 Debian jessie 图像的工作中使用 Gitlab-ci。首先,我需要安装一些包。一切都好。然后,我想将用户从 root 更改为非 root 用户,但是 su 命令不起作用。 下面是一个关于改变用户的测试。

我的.gitlab-ci.yml:

image: debian:jessie

test:
    script:
    - whoami
    - adduser --disabled-password --gecos "" builder
    - su -l builder
    - whoami

我的结果:

$ whoami
root
$ adduser --disabled-password --gecos "" builder
Adding user `builder' ...
Adding new group `builder' (1000) ...
Adding new user `builder' (1000) with group `builder' ...
Creating home directory `/home/builder' ...
Copying files from `/etc/skel' ...
$ su builder
$ whoami
root

最佳答案

我自己找到了答案:

 image: debian:jessie

 test:
     script:
     - whoami
     - adduser --disabled-password --gecos "" builder
     - su -l builder
-    - whoami
+    - su builder -c "whoami"

使用命令 su <username> -c "<command>"将帮助使用 <username> 运行命令用户,以防万一。

关于debian - Gitlab-ci, image debian :jessie. 无法使用 su 命令更改用户,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58215781/

相关文章:

ldap - 在没有特殊 gitlab 用户的情况下设置 gitlab LDAP 身份验证

Gitlab-ci 和 deploy.sh

docker - 未创建 GitLab CI Docker WORKDIR

gitlab - 如何在 GitLab YAML 文件中生成随机数

c++ - boost::asio 从/dev/input/event0 读取

linux - 需要了解主机和容器中 "ulimit"的 nofile 设置

redis - 在安装 gitlab-shell 时遇到问题

ruby - 无法让我的基于 gem 的主题工作。主题找不到布局

php - 授予管理员网站用户修改公共(public)网站权限的最佳方式?

linux - 在bash中为postgresql生成随 secret 码