I've installed a service which runs as another user (for security reasons I don't want it to run as root) and this user account is locked (i.e. can't login). Obviously now when I run commands to query this service from my user account, the command line tools run as my user and the service is not running as me and so errors are returned. Currently I'm having to use sudo -H -u username command in order to use the command line tools.

How do I make a service running as a user accessible to another user? I've tried adding my user account to the same group but no luck.


  • You tagged this question as systemd, but didn't mention it in your question. When your say "query the service", are you referring to using the systemctl tool? – Mark Stosberg May 17 '18 at 11:37
  • @MarkStosberg So I'm running a service using a systemd .service file and I have a line 'user=other_user'. There is a running daemon and an admin cli tool (just like for example mysqld and mysql) but I can't query the running service with the cli tool as the service is running as another user (i.e. not me). Usually the service would run as root so sudo would do the trick. In this case access is denied from the cli tool. So it there a way to access the service as a different user with 'sudo -u -H service_username' every time? Thanks. – Sapient Saxon Saboo Jun 19 '18 at 22:21

Make a one or two line bash script designed to be run as root which runs the command you want as as the other user, using su or sudo.

Add a check to the script to confirm that's only run as root to avoid strange error messages.

To run the command as another user, just sudo my-cli-tool ....

This is fast to create and memorable to use.

Your Answer

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.