So at my job I SSH from my CentOS machine to other local CentOS machines. We use an application that runs in both X11 and terminal. Some features are available exclusively in terminal and other features are exclusively in X11. The program auto detects if there is a X display to connect to and will use it if available. It would be nice to be able to quickly toggle between the two version of the application without having to put in an enhancement request. We have a large amount of desktop icons/short cuts without a -X or -Y flag. Is there any way to enable/disable X11 forwarding on a running SSH session that was started without the -X or -Y flag?


If you run with -X or -Y then this will set $DISPLAY on the remote end to point to the X-tunnel. Unsetting $DISPLAY will prevent X applications from talking to the X server. e.g.

$ echo $DISPLAY 

$ xdpyinfo | head -2
name of display:    localhost:10.0
version number:    11.0

$ DISPLAY= xdpyinfo | head -2
xdpyinfo:  unable to open display "".

$ DISPLAY= xterm
xterm: Xt error: Can't open display: 
xterm: DISPLAY is not set

So with X tunneling enabled you should be able to "hide" it by unsetting $DISPLAY.

Inside an SSH session you can type ~? to get a list of changes you can make. You can add/remove port forwarding via ~C but you can't easily change X tunneling because that would require running xauth and similar. The sequence of events would be to forwarding a remote port back to localhost:6000 (or whatever port your local X server is on), setting DISPLAY and adding xauth permissions - not so easy!

|improve this answer|||||

When you need to run the application without X11, try: export DISPLAY=''

and with X11 leave DISPLAY as it is.

|improve this answer|||||

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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