Ubuntu – Make a systemd service run as user xyz

systemd

I've created a .service file that includes User=xyz in the [Service] section. The service still runs as root. Quid?

[Unit]
Description=...
Requires=network-online.target

[Service]
ExecStart=/usr/bin/java ...
Type=simple
ExecStop=/usr/bin/java ...
User=siraprise

[Install]
WantedBy=multi-user.target

Best Answer

Apparently the behaviour changes if User= is specified before ExecStart=.

Don't know whether that's a feature or an accident, but as a feature it's pretty dumb and moreover it seems undocumented which is actively annoying.

Related Question