Quick question, is it possible to run as non-root for applications, automatically started when the pi is booted?

I'm having performance and memory issues when my pi starts a homebrewn spotify-client on boot.

Performance - I cannot explain why this is different than when running it from a terminal once logged in, but the music lags a second once every 15-30 seconds.

Memory - My offline tracks doesn't get saved from session to session.

This leads me to the question, can I 'fake' a user logging in and starting the app with user-previlegies?

Right now i'm using /etc/rc.local to run the command /home/pi/spotifyapp & Everything runs smooth and offline tracks are saved when i start the app by myself after the pi has booted


I am skeptical whether running this application under a different user will resolve your issue.

However that being said, you can use the su command to run a command as another user. Therefore to run /home/pi/spotifyapp you should use the following in your rc.local file:

su fakeuser -c '/home/pi/spotifyapp &'

You may want to redirect stdout and stderr to a file to allow you to see any messages generated. The following command will do that:

su fakeuser -c '/home/pi/spotifyapp >> /tmp/spotifyapp.log 2>&1 &'

Where fakeuser is the username that you want to run the process under.

|improve this answer|||||
  • 1
    Changing the current directory, i.e. cd /home/pi/app/ and then running it as a another user seems to solve the problem. Didn't know that trick, thanks a lot :-) – Allan Nørgaard Jun 27 '13 at 8:03

Usually, scripts in /etc/rc.d are using start-stop-daemon to launch, stop and control status of boot-time processus.

Combined with the optional -c, --chuid argument, you can specify under which user you want the process to run.

|improve this answer|||||

I use

sudo -u yourusername command -parameter
|improve this answer|||||

You could place your script at the bottom of /etc/profile file.

|improve this answer|||||
  • I don't think this would have solved my problem, since I had performance issues. Your answer is about starting a process once logged in. Also, you're 3 years late to the party :) – Allan Nørgaard Nov 28 '16 at 8:00
  • 1
    I've browsed around and just throwing my thoughts into it. Maybe helps someone in the future. – HelpNeeder Nov 29 '16 at 15:18

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.