skip to Main Content

I have a machine with Ubuntu 20.04 as OS and Jetbrains IntellijIdea for Java development.
I connect to my machine with xrdp, but when I am to run IntellijIdea as root on my machine I got following message:

`No protocol specified

Start Failed
Failed to initialize graphics environment

java.awt.AWTError: Can’t connect to X11 window server using ‘:10.0’ as the value of the DISPLAY variable.
at java.desktop/sun.awt.X11GraphicsEnvironment.initDisplay(Native Method)
at java.desktop/sun.awt.X11GraphicsEnvironment$1.run(X11GraphicsEnvironment.java:107)
at java.base/java.security.AccessController.doPrivileged(AccessController.java:318)
at java.desktop/sun.awt.X11GraphicsEnvironment.(X11GraphicsEnvironment.java:62)
at java.desktop/sun.awt.PlatformGraphicsInfo.createGE(PlatformGraphicsInfo.java:36)
at java.desktop/java.awt.GraphicsEnvironment$LocalGE.createGE(GraphicsEnvironment.java:103)
at java.desktop/java.awt.GraphicsEnvironment$LocalGE.(GraphicsEnvironment.java:88)
at java.desktop/java.awt.GraphicsEnvironment.getLocalGraphicsEnvironment(GraphicsEnvironment.java:116)
at java.desktop/sun.awt.X11.XToolkit.(XToolkit.java:514)
at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:40)
at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:599)
at com.intellij.idea.StartupUtil$initAwtToolkit$1$1.invokeSuspend(StartupUtil.kt:424)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.scheduling.CoroutineScheduler.runSafely(CoroutineScheduler.kt:570)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.executeTask(CoroutineScheduler.kt:750)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.runWorker(CoroutineScheduler.kt:677)
at kotlinx.coroutines.scheduling.CoroutineScheduler$Worker.run(CoroutineScheduler.kt:664)
Suppressed: java.lang.NoClassDefFoundError: Could not initialize class sun.awt.X11.XToolkit
at java.desktop/sun.awt.PlatformGraphicsInfo.createToolkit(PlatformGraphicsInfo.java:40)
at java.desktop/java.awt.Toolkit.getDefaultToolkit(Toolkit.java:599)
at java.desktop/java.awt.Toolkit.getEventQueue(Toolkit.java:1498)
at java.desktop/java.awt.EventQueue.isDispatchThread(EventQueue.java:1103)
at java.desktop/javax.swing.SwingUtilities.isEventDispatchThread(SwingUtilities.java:1493)
at java.desktop/javax.swing.text.StyleContext.reclaim(StyleContext.java:473)
at java.desktop/javax.swing.text.StyleContext.addAttribute(StyleContext.java:330)
at java.desktop/javax.swing.text.html.StyleSheet.addAttribute(StyleSheet.java:607)
at java.desktop/javax.swing.text.StyleContext$NamedStyle.addAttribute(StyleContext.java:1558)
at java.desktop/javax.swing.text.StyleContext$NamedStyle.setName(StyleContext.java:1368)
at java.desktop/javax.swing.text.StyleContext$NamedStyle.(StyleContext.java:1315)
at java.desktop/javax.swing.text.StyleContext.addStyle(StyleContext.java:125)
at java.desktop/javax.swing.text.StyleContext.(StyleContext.java:105)
at java.desktop/javax.swing.text.html.StyleSheet.(StyleSheet.java:167)
at com.intellij.ide.ui.html.GlobalStyleSheetHolder.(GlobalStyleSheetHolder.kt:34)
at java.base/java.lang.Class.forName0(Native Method)
at java.base/java.lang.Class.forName(Class.java:467)
at com.intellij.idea.StartupUtil$preloadLafClasses$1.invokeSuspend(StartupUtil.kt:523)
at kotlin.coroutines.jvm.internal.BaseContinuationImpl.resumeWith(ContinuationImpl.kt:33)
at kotlinx.coroutines.DispatchedTask.run(DispatchedTask.kt:106)
at kotlinx.coroutines.internal.LimitedDispatcher.run(LimitedDispatcher.kt:42)
at kotlinx.coroutines.scheduling.TaskImpl.run(Tasks.kt:95)
… 4 more


Your JRE: 17.0.6+10-b829.9 amd64 (JetBrains s.r.o.)
/opt/idea-IU-231.9011.34/jbr
`

I tried to run other apps as root like nautilus with following command
sudo nautilus but I received
`** (org.gnome.Nautilus:11509): WARNING **: 13:10:08.024: Error on getting connection: Failed to load SPARQL backend: Error spawning command line ?dbus-launch –autolaunch=a4ecd6e0b63d4eb2b78a1a4f9c470d3c –binary-syntax –close-stderr?: Child process exited with code 1
No protocol specified
Unable to init server: Could not connect: Connection refused

(org.gnome.Nautilus:11509): Gtk-WARNING **: 13:10:08.046: cannot open display: :10.0
`

when I run both applications as normal user and without sudo, they run correctly but with sudo they fail, could anyone help?

2

Answers


  1. Chosen as BEST ANSWER

    After many Googling and try and error I found the answer:

    The problem will be resolved with installing and configuring the xauth package on your system. This package provides a mechanism for managing authentication credentials (known as “cookies”) used by the X11 server to determine whether a client is authorized to connect to the server. The steps are as below:

    1- Install xauth by running the command sudo apt-get install xauth in the terminal

    2- Run the xhost + command in the terminal to temporarily disable access control and allow clients to connect to the X11 server from any host.

    3- Run IntelliJ IDEA as root with the sudo command again like sudo /opt/idea2023/bin/idea.sh

    4- For Nautilus you can run sudo nautilus in terminal.

    5- Enjoy:)


  2. The issue you’re experiencing is related to running graphical applications, such as IntelliJ IDEA and Nautilus, with root privileges. By default, the X server (responsible for handling graphical display) does not allow connections from the root user for security reasons.
    So you have to figure out how to run graphical applications with root privileges.

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search