Question

I just got my Kali live USB up and running and wanted to get familiar with the system by working on some code I have been writing on my windows box. Long story short I couldn't get some very basic tkinter code to work so I went super basic. Turns out I can only get it to run if I'm root or the sudo. see below.

ben@kali:/usr/lib/python3.2$ python
Python 3.2.3 (default, Feb 20 2013, 14:44:27) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
>>> t = Tk()
No protocol specified
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "tkinter/__init__.py", line 1701, in __init__
    self.tk = _tkinter.create(screenName, baseName, className, interactive,     wantobjects, useTk, sync, use)
_tkinter.TclError: couldnt connect to display ":0.0"
 >>> 
ben@kali:/usr/lib/python3.2$ sudo python
Python 3.2.3 (default, Feb 20 2013, 14:44:27) 
[GCC 4.7.2] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> from tkinter import *
>>> t = Tk()
>>> 

as you can see when not running python as root I get errors, by using sudo for python suddenly tkinter works (obviously you can't see the window but it works). I'm very new to linux and really aren't sure where to start. I did try chmod 777 on the tkinter folder but that seemed to have no effect. Any ideas would be extremely helpful. Thank you

Was it helpful?

Solution

It all depends on what your DISPLAY environment variable is set to. That indicates the socket that represents the connection to the display server; for :0.0, that's a Unix-domain socket (typically /tmp/.X11-unix/X0, but not necessarily; it's up to an agreement between your Xserver and your Xlib). If you've not got permission to access that socket in that directory, you won't be able to use that display.

There might also be some issues relating to the file named in the XAUTHORITY environment variable, depending on exactly how the connection is secured and authenticated. There's a lot of possible complexity here, but the summary is that if a security key required to authenticate to the X server is stored in a file that the X client library can't read (or can't find), the connection will fail. This is independent of whether the socket is reachable in the first place (my preceding paragraph).

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top