⚙️

Gitlab

1 notes  •  DevOps & CI/CD

Fix GitLab Runner Error: sudo no tty present

When a GitLab CI/CD job runs a command with sudo, the runner may fail with:

sudo: no tty present and no askpass program specified

This happens because the runner's user is not authorised to use sudo without a password prompt.

Fix – Allow the runner user to run sudo without a password

Edit the sudoers file safely using visudo:

sudo visudo

Add the following line (replace gitlab-runner with the actual runner user):

gitlab-runner ALL=(ALL) NOPASSWD: ALL

For a more restrictive approach, allow only the specific command(s) needed:

gitlab-runner ALL=(ALL) NOPASSWD: /usr/bin/systemctl restart nginx, /usr/bin/apt-get

Alternative – Run commands as root in the pipeline

If the runner is using the shell executor, configure it to run as root:

sudo gitlab-runner uninstall
sudo gitlab-runner install --user=root
sudo gitlab-runner start

Note: Running CI jobs as root is a security risk. Prefer the NOPASSWD sudoers approach above and restrict to specific commands.

Docker executor alternative

If using the Docker executor, most CI tasks run as root inside the container automatically — sudo is generally not needed.