Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to enable X11 forwarding in PyCharm SSH session?

The Question

I'm trying to enable X11 forwarding through the PyCharm SSH Terminal which can be executed via

"Tools -> Start SSH session..." 

Unfortunately, It seems there is no way of specifying the flags like I would do in my shell for enabling the X11 Forwarding:

ssh -X user@remotehost 

Do you know some clever way of achieving this?


Current dirty solution

The only dirty hack I found is to open an external ssh connection with X11 forwarding and than manually update the environment variable DISPLAY.

For example I can run on my external ssh session:

vincenzo@remotehost:$ echo $DISPLAY localhost:10.0 

And than set on my PyCharm terminal:

export DISPLAY=localhost:10.0 

or update the DISPLAY variable in the Run/Debug Configuration, if I want to run the program from the GUI.

However, I really don't like this solution of using an external ssh terminal and manually update the DISPLAY variable and I'm sure there's a better way of achieving this!

Any help would be much appreciated.


P.s. Making an alias like:

alias ssh='ssh -X' 

in my .bashrc doesn't force PyCharm to enable X11 forwarding.

like image 435
Gengiolo Avatar asked Jan 27 '17 10:01

Gengiolo


People also ask

How do I enable X11 forwarding with SSH?

Go to Connection, select SSH, and then click Then, click on Browse to select the private key generated earlier If you are using key based authentication. Go to Connection, select SSH, and then click on Then, select enable X11 forwarding.

How do I use X11 MobaXterm forwarding over SSH?

MobaXterm: X11 is automatically enabled. Secure CRT: Right-click a saved connection, and select "Properties". Expand the "Connection" settings, then go to "Port Forwarding" -> "Remote/X11". Check "Forward X11 packets" and click "OK".

What is X11 forwarding in SSH?

X11 forwarding is a mechanism that allows a user to start up remote applications, and then forward the application display to their local Windows machine. It enables you to run GUIs from a local server. It's essentially remote desktop software that looks better on your screen and is easier to work with.

How do I start an SSH session in PyCharm?

Launch the SSH TerminalFrom the main menu, choose Tools | Start SSH Session. Alternatively, invoke the Help | Find Action Ctrl+Shift+A dialog, search for start ssh.., and select Start SSH Session.


1 Answers

So I was able to patch up jsch and test this out and it worked great.

Using X11 forwarding

You will need to do the following to use X11 forwarding in PyCharm:
- Install an X Server if you don't already have one. On Windows this might be the VcXsrv project, on Mac OS X the XQuartz project.
- Download or compile the jsch package. See instructions for compilation below.
- Backup jsch-0.1.54.jar in your pycharm's lib folder and replace it with the patched version. Start Pycharm with a remote environment and make sure to remove any instances of the DISPLAY environment variable you might have set in the run/debug configuration.

Compilation

Here is what you need to do on a Mac OS or Linux system with Maven installed.

wget http://sourceforge.net/projects/jsch/files/jsch/0.1.54/jsch-0.1.54.zip/download unzip download cd jsch-0.1.54 sed -e 's|x11_forwarding=false|x11_forwarding=true|g' -e 's|xforwading=false|xforwading=true|g' -i src/main/java/com/jcraft/jsch/*.java sed -e 's|<version>0.1.53</version>|<version>0.1.54</version>|g' -i pom.xml mvn clean package 

This will create jsch-0.1.54.jar in target folder.

X11 Enabled

like image 112
Tarun Lalwani Avatar answered Sep 22 '22 11:09

Tarun Lalwani