Skip to content

Creating a System User for systemd Services


* Verified on Ubuntu 22.04 / ALSE 1.7.x. For other OS versions, consult your vendor's documentation for command compatibility
* Command parameters and options can be reviewed using the man <command> utility, available on most operating systems
* The following commands require root privileges

This example demonstrates creating a system user named gitflic-agent to run the GitFlic Runner agent as a systemd service.

Step-by-Step Guide

1. Create the system user using useradd:

useradd -r -m -s /usr/sbin/nologin gitflic-agent

2. Create required directories in the user's home folder with mkdir:

mkdir -p /home/gitflic-agent/gitflic-runner/build /home/gitflic-agent/gitflic-runner/cache

3. Copy necessary files using cp:

cp runner.jar helper.jar shell-scripts/helper.sh /home/gitflic-agent/gitflic-runner/

4. Set proper ownership and permissions with chown and chmod:

chown -R gitflic-agent:gitflic-agent /home/gitflic-agent/
chmod -R 744 /home/gitflic-agent/gitflic-runner/

5. In your systemd unit file, include these directives:

User=gitflic-agent
Group=gitflic-agent

Advanced Configuration (Use with Caution)

* These operations may compromise system security - review /etc/sudoers documentation first

  • To grant sudo privileges:

    usermod -aG sudo gitflic-agent
    

  • To enable passwordless sudo (not recommended for production):

    sed -i '$ a gitflic-agent ALL=(ALL) NOPASSWD: ALL' /etc/sudoers
    

Automatic translation!

This page has been automatically translated. The text may contain inaccuracies.