2

For testing purposes a systemd service file is meant to execute a simple bash script. I want the service to be started by a "system" user. The bash script is owned by this system user and has granted execution permission.

The Service file is simply:

[Unit]
Description=Come one step closer
After=network-online.target
Requires=network-online.target

[Service]
User=test1
Group=test1
Type=simple
ExecStart=/usr/bin/bash /absolute/path/to/test.sh

[Install] 
WantedBy=multi-user.target

The test.sh script should simply give out a message to journalctl - it is just for testing.

I reloaded the systemd unit files with:

$ sudo systemctl daemon-reload

I started the service with:

$ sudo systemctl start tester.service

The output of systemctl status tester.service yields, that there is no permission for the bash execution.

I added the "system" user test1 like that to the system:

$ sudo useradd -r -s /usr/bin/bash test1 -U

What do I need to do for user test1 to get permission to start the service. I cannot test the bash script with user test1, because as test1 being a system user I cannot log in as test1.

  • Who put bash in /usr/bin? – Ipor Sircer Nov 14 '18 at 1:04
  • @bejo Please check permissions of all the directories above /absolute/path/to/test.sh, you need "execute" (x) permissions in all of them to be able to access the script with a non-root user. Maybe post output of ls -ld / /absolute /absolute/path /absolute/path/to /absolute/path/to/test.sh output if you want helping checking permissions – filbranden Nov 14 '18 at 1:25
  • @IporSircer the /usr merge did... At least on recent Fedora, /bin is a symlink to /usr/bin. – filbranden Nov 14 '18 at 1:56
  • @bejo You can also probably get a shell under user "test1" with the command sudo su - test1 – filbranden Nov 14 '18 at 2:00
  • @FilipeBrandenburger Thank you for your answer. That does the trick. One folder did not provide x-permission. I changed that and it is working now. Great hint. Thanks again. Can you copy your Comment into an answer, just so I can mark my problem as solved? – bejo Nov 14 '18 at 20:00
0

As established on the comments, the problem is with permissions of the directories above /absolute/path/to/test.sh, in which a non-root user needs to have "execute" (x) permissions in order to be able to access the script.

This can be diagnosed by looking at the mode of each of the parent directories, for example using a command such as:

ls -ld / /absolute /absolute/path /absolute/path/to /absolute/path/to/test.sh

And checking whether "test1" user would have execute permissions to all directories, in addition to read permissions to the test.sh script itself.

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.