I have a camera application which I am trying to run under sudo: but I am receiving this error

cannot connect to x server

the issue is when I dont use sudo, the program opens fine. However, there are certain parts of this application which still need admin privileges.

Since it is a GUI application, I tried to use gksudo then it opens a window asking about the password, but after entering the password the application returns and GUI does not open!

I have tried also

sudo xhost local:root

and got:

xhost: unable to open display""   

I am using lubuntu 14.04

  • 1
    What application?
    – Fabby
    Jan 8, 2015 at 18:21
  • @Fabby, It is the camera manager application from IDS imaging company. It uses QT4 to build a gui application to perform Ethernet configuration.
    – Samer
    Jan 9, 2015 at 18:24

2 Answers 2


This answer is a cannon to kill a rabbit, but if all you're interested in sudoing X applications that is what you'll need.

The solution:

Add to your ~/.bashrc

# Fabby: 2014-11-14: http://askubuntu.com/questions/571116/
# to allow forwarding of xauth keys between users when calling su
# needs to be the last line
export $(dbus-launch)

The explanation:

  • Do you know what the X server is? OK!
  • Do you know that it has a client/server technology? OK!
  • Do you know what D-Bus is? OK!
  • Well, now the dbus-launch variable gets exported so that x messages from one user session can use other user's session! Plain and simple!

I am using SecureCRT as ssh tool, however it cannot display some plots on local host with Windows OS. I have the same problem when using Canopy.


  1. Install Xmanager, running Xmanager Passive.
  2. Add "export DISPLAY=your ip:0.0" in ~/.bashrc, source ~/.bashrc (ip is your host IP, where you wanna display plots or things like that. If you are using Windows, cmd-ipconfig, find your IP).
  3. Test (i.e. $xclock, you can see a clock in your windows screen) or directly test your own GUI applications.


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.