OAuth2 Proxy is a powerful tool for adding authentication to your applications. Running it as a systemd service ensures it starts automatically, integrates well with Linux systems, and can be easily managed. This guide will show you how to configure OAuth2 Proxy as a systemd service.
Prerequisites
- A server running a Linux distribution with systemd (e.g., Ubuntu, CentOS).
- OAuth2 Proxy installed and configured.
- Root or sudo access.
Step 1: Create a systemd Service File
Create a new service file for OAuth2 Proxy. Run the following command:
sudo nano /etc/systemd/system/oauth2-proxy.service
Add the following configuration:
[Unit]
Description=OAuth2 Proxy
After=network.target
[Service]
ExecStart=/usr/local/bin/oauth2-proxy --config=/etc/oauth2-proxy/oauth2-proxy.cfg
Restart=on-failure
User=oauth2proxy
Group=oauth2proxy
[Install]
WantedBy=multi-user.target
Ensure the ExecStart
path matches the location of the OAuth2 Proxy binary on your system. Also, update the --config
parameter to point to your configuration file.
Step 2: Adjust Permissions
Set appropriate permissions for the service file:
sudo chmod 644 /etc/systemd/system/oauth2-proxy.service
Create a dedicated user and group for OAuth2 Proxy:
sudo useradd -r -s /bin/false oauth2proxy
Step 3: Reload systemd and Start the Service
Reload the systemd daemon to recognize the new service:
sudo systemctl daemon-reload
Start the OAuth2 Proxy service:
sudo systemctl start oauth2-proxy
Enable it to start on boot:
sudo systemctl enable oauth2-proxy
Step 4: Verify the Service
Check the status of the service to ensure it’s running:
sudo systemctl status oauth2-proxy
View logs to troubleshoot any issues:
sudo journalctl -u oauth2-proxy
Conclusion
By setting up OAuth2 Proxy as a systemd service, you simplify its management and ensure it starts reliably with your server. This approach is especially useful for production environments where stability and automation are critical.