Skip to content

Instantly share code, notes, and snippets.

@sevenissimo
Created April 2, 2025 08:35
Show Gist options
  • Select an option

  • Save sevenissimo/03a03badc06d9d427cd917ef10ad2a0f to your computer and use it in GitHub Desktop.

Select an option

Save sevenissimo/03a03badc06d9d427cd917ef10ad2a0f to your computer and use it in GitHub Desktop.

Run commands as Systemd (Dynamic)User

My Systemd unit uses User=hass, but user is reasonably locked. su, sudo or runuser are not aplicable.

Install packages in Python venv

systemd-run --uid=$(id -u hass) --gid=$(id -g hass) /usr/bin/python -m venv /var/lib/hass/.venv && /var/lib/hass/.venv/bin/pip install packaging

Check Home Assistant config

systemd-run --uid=$(id -u hass) --gid=$(id -g hass) /usr/bin/python -m venv /var/lib/hass/.venv && /var/lib/hass/.venv/bin/hass --config /var/lib/hass/ --script check_config -i -f

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment