Ssh – how to run gnome-terminal on remote centos 7 machine

gnomeremote-accessssh

My local machine is linux mint, and remote one is centos 7.
I try to open gnome-terminal on remote machine with x-forwarding, and its not working.

When I connect to host in interactive mode

$ ssh -Y centos-host

Then in opened session I can run gnome-terminal and x-forwarding working

$ gnome-terminal 
$ netstat -nltp
Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -
tcp        0      0 127.0.0.1:6010          0.0.0.0:*               LISTEN      -  

However when I try yo run

$ ssh -Y centos-host gnome-terminal

The window with gnome terminal opened, but no tunnel for X created.

Proto Recv-Q Send-Q Local Address           Foreign Address         State       PID/Program name 
tcp        0      0 0.0.0.0:22              0.0.0.0:*               LISTEN      -

I have an another linux mint remote machine, and not experienced such problem with it. So, I think something wrong with centos 7.

Please, help.
Thank you.

Best Answer

The reason is that gnome-terminal forks itself into the background. If you run it in your interactive ssh session, you will notice that you get a new command prompt even though the terminal is still open. In the non-interactive case, as soon as this happens, ssh will think the command has terminated and closes the session, including closing the listening X11 socket on the server. Since there are still active X11 connections, ssh doesn't exit immediately, which is why it looks as if the session is still active, however no new X11 connections can be opened.

You used to be able to do this by using gnome-terminal --disable-factory, however this has unfortunately been removed from gnome-terminal at some point. You have two options now:

  • Use another terminal program that doesn't fork into the background, for example xterm
  • Directly after starting gnome-terminal, in the same ssh session run a command that doesn't terminate, for example ssh -Y server 'gnome-terminal; echo Press enter to exit; read'