I am trying to run gedit
from an SSH terminal on Windows, connected to an Amazon EC2 instance running Ubuntu 12.04 Server and I am getting this error:
Cannot open display:
How do I fix it?
I am trying to run gedit
from an SSH terminal on Windows, connected to an Amazon EC2 instance running Ubuntu 12.04 Server and I am getting this error:
Cannot open display:
How do I fix it?
So you are connecting from your home pc (let's call it your machine) to a server (let's call it server) via ssh? You want to start a program with a graphical window on the server via your machine? If that is correct than by all means read on.
Let's call the program to start
gedit
but the process is the same for all. Depending on where you want to see the graphical window skip to the right heading.Window on your machine's screen
If you want to see and use gedit's window on your remote machine but start in on the server, you will want your shell session to look like this:
Don't mind the warnings, they are normal - the gedit window will pop up on your remote machine's screen like it would look on the server. The trick is to use the "-X"-option as in
ssh -X
which enables X-tunnelling and sets theDISPLAY
variable right.This assumes that you're using an SSH client that supports X11 and that your server has an X-server running (some without a need for GUIs don't run an X-server). Especially on windows this might be an issue as most windows terminal programs don't have X. As izx stated the MobaXTerm is one of the many SSH clients for windows that has an X-Server though.
For a server lacking X11 however, you'd have to install it.
On the server's screen
You can also start an instance on the screen of your server by calling gedit like this:
You have to substitute the right value instead of
:0.0
though to get it on the right X-screen (only important if multiple screens are connected to your server or if it's somewhat peculiar in its configuration).Here the most common scenario for that not to work would be if the Server lacked an X11-Server but than it wouldn't have a monitor connected to it or have no graphical user interface and you'd not be reading this :D.
A bit of theory
I'm no expert in this, but the way I think it works is, that each physical screen, i.e. each monitor connected to an individual computer gets a running number in the form of
0.0
,1.0
,2.0
,...This number is assigned by the X-Window-System aka X11. That is a layer to provide a network and basic graphical interface that Unity, Gnome, KDE and the like can build upon.
You can see how many displays a given machine has and what numbers are in use by running
for x in /tmp/.X11-unix/X*; do echo ":${x##*X}"; done
on the machine in question.* Then each computer that is configured to make its screens available and runs an X server has a hostname. You can use a hosts screens from any machine in the same network by setting yourDISPLAY
variable accordingly toDISPLAY=hostname:0.0
. Ssh does this for you in a sensible way if you provide the-X
option.*Note: I suppose there is a better way than this for-loop.
If all else fails
Use a shell text editor.
vi
,vim
,nano
andemacs
are the most common and at least one of them will be installed and operational. Of themnano
is the easiest and most self explanatory.Since you are using Windows on your side, you will need an SSH-client that runs a local X server on Windows to run graphical applications from the server remotely on your screen.
From experience, I would recommend the free MobaXTerm which has this functionality built-in. Please download it and give it a try:
If you get any errors, that's because sometimes a minimal server image may not be set up to allow X-forwarding into it. In that case, please comment and I'll help you solve it; I've done this with lots of minimal VPSs running Ubuntu/Debian.
What con-f-use said.
Basically you have a terminal through SSH and Gedit is a GUI program. con-f-use's answer will make it work from a Linux GUI client session.
The other option would be to use a non GUI editor like nano, Vi or numerous others.
Well, I had this issue of being unable to use X forward on my vagrant instance. Solution for that was pretty straight forward. Simply install the
xauth
package. If it still doesn't works then the solution is to enable X11Forwarding and related settings in the respective/etc/ssh/ssh_config
and /etc/ssh/sshd_config` These are the only issues that usually need fixing in terms of X forwarding.Also, one of the most crucial method to fixing the ssh related issues is to use
ssh -v
the verbose logging allows you to see what is going on.