Operating System - Linux
1748103 Members
4851 Online
108758 Solutions
New Discussion юеВ

Re: gui commands doesnt works when running via sudo

 
Maaz
Valued Contributor

gui commands doesnt works when running via sudo

jodt@tiger:~/Desktop> xhost +
access control disabled, clients can connect from any host
jodt@tiger:~/Desktop> sudo firefox
Error: no display specified
jodt@tiger:~/Desktop> sudo virt-manager
Unable to initialize GTK: could not open display
jodt@tiger:~/Desktop>

only "sudo /sbin/yast2" works, but in TUI(ncurses) mode

all of the above commands works nicely when I did "su - root"

what should I do, please help

Regards
Maaz
12 REPLIES 12
Jupinder Bedi
Respected Contributor

Re: gui commands doesnt works when running via sudo

do as follows


#xhost +

than

# DISPLAY=ip_address:0.0;export DISPLAY

than try and also note ip_address should be of the same machine on which you want to diaplay your gui
All things excellent are as difficult as they are rare
Maaz
Valued Contributor

Re: gui commands doesnt works when running via sudo

Hi Thanks Jupinder Bedi for help

I did followinf
jodt@tiger:~/Desktop> xhost +
jodt@tiger:~/Desktop> DISPLAY=127.0.0.1:0.0; export DISPLAY

but no gain.. same errors.

I am working on this box directly(no network ..ssh etc)

Regards
Maaz
Emil Velez
Honored Contributor

Re: gui commands doesnt works when running via sudo

Need to set the display


SAM has a restricted sam builder on 11.23 and lower so a non-root user can user their regular id to do system admin tasks in sam.

In 11.31 the system management homepage can be configured to allow a non-root person to do different tasks with their regular userid. This way sudo is not necessary.
Andrew Cowan
Honored Contributor

Re: gui commands doesnt works when running via sudo

I think that the problem is that Linux is denying you local access to the desktop and not sudo.

I can't find the exact manual page but you have to change one of the 'sysconfig' files to enable local access to the desktop.

Some distributions such as Fedora, Mandriva, and Red Hat, use the prefdm script to decide on the XDMCP server to run. Linux runs the prefdm script that loads ├в /etc/sysconfig/desktop├в file. The DESKTOP line in ├в /etc/sysconfig/desktop├в file sets the default desktop environment, which sets the default XDMCP server.

The ├в /etc/X11/xdm/Xaccess├в file is a configuration file of XDM. You can configure XDM server for remote access. The /etc/X11/xdm/Xaccess file controls access of XDM server. You can make use of an asterisk (*) to provide access of the system to anyone. The * CHOOSER BROADCAST line as displayed on the screen, tells XDM that anyone may request chooser that accepts XDMCP connections
Maaz
Valued Contributor

Re: gui commands doesnt works when running via sudo

Hi thanks Emil Velez
there is no SAM here, I am using a Linux distro(SUSE 11)

I think SAM is a YaST equivalent in HP-UX

Regards
Steven Schweda
Honored Contributor

Re: gui commands doesnt works when running via sudo

> Error: no display specified

echo $DISPLAY

> all of the above commands works nicely when
> I did "su - root"

su - root
echo $DISPLAY

What's different?
Maaz
Valued Contributor

Re: gui commands doesnt works when running via sudo

I would like to clear that, I am not accessing this box remotely, I am working on this directly, logs in via an ordinary account(jodt), then whenever I need to work as root, I try to sudo.

Hi Steven Schweda Thanks for help
jodt@tiger:~/Desktop> sudo firefox
Error: no display specified
jodt@tiger:~/Desktop> echo $DISPLAY
:0.0
jodt@tiger:~/Desktop> su - root
Password:
tiger:~ # echo $DISPLAY
:0.0
tiger:~ #

Hi Andrew Cowan thanks for help
/etc/sysconfig/console, /etc/sysconfig/displaymanager, and /etc/X11/xdm/Xaccess attached.

tiger:~ # grep -v ^# /etc/X11/xdm/Xaccess

* #any host can get a login window

* CHOOSER BROADCAST #any indirect host can get a chooser

tiger:~ # grep -v ^# /etc/sysconfig/displaymanager

DISPLAYMANAGER="gdm"
DISPLAYMANAGER_REMOTE_ACCESS="no"
DISPLAYMANAGER_ROOT_LOGIN_REMOTE="no"
DISPLAYMANAGER_STARTS_XSERVER="yes"
DISPLAYMANAGER_XSERVER_TCP_PORT_6000_OPEN="no"
DISPLAYMANAGER_AUTOLOGIN=""
DISPLAYMANAGER_PASSWORD_LESS_LOGIN="no"
DISPLAYMANAGER_AD_INTEGRATION="no"
DISPLAYMANAGER_SHUTDOWN="auto"
DISPLAYMANAGER_RANDR_MODE_VGA=""
DISPLAYMANAGER_RANDR_MODE_auto="1024x768_60 64.11 1024 1080 1184 1344 768 769 772 795 -HSync +Vsync"
DISPLAYMANAGER_XSERVER="Xorg"

tiger:~ # grep -v ^# /etc/sysconfig/console

CONSOLE_FONT="lat9w-16.psfu"
CONSOLE_UNICODEMAP=""
CONSOLE_SCREENMAP="trivial"
CONSOLE_MAGIC="(K"
FB_MODULES=""
FBSET_PARAMS=""
CONSOLE_ENCODING="UTF-8"

Regards
Steven Schweda
Honored Contributor

Re: gui commands doesnt works when running via sudo

> jodt@tiger:~/Desktop> sudo firefox
> Error: no display specified
> jodt@tiger:~/Desktop> echo $DISPLAY
> :0.0

That shows what DISPLAY is in your _normal_
environment, _after_ the "sudo xxx" command
has failed. What I'd like to know is what
DISPLAY is _in_ the "sudo" environment.

I don't use sudo, so I know nothing, but if
it doesn't pass through your DISPLAY setting,
then you might try writing a script which
sets DISPLAY and then runs your browser, and
then try running "sudo your_script". Or, for
example, something like:

sudo DISPLAY=':0.0' firefox
or:
sudo firefox --display ':0.0'


"man firefox" seems to do nothing good around
here, but there's some value in:

firefox --help

Most X programs offer a "-display" (or,
apparently, a "--display") option.

man X
Andrew Cowan
Honored Contributor

Re: gui commands doesnt works when running via sudo

Maaz,

Take a look at these links:

http://www.linuxjournal.com/content/getting-vncserver-running-core-10-gdm

http://www.idevelopment.info/data/Unix/Linux/LINUX_ConfiguringXDMCPRedHatLinux.shtml

Your problem is caused by the GDM security that allows your user to open windows within their own session but it disallows another user, so when you su within a shell, GDM does not see it because it is still running as your user.