8

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.

12

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:

display-setup-script=/home/user/bin/xhost.sh

example /etc/lightdm/lightdm.conf file:

[SeatDefaults]
greeter-session=unity-greeter
user-session=ubuntu
display-setup-script=/home/user/bin/xhost.sh

example /home/user/bin/xhost.sh file:

#!/bin/bash
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.

| improve this answer | |
  • 2
    you might need to make the xhost.sh script executable with: chmod +x /home/user/bin/xhost.sh – George Litos Nov 2 '12 at 6:25
  • Works in Xubuntu 18.04, but make sure the script is executable as @George Litos mentioned, otherwise your system won't boot. – José Tomás Tocino Jun 12 '18 at 10:21
2

This worked for me:

Edit ~/.xinitrc:

export DISPLAY=":0.0"
xhost +
openbox

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.

| improve this answer | |
  • xhost: unable to open display ":0.0" – alper Jul 16 at 10:31
  • 1
    @alper : Probably you are connecting remotely and there is no display or X available? Check: superuser.com/questions/310197/… – lepe Jul 16 at 14:04
1

~/.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
| improve this answer | |
1

I had the same issue with Ubuntu 17.10. It could be that my system was not properly configured. Anyway, in my case, I added

xhost + SI:localuser:root > /dev/null

at the bottom of my ~/.bashrc file and it worked. I don't know if this is a security risk. I share that in case someone else is in the same situation and trust that adding root to the list of privileged X server users should be OK.

It is suggested here on ubuntuhandbook.org

You can test it directly on the terminal first:

xhost + SI:localuser:root
xhost -

The second line makes sure that only those in the list have access to the X server. Then try "Edit as administrator", after right clicking on a file or directly execute

pkexec gedit

If this does not work, then it is pointless to make the command permanent in ~/.bashrc.

To be more precise, I first executed

xhost

to see which users had access to the X server. I saw that the format was SI:localuser:dominic where dominic is my login name. So, I used the same format SI:localuser:root to add the root user.

| improve this answer | |
0

Here's a variant of @GeorgeLitos's answer, with these changes:

  • Don't directly modify /etc/lightdm/lightdm.conf, as this is a system-owned file that may be overwritten by system upgrades. Instead, use the extension directory /etc/lightdm/lightdm.conf.d/. This also means that other settings don't need to be duplicated in there.
  • No need for a separate shell script; the command can be directly placed into the configuration file.

Just create a file (as user root) /etc/lightdm/lightdm.conf.d/xhost.conf with these contents:

[SeatDefaults]
display-setup-script=xhost +

This works on Ubuntu 16.04.5 LTS.

| improve this answer | |
-1

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

| improve this answer | |
  • 1
    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
-1

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

xhost +local:
| improve this answer | |

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.