在Gitlab Runner中的权限被拒绝



我有一个Gitlab运行器在VPS中运行,现在面临这个错误:

Running on vps...
Getting source from Git repository
00:02
Fetching changes with git depth set to 50...
Reinitialized existing Git repository in /home/gitlab-runner/builds/-Jgf7oJG/0/agency/project/app/.git/
Checking out 67b23db2 as testing...
Removing .env
Skipping Git submodules setup
Executing "step_script" stage of the job script
00:00
$ mkdir -p ~/.ssh
$ echo "$SSH_PRIVATE_KEY" | tr -d 'r' > ~/.ssh/id_rsa
$ chmod 700 ~/.ssh/id_rsa
$ eval "$(ssh-agent -s)"
Agent pid 929369
$ ssh-add ~/.ssh/id_rsa
Identity added: /home/gitlab-runner/.ssh/id_rsa (/home/gitlab-runner/.ssh/id_rsa)
$ ssh-keyscan -H $SSH_HOST >> ~/.ssh/known_hosts
bash: line 133: /home/gitlab-runner/.ssh/known_hosts: Permission denied
Cleaning up file based variables
00:00
ERROR: Job failed: exit status 1

我在运行程序的vps中尝试了以下命令:

$ sudo usermod -a -G sudo gitlab-runner
$ sudo visudo

并将其添加到文件的底部。gitlab-runner ALL=(ALL) NOPASSWD: ALL

确保您的known_hosts文件具有以下组&权限。

-rw-r——r——1 gitlab-runner gitlab-runner 444 Aug 2 00:00 known_hosts

from SSHD manual

~/.ssh/known_hosts
Contains a list of host keys for all hosts the user has logged into that are not already in the systemwide list of known host keys.  The format of this file is described above.  This file should be writable only by root/the owner and
can, but need not be, world-readable.

chmod 600/644 for ~/.ssh/known_hosts

最新更新