Ask Ubuntu is a question and answer site for Ubuntu users and developers. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

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


share|improve this question
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. – Javier Rivera Oct 7 '11 at 6:57
@JavierRivera So what would be the solution ? – omeid Oct 8 '11 at 12:15
Good question, upvoted ;). – Javier Rivera Oct 8 '11 at 12:24
up vote 5 down vote accepted

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.
share|improve this answer
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. – Nathan Osman 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.

share|improve this answer

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.

share|improve this answer
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 bad :-) – thom Mar 3 '13 at 23:20

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

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