jeandupont
Posts: 38
Joined: Mon Dec 23, 2013 2:13 pm

trouble running idle as a root using vnc

Mon Dec 23, 2013 2:36 pm

I'm using the rpi for learning Python. I discovered that when programming the GPIO pins the default idle which is on the desktop doesn't allow one to write to the pins because you need to be a sudoer to do that. So I did the following:
1. Open a terminal
2. type cd ~/Desktop
3. type touch idle_as_root
4. type nano idle_as_root
5. type in sudo idle
6. exit nano
7. type in sudo chmod +x idle_as_root
8. Close terminal
9. Double click on the idle_as_root program on your desktop
So far so good. This works fine as long a I run the GUI with a screen connected to the rpi.
Because I don't always have an extra screen at my disposal, I want to connect to the rpi via vnc.
To achieve that I did this:
made the file /etc/init.d/tightvncserver:
#!/bin/bash
# /etc/init.d/tightvncserver
VNCUSER='pi'
case "$1" in
start)
#changed line below for correct user-environment, otherwise you'll start in / and not in /home/pi
# su $VNCUSER -c '/usr/bin/tightvncserver :1'
su -l $VNCUSER -c '/usr/bin/tightvncserver :1'
echo "Starting TightVNC server for $VNCUSER "
;;
stop)
pkill Xtightvnc
echo "Tightvncserver stopped"
;;
*)
echo "Usage: /etc/init.d/tightvncserver {start|stop}"
exit 1
;;
esac
exit 0
then started tightvncserver a first time and entered password
then
sudo chmod 755 /etc/init.d/tightvncserver
then
sudo update-rc.d tightvncserver defaults

I now can log in via vncviewer and see the desktop, clicking the standard idle-icon works fine, clicking the idle_as_root however
does not work.
After some further research I found that entering the command
xhost +local:root
also makes idle_as_root work

I now want to perform this command "xhost +local:root" automatically when booting
unfortunately putting it in ~/.bash_profile doesn't make it work, neither does putting it in ~/.xsession, nor in ~/.xinitrc, nor in an autostart-file in ~/.config/openbox/ ...
Putting it in .bashrc does work _after_ opening a terminal which isn't very nice workaround

So my question is, where to put that" xhost +local:root command". It should work preferably both with or without starting directly in the GUI

help is very much welcome
kind regards,
jean
Last edited by jeandupont on Mon Dec 23, 2013 4:35 pm, edited 1 time in total.

User avatar
jojopi
Posts: 3078
Joined: Tue Oct 11, 2011 8:38 pm

Re: trouble running idle as a root using vnc

Mon Dec 23, 2013 4:23 pm

jeandupont wrote:so my question is, where to put that" xhost +local:root command". It should work preferably both with or without starting directly in the GUI
That is not the best solution. It is illogical to turn off security for root's benefit, because root can bypass security anyway.

Your problem is that idle, when it is running as root, does not know where to look for your .Xauthority file. You could change the script to "sudo XAUTHORITY=$HOME/.Xauthority idle". However, that only works as long as sudo does not need to ask for a password. sudo is not really suited to starting GUI applications. Use "gksu idle" instead.

jeandupont
Posts: 38
Joined: Mon Dec 23, 2013 2:13 pm

Re: trouble running idle as a root using vnc

Mon Dec 23, 2013 5:09 pm

jeandupont wrote:
>so my question is, where to put that" xhost +local:root command". It should work preferably both with or without starting directly >in the GUI
>
>That is not the best solution. It is illogical to turn off security for root's benefit, because root can bypass security anyway.
>Your problem is that idle, when it is running as root, does not know where to look for your .Xauthority file. You could change the >script to "sudo XAUTHORITY=$HOME/.Xauthority idle". However, that only works as long as sudo does not need to ask for a >password. sudo is not really suited to starting GUI applications. Use "gksu idle" instead.

thanks a lot, just changing sudo idle to gksu idle in idle_as_root.desktop does the job, great!
kind regards,
jean

Josephus
Posts: 6
Joined: Wed Dec 03, 2014 2:48 pm

Re: trouble running idle as a root using vnc

Wed Dec 03, 2014 4:03 pm

I have the same problem !


[email protected] ~ $ sudo idle &
[1] 3950
[email protected] ~ $ Client is not authorized to connect to ServerTraceback (most recent call last):
File "/usr/bin/idle", line 5, in <module>
main()
File "/usr/lib/python2.7/idlelib/PyShell.py", line 1427, in main
root = Tk(className="Idle")
File "/usr/lib/python2.7/lib-tk/Tkinter.py", line 1712, in __init__
self.tk = _tkinter.create(screenName, baseName, className, interactive, wantobjects, useTk, sync, use)
_tkinter.TclError: couldn't connect to display ":1.0"
[email protected] ~ $

I have spent hours to solve this ......... please help

User avatar
DougieLawson
Posts: 35555
Joined: Sun Jun 16, 2013 11:19 pm
Location: Basingstoke, UK
Contact: Website Twitter

Re: trouble running idle as a root using vnc

Wed Dec 03, 2014 10:15 pm

Run the vncserver as root
sudo vncserver
connect to the root vnc session then run
sudo DISPLAY=:2 idle # with the right number for root's VNC.
Note: Having anything humorous in your signature is completely banned on this forum. Wear a tin-foil hat and you'll get a ban.

Any DMs sent on Twitter will be answered next month.

This is a doctor free zone.

Return to “Troubleshooting”