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 am able to set xhost at boot in Fedora by editing /etc/gdm/Init/Default and for example add:

/usr/bin/xhost +local:

How can similar be done in Ubuntu? I want that the

/usr/bin/xhost +local:

command is executed when the system is sitting at login prompt.

share|improve this question

The xhost command needs an active X server to run, it can run at the login screen, for example when lightdm loads. You can enable it by editing /etc/lightdm/lightdm.conf and adding the line:


example /etc/lightdm/lightdm.conf file:


example /home/user/bin/ file:

xhost +

It works on Ubuntu 12.04.1 LTS, and it was needed to enable a Java application that needed X and was run by Tomcat 6.

share|improve this answer
you might need to make the script executable with: chmod +x /home/user/bin/ – George Litos Nov 2 '12 at 6:25

This worked for me:

Edit ~/.xinitrc:

export DISPLAY=":0.0"
xhost +

Note: in my specific setup, I'm running only openbox. Normally that file is empty or missing in Ubuntu. My guess is that you could remove the "openbox" line and it would work, but I don't have a way to test it right now. If it doesn't work, replace the last line for your window manager command.

share|improve this answer

~/.xinitrc did not work for me on Ubuntu 14.04 but the following in ~/.profile did. On each login, GUI/terminal/SSH/etc..., the script will run so I redirect stdout to silence the output.

xhost +local: > /dev/null

share|improve this answer

Edit the file /etc/rc.local (with sudo) and add the command before the last command (exit 0).

share|improve this answer
This wont work(and I tried never the less and it doesnt work). Because that script will not have access rights to change that setting at first place. It has to be done as lightdm user? – yurtesen Mar 26 '12 at 9:24

Add the following line to /etc/xdg/lxsession/LXDE/autostart

xhost +local:
share|improve this answer

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.