I have some commends that I wish to be called right after login, including 'startx', and I thought rc.local seems a nice place for them, but the problem is that rc.local is run as root and I don't want that, obviously I can do something like this:

su username -c somecommend-here

But I am looking for a way to run the whole 'rc.local' as normal user, or perhaps there is a better place to put my code ?

PS. I am using Ubuntu-mini-remix 1104i386


  • AFAIK rc.local is executed parallel to login at the end of the boot sequence. I mean, it will be executed even if you don't log in, but you can be logged in ant it could be pending execution. Oct 7 '11 at 6:57
  • @JavierRivera So what would be the solution ?
    – omeid
    Oct 8 '11 at 12:15

The easiest way to launch a command when a user logs in is to create a .desktop file for the command and stick it in the ~/.config/autostart folder. What does the desktop file look like? Here is an example that retrieves the Ask Ubuntu home page with wget every time the user logs in:

[Desktop Entry] 
Name=Launch wget
Comment=Fetches the Ask Ubuntu home page.
Exec=wget http://askubuntu.com/
  • Does not seem a good idea to launch startx (as the OP asked) after graphical login.
    – enzotib
    Oct 7 '11 at 7:46
  • @enzotib: There is no mention of a graphical login. Oct 7 '11 at 16:27
  • Maybe I misunderstood the question, I believed the user would to start startx from rc.local. Sorry
    – enzotib
    Oct 7 '11 at 16:38

I don't know the differences between /etc/rc.local and a crontab, but I generally make a service account and add the appropriate job. For example: sudo crontab -u p4padmin -e

@reboot ~/bin/p4p -d -r ~/var/p4p/cache/foo -p 2020 -t depot:2020 -L ~/var/p4p/log/foo.log

You don't have to login for the service to execute.


The linux way is to append your commands to ~/.bashrc instead of /etc/rc.local.

Every user has a .bashrc in it's home directory. This scriptfile is run automatically just after a user logs in. It is run with the credentials of the user so a su command is not needed.

It seems to me that this is exactly what you are looking for.

  • This is not quite correct, as .bashrc is not read when a user logs in using the normal lightdm, for example.
    – user76204
    Mar 3 '13 at 18:32
  • I concluded too fast that the user was using a commandline login instead of a display manager because of the "manual" startx command he mentioned....my bad :-)
    – thom
    Mar 3 '13 at 23:20

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.