Running as non-root user

Tom4 years ago

I am trying to run run traccar as non-root user, and need help. I read this :
https://www.traccar.org/linux/

I have Ubuntu 18.04 LTS , working setup with traccar 4.7 (running as root-user).

What have I checked / done ?
“ps -ef” shows that traccar service runs as root (root ….. /opt/traccar/jre/bin/java -j )
“ls -al /opt/” shows that root is owner of the directory “/traccar”
“ls -al /opt/traccar” shows that root is owner of the sub-directories in “/opt/traccar” and files there.

I added a user with “adduser traccuser” (traccuser is the username)
I set the owner of the directory “/traccar” (and the sub-directories and files in this directory) the new user with :
“chown -R traccar:traccar /opt/traccar”

I checked the owner of the directory and sub-directories again with “ls -al /opt/” and “ls -al /opt/traccar” – the new user “traccuser” is owner now.

I created a directory with “mkdir /etc/systemd/system/traccar.service.d/” and then
created a file with “touch /etc/systemd/system/traccar.service.d/run-as-user.conf” , both described here https://www.traccar.org/linux/

I edit the file “run-as-user.conf” in “/etc/systemd/system/traccar.service.d/” and put in :
[Service]
User=traccuser
Group=traccuser

At last, I restarted the server and checked with “ps -ef” the user of the service – traccar is working,
but the traccar service is running farther as user “root”.

What have I done wrong ?

Thanks for help !

Tom

Anton Tananaev4 years ago

What is the issue?

Tom4 years ago

At the end i wrote :
At last, I restarted the server and checked with “ps -ef” the user of the service – traccar is working,

but the traccar service is running farther as user “root”.

Anton Tananaev4 years ago

I asked exactly because that sentence is not clear to me. What do you mean by "running farther"? Are you saying that it stops by itself? I'm not sure why you wouldn't just say that, if that's the case.

Tom4 years ago

Oh, ok - sorry for my bad english.

At last i restarted the server, after the restart i expected that the traccar service runs as user traccuser now (traccuser is the newly added non-root user).

But the traccar service runs as user root, just like before, checked with ps -ef .

Thank you for your help.

Anton Tananaev4 years ago

I guess the issue is with systemd service configuration.

Tom4 years ago

With the command "systemctl status traccar.service" i found out that the file "run-as-user.conf" was corrupt. I deleted the file and created a new one, and now the traccar service is running as the added non-root user.

I am not practiced with linux. I hope my summary of commands in this thread is helpful for other Linux newbies.

Zero482 years ago

I Usually change the owner of Traccar files from root to traccar in this way :

$ sudo chown -R traccar:traccar /opt/traccar

I hope this help somebody