Solution for „Error: Can’t open display: (null)“ on Linux!
02/17/2023 (957x read)
No protocol specified
Error: Can’t open display: (null)
Failed creating new xdo instance
If you’re using a Linux system, you might encounter this error message: „No protocol specified – Error: Can’t open display“. This might occur when trying to start a graphical application. The error indicates that you are unable to access the X server, which is responsible for displaying graphical content. In our example, we try to run the xdotool.
There are several steps you can take to fix this error:
- Check the DISPLAY variable: The first thing to check is the value of the DISPLAY variable, which tells applications where to display an output. Open a terminal and type „echo $DISPLAY“ to check if the variable is set correctly. If the value is blank or incorrect, set it to „:0.0“ by typing „export DISPLAY=:0.0“.
- Check X server permissions: If the DISPLAY variable is set correctly and you’re still seeing the error, it could be due to insufficient permissions for the X server. To fix this, run the command „xhost +local:“ to grant access to all local users.
- Check firewall settings: If you’re still unable to access the X server, it could be due to firewall settings blocking the connection. Make sure that the firewall is not blocking the X server port (port 6000).
Export the display
Another solution, if running the app in a script, is to try to export the display by entering these lines:
export DISPLAY=":0" export XAUTHORITY=/home/pi/.Xauthority
Our xdotool example, which shall refresh the firefox browser via an SSH connection, would look like this:
#!/bin/bash export DISPLAY=":0" export XAUTHORITY=/home/pi/.Xauthority xdotool getactivewindow xdotool key F5
Running the script with sudo permissions should help to get rid of the „Can’t open display: (null)“ error:
sudo sh firefox-reload.sh