Take the 2-minute tour ×
Ask Ubuntu is a question and answer site for Ubuntu users and developers. It's 100% free, no registration required.

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?

share|improve this question
add comment

3 Answers 3

up vote 9 down vote accepted

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:

enter image description here

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.

share|improve this answer
add comment

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 geidt 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:

user@remote-machine:~$ ssh -X user@server
Last login: Tue Aug 14 13:47:04 2012 from clientXX
*******************************************************************************
M O T D (Message Of The Day)
*******************************************************************************
user@server:~$ gedit .bash_aliases 

** (gedit:7851): WARNING **: Could not load theme icon gtk-home: Icon 'gtk-home' not present in theme

(gedit:7851): Gtk-WARNING **: Attempting to store changes 

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 the DISPLAY 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:

ssh user@server
DISPLAY=:0.0 gedit

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 your DISPLAY variable accordingly to DISPLAY=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 shall text editor. vi, vim, nano and emacs are the most common and at least one of them will be installed and operational. Of them nano is the easiest and most self explanatory.

share|improve this answer
    
@all: Feel free to correct me if I got anything wrong. –  con-f-use Aug 14 '12 at 12:17
    
@coding crow: If you're SSHing from Windows it depends on the client whether or not that will work. Some clients don't communicate with X11 and thus no X-forwarding - for some though it just works fine. If not working change the SSH client for Windows or use nano, vim or emacs as xyious suggested in his answer. –  con-f-use Aug 14 '12 at 12:19
    
Yes I got a down vote, saw it in my profile and wondered why there is no comment or anything. Not so important didn't have to do with you, just wondered - glad you problem is solved and I could be of a little help here. –  con-f-use Aug 14 '12 at 14:27
add comment

What con-f-use said.
Basically you have a terminal through ssh and gedit is a GUI program. What con-f-use said 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.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.