Sudo won't open applications GUI

Hello,
I need some help regarding running applications using sudo.
Whenever I try to run an app using the sudo command in Konsole I get a message that the Display cannot be opened.
For example:

sudo gedit /etc/samba/smb.conf
Cannot open display: 
Run 'gedit --help' to see a full list of available command line options.

or

sudo virtualbox
Failed to open the X11 display!

or

sudo kwrite /etc/samba/smb.conf
kwrite: cannot connect to X server

or

sudo bluefish /etc/samba/smb.conf

** ERROR **: Error parsing command line options. Cannot open display: 
Please run: bluefish -?

However, normal running of these applications works perfectly.
I can’t seem to figure out the problem, can anyone help?

Thanks in advance.

For use in terminal or in a script as a regular user only try these:

For KDE:

dbus-launch kdesu kwrite /etc/samba/smb.conf

OR

For Gnome:

dbus-launch gnomesu gedit /etc/samba/smb.conf

Thank You,

Thanks, that worked perfectly :slight_smile:
Do I have to use dbus everytime I try to run an application using sudo?? I am sorry for the newbie question I have only recently switched to openSUSE from ubuntu, and things like these used to work there…

You don’t have to use dbus-launch at all for programs such as kwrite or gedit.

Indeed the issue is using sudo, which will not work with graphic programs like kwrite or gedit and the need was to switch to using kdesu or gnomesu instead, but other programs may not start in a terminal session with out using the dbus-launch app and I have found no problem using it in when in doubt.

Thank You,

Great, I even managed to run the VirtualBox now. :))

Thanks again.

First off, we were more than happy to help. But, I must say that it is preferred to not run VirtualBox as root. The need to run VirtualBox as root depends on where its configuration files and Virtual Disks are located. For each Virtual Session, there are two components, its configuration file and its virtual disk. And, besides that, if you started running VirtualBox as root the very first time, its configuration files are most likely in the root user folder. On my PC, the default Virtual Machine Folder is located: /VirtualBox/VirtualBoxVMs and I am also creating the Virtual Disks there. This is a EXT4 partition I created just for VirtualBox and I have set the fstab load options as just “defaults”, thus not requiring you to be root. I made these selections myself to a partition that had lots of room. If instead, you created these in your /home folder. where you also had lots of room, you would not need to be root either to run VirtualBox. So, if either the Virtual Machine files or the Virtual Disk files are located in /root or on any partition you must be root to write top, then you can only get VirtualBox to run as root. One way to change this is to change the preferences to point into your home area, make sure your Virtual Disks are also located in /home or some where you have rights without being root. You can create a new Virtual Machine, with the same settings, but to use an existing Virtual Disk. I do this to move a created Virtual Session to a different computer and it does work just fine. You could continue on as before and decide to do something else when you reinstall openSUSE or when you get a new computer. As you notice, except for YaST and a very few other things, you need not be root to run them such as Firefox, or LibreOffice or Amarok, just to name a few. So think about it and ask for help if you need it.

Thank You,