Last Updated on 2021-02-10 by Clay
Introduction
When we using terminal to connect remote server, we can open the remote GUI program on the local device via some simple configures.
So, let's start to go to the topic and simply record my experience in this test! (Note: this test is only successful as Linux to Linux)
ssh -Y parameter
We always using the following command to connect to the remote server:
ssh user@server_ip
And then, if we want to open a GUI program like a file manager or you call it a "folder", we can key in "nautilus" in terminal:
nautilus
Output:
Unable to init server: Could not connect: Connection refused
(nautilus:18395): Gtk-WARNING **: 23:31:36.729: cannot open display:
I thought this was impossible or it may be had some complicated settings or packages ... in before.
X Window has a network transmission protocol. This means that as long as we can configure it, and then our local device should be able to draw the window of the GUI software.
So, when you want to draw (open) a graphic interface, the system will automatically look for a environment variable named "DISPLAY".
First, we can look at the DISPLAY variable on the local side.
echo $DISPLAY
Output:
:0
As we can see, in the local device it always display ":0".
If we in the remote server and use the same command?
echo $DISPLAY
Output:
Yes, we can see nothing. This environment variable usually configure by the system of our desktop manager. For example: GDM.
So, how should we present the GUI software of the remote server on the local side? If face, we can add a parameters to the connection command when we connecting.
ssh -Y user@server_ip
After the connection is in, let's take a look at the current DISPLAY variable
echo $DISPLAY
Output:
localhost:10.0
If "localhost:10.0" is printed successfully, it means the setting is successful! If it is not printed, you can go to /etc/ssh/sshd_config and set "X11Forwarding" to "yes".
Now that everything is set, let's test the effect! This time, enter the following command on the remote terminal again:
nautilus
Output:
Succeeded! In this way, we can open the remote program on the local side! However, it should be noted that since it is transmitted through the network, the software response is not so immediate, which is a pity.