0

So I am looking for a way to start a system service at the boot time to run as a normal user.

I created service file /etc/systemd/system/my-service.service as root, and then when I tried to start the service as a regular user: service my-service start I was given a chance to choose the user to run the service, but then also I was asked to enter a password. However, I didn't set up the pass for this user on purpose, and I only use private key for authentication. The service that I have created, I just need to execute a command under specific user, and not root. What are my options here?

0

You need root-access to start services, even when they are set up to run as a user.

So:

sudo service my-service start

You user needs access to sudo though ... for the first user that is set up on ubuntu this is usually the case by default. You will then need to enter the password of your own user (not the one the service runs under).

You can also set up /etc/sudoers to allow your user to run the command without asking for a password.

|improve this answer|||||
0

You should access the /etc/sudoers file and add the following line:

user   ALL=NOPASSWD:/etc/systemd/system/my-service.service

This will allow the user to start/stop/restart the service without prompting for a password.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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