LinuxQuestions.org
Share your knowledge at the LQ Wiki.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Software
User Name
Password
Linux - Software This forum is for Software issues.
Having a problem installing a new program? Want to know which application is best for the job? Post your question in this forum.

Notices


Reply
  Search this Thread
Old 03-25-2012, 08:14 PM   #1
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Can't connect to Xserver


Hello all,

I am trying to pop up a messagebox in KDE4 from a background process. In order to test this, I have opened a real console (CTRL-ALT-F1) and su-ed to root.

According to ps ax | grep X, X is running on display :0 and VT8:
/usr/bin/X :0 vt8 -br -nolisten tcp -auth /var/run/xauth/A:0-9tDrka

Now my problem is that I can't connect to the X server from a console. This is the error message that I get when entering this command:
export DISPLAY=:0 && kdialog --msgbox "Hello world"
returns:
kdialog: cannot connect to xserver :0

Thinking that this might have to do something with allowed connections, I tried to set xhost:
export DISPLAY=:0 && xhost +localhost
which returns
xhost: unable to open display ":0"

For DISPLAY I tried :0, :1, :0.0, :0.1, :1.0, :1,1, but to no avail.

From a virtual console (pts/0) it is no problem to pop up message boxes.

I am running Debian Squeeze, KDE 4.4.5, kernel 2.6.32-5-amd64

Anyone who has some tips on how to accomplish this, or how to find out which DISPLAY to use?

jlinkels
 
Old 03-26-2012, 04:38 AM   #2
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

Rep: Reputation: 385Reputation: 385Reputation: 385Reputation: 385
Im not so sure about this but what about:
Code:
export DISPLAY=/usr/bin/X :0 && kdialog --msgbox "Hello world"
or yet(this one might be a bit rough)
Code:
export DISPLAY=/usr/bin/X :0 vt8 -br -nolisten tcp -auth /var/run/xauth/A:0-9tDrka && kdialog --msgbox "Hello world"


Regards
 
Old 03-26-2012, 06:39 AM   #3
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,869

Rep: Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314
xhost must be executed in a terminal window and after that you can try to access it from your console.
executing xhost in the console will not work (it is not allowed to modify access outside of the X windows)

Last edited by pan64; 03-26-2012 at 06:40 AM. Reason: mistyped
 
1 members found this post helpful.
Old 03-26-2012, 11:35 AM   #4
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
pan64: Something is starting to dawn now.
Console is considered something different than Xterm. Xterm is able to connect to the Xserver, but Console cannot because it is an external connection. So from Xterm the xhost command has to be issued, and then Console should be able to connect?
Let me experiment with that later.

jlinkels
 
Old 03-26-2012, 11:50 AM   #5
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,869

Rep: Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314
xhost is used to set access control. By default the owner of the xserver (the user who started that session) will be able to modify it. Xterm is started within the session, so there is no problem with it, but when you want to start something from the console....
So you need to switch off access control - that is xhost +, you can execute it in the Xterm window - and than you can make connections from outside.

in the real unix/linux life the X windows system is a client/server pair of applications, the Xserver itself is owned by root, and is usually named X or Xorg. It is only used to draw the content on the display. The client side is called session manager and this is owned by the user. All the applications within a session connect to the session manager, and the manager takes care about the access rights (to itself).
 
1 members found this post helpful.
Old 03-26-2012, 02:00 PM   #6
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Good, thanks for pointing me in the right direction.
What I did is this:
I am logged in into KDE as jlinkels
In Xterm I issued the command xhost +localhost
Then in Console (TTY1), logged in as jlinkels, the kdialog command succeeded.
However, as root it did not. Which is understandable according to the text in your post.
When I tried:
root# su - jlinkels -c "export DISPLAY=:0 && kdialog \"Hello\""
this worked as well.
The script I am writing will be running with root credentials. So by using the su command and specifying this user, I can pop up a dialog for this user. Would that be the correct approach?

jlinkels
 
Old 03-26-2012, 03:10 PM   #7
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
I don't know if you noticed but the -nolisten tcp option sounds like X won't be listening to anything you want to send it through network, even if it's from localhost.
 
Old 03-26-2012, 03:27 PM   #8
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,869

Rep: Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314
you would need to read the man page of xhost..http://www.manpagez.com/man/1/xhost/.
xhost +localhost will allow to connect from console or from another x session on the localhost but only for the same user.
xhost +root will allow the user root to connect.
xhost + will completely switch off access control, so anyone can connect from anywhere.
 
Old 03-26-2012, 03:36 PM   #9
eantoranz
Senior Member
 
Registered: Apr 2003
Location: Costa Rica
Distribution: Kubuntu, Debian, Knoppix
Posts: 2,092
Blog Entries: 1

Rep: Reputation: 90
I just tried adding xhost +localhost on my computer (runs with -nolisten tcp) and just got kicked out of trying to run one application from a VT (as I expected, as a matter of fact).
 
Old 03-26-2012, 05:19 PM   #10
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by eantoranz View Post
I don't know if you noticed but the -nolisten tcp option sounds like X won't be listening to anything you want to send it through network, even if it's from localhost.
I did see the -nolisten. But:
- I know I am able to connect from other hosts over ssh, using ssh -x, which means there connection possible from the localhost. (I believe ssh -x acts like a tunnel)
- Turning off -nolisten in Debian is one of the best kept secrets in the X environment. Googling yields hundreds of solutions telling (a) to switch this off in /etc/X11/xinit/xserverrc, but this file and directory doesn't exist or (b) grep in /etc/ and subfolders for the string nolisten, which is not found.

Ref. the second paragraph, I would be extremely happy if someone can tell me how to switch off this option so I can experiment with it. It is not funny to see how numerous parrot posters on forums simply repeat (verbatim): "you have to turn off this option by editing xserverrc".

jlinkels
 
Old 03-26-2012, 05:24 PM   #11
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by pan64 View Post
you would need to read the man page of xhost..http://www.manpagez.com/man/1/xhost/.
That might be an idea. I did browse thru the man page, but I might have missed a paragraph or two...
Quote:
Originally Posted by pan64 View Post
xhost +localhost will allow to connect from console or from another x session on the localhost but only for the same user.
xhost +root will allow the user root to connect.
Let me try that as well.
Quote:
Originally Posted by pan64 View Post
xhost + will completely switch off access control, so anyone can connect from anywhere.
Although this network is behind a NATted router and the local network is completely trusted, I don't think that is a good thing to do. Even if it is safe, it is a brute force approach. I think you gave this example as how not to set the permissions, right?

jlinkels
 
Old 03-27-2012, 12:13 AM   #12
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,869

Rep: Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314Reputation: 7314
Quote:
Originally Posted by jlinkels View Post

Although this network is behind a NATted router and the local network is completely trusted, I don't think that is a good thing to do. Even if it is safe, it is a brute force approach. I think you gave this example as how not to set the permissions, right?
You are right, xhost + is not suggested anyway. But if you want to test if it works you can give it a try. This is the simplest way to check the configuration. xhost - will switch on access control again.
 
Old 03-27-2012, 01:03 AM   #13
ukiuki
Senior Member
 
Registered: May 2010
Location: Planet Earth
Distribution: Debian
Posts: 1,030

Rep: Reputation: 385Reputation: 385Reputation: 385Reputation: 385
Quote:
Originally Posted by jlinkels View Post
... /etc/X11/xinit/xserverrc, but this file and directory doesn't exist or ...
Ok that got me because on one of my Debian machines i do have that file, but some others not. I know that because of this post. The package that generates it is xbase-clients.

Regards
 
1 members found this post helpful.
Old 03-27-2012, 08:08 AM   #14
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by ukiuki View Post
Ok that got me because on one of my Debian machines i do have that file, but some others not. I know that because of this post. The package that generates it is xbase-clients.
Regards
Weird, I am running Squeeze as well. But on none of the machines I originally installed with Squeeze this directory or file is present. On upgraded machines this file is present, and on the sole Lenny machine which I haven't touched for 730 days the file is there as well.

Frankly I despise the Xorg/KDM/KDE policy to hide, move, rename or obsolete configuration files. If the config files are still present and being used they can be in 17 different locations, and on top of that Debian applies its own policy of using or ignoring files. Xorg/KDM/KDE is not the easiest by nature alone, and we could do without additional obfuscation.

jlinkels

OT1: Love to see that configuration in the post you are referring to. I used to sell those machines in 1998 with Win98 installed. Yikes!

OT2: Your statement about Facebook could not be more true! Someday I would expect Facebook to collect all information about my machine, web pages I have visited and whatnot, and then add me to a community: "Hi jlinkels: we thought you might like to know that all these people have visited amazon.com like you did, so we added you to that group. You will receive all mail from those group members, and we carefully have hidden the unsubscribe button"
 
Old 03-27-2012, 08:12 AM   #15
jlinkels
LQ Guru
 
Registered: Oct 2003
Location: Bonaire, Leeuwarden
Distribution: Debian /Jessie/Stretch/Sid, Linux Mint DE
Posts: 5,195

Original Poster
Rep: Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043Reputation: 1043
Quote:
Originally Posted by pan64 View Post
xhost +root will allow the user root to connect.
No, it doesn't. xhost considers root as a hostname. As I understand if I want to use a name, it should be a nis name. I do have nis running, but root is a local account.

jlinkels
 
  


Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
can't connect to xserver? joutlancpa Slackware 4 09-08-2011 10:05 AM
Cannot connect to Xserver Srikanth VM Slackware 3 10-03-2009 08:33 AM
can't connect to Xserver in Ubuntu hari78 Linux - Software 2 07-28-2009 10:55 PM
java can't connect to Xserver alaios Linux - Software 5 01-10-2006 12:29 AM
fluxbox Error: couldn't connect to xserver Furlinastis Slackware 4 09-22-2005 07:20 AM

LinuxQuestions.org > Forums > Linux Forums > Linux - Software

All times are GMT -5. The time now is 08:57 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration