joelspadin / vscode-remote-x11

Visual Studio Code extension that sets the DISPLAY environment variable in remote workspaces
39 stars 9 forks source link

Support password-protected private keys #4

Closed sleighsoft closed 4 years ago

sleighsoft commented 4 years ago

This really sounds like something I am in dire need right now.

Sadly, I do not seem to understand how to set it up properly.

My use case is showing a matplotlib output window, by using plt.show(). The python file is run through the VSCode Terminal that open up when I connect to the server with Remote - SSH.

I would really appreciate your help :)

joelspadin commented 4 years ago

You need to be running an X server on your local machine. If you're using Windows, https://sourceforge.net/projects/vcxsrv/ works well. Once you have the server running, you can test it independently of VS Code by doing something like the following:

  1. Open a terminal (CMD or PowerShell work on Windows) and run

    ssh -X user@hostname

    using the same user and hostname or IP address that you use with the Remote - SSH extension in VS Code. If you're using Windows and it can't find ssh, use C:\Windows\System32\OpenSSH\ssh.exe -X user@hostname instead.

  2. Once you're logged into the other machine with SSH, check that the DISPLAY variable is set properly:

    echo $DISPLAY

    this should print out something like "localhost:10.0".

  3. Finally, run a GUI program from the SSH shell:

    xclock

    If everything is working correctly, you should see a small clock window appear. If not, you'll need to troubleshoot your X windows setup.

If things work normally but not when going through VS Code, then there could be an issue with my extension. Check VS Code's "Output" panel and check if the logs for "Remote X11" or "Remote X11: SSH" show anything useful.

sleighsoft commented 4 years ago

Thank you very much for your detailed answer @ChaosinaCan.

Unfortunately I still have some questions:

I did manage to make the Putty approach working. So it definitely works.

I'll let you know if I run into any more problems.

Thanks again!

joelspadin commented 4 years ago

I am using PowerShell 7 currently, but I don't think that matters. Support for -X would be determined by the version of SSH you're using.

This extension uses its own version of SSH implemented in JavaScript, so -X should always be supported. If it works with PuTTY, it should be possible to get it to work using my extension. Logs from the output panel might help figure out why it's not working.

sleighsoft commented 4 years ago

It does not set $DISPLAY

This is the output I observe: Remote X11 (SSH) - Here it uses user@ip

Connecting to user@ip port 22

Remote X11 - Here it uses user@host where host is the literal 'host'

Setting up display for remote "ssh-remote".
Connecting to SSH user@host 22

This seems to be the relevant log. I connect to the Remote VSCode instance with ssh remote where remote is an entry in my .ssh/config.

Somehow your extension uses the name of this config entry to construct the path C:\Users\User\.ssh\remote which does not exist.

Log (Remote Extension)

 [exthost] [error] Activating extension spadin.remote-x11 failed due to an error:
 [exthost] [error] Error: ENOENT: no such file or directory, open 'C:\Users\User\.ssh\remote'

Edit:

Ok I found out that the key file can be specified in the settings which fixes the Log (Remote Extension) issue in parts. Now the problem is, that it does not prompt me for a password (the privatekey is secured with a password).

Wouldn't it be possible, that your extension uses the ssh credentials already used by VSCode?

joelspadin commented 4 years ago

Somehow your extension uses the name of this config entry to construct the path C:\Users\User.ssh\remote which does not exist.

I have no idea what could be causing that unless you set your remoteX11.SSH.privateKey setting to that. If the setting isn't set, it uses ~/.ssh/id_rsa: https://github.com/ChaosinaCan/vscode-remote-x11/blob/master/ssh/src/extension.ts#L40

Now the problem is, that it does not prompt me for a password (the privatekey is secured with a password). Wouldn't it be possible, that your extension uses the ssh credentials already used by VSCode?

I haven't been able to find any way to get those credentials, so unfortunately no. That is handled internally to the Remote - SSH extension, and Microsoft doesn't publish any API or even the source for that extension.

I could make my extension prompt you for your password separately. This isn't something I regularly use, so I don't know when I would get around to implementing it though. (Pull requests are welcome!)

sleighsoft commented 4 years ago

A password prompt would be much appreciated. Sadly, I am no JavaScript expert :/

joelspadin commented 4 years ago

@sleighsoft I just published version 1.3.0 which supports getting keys from ssh-agent. This method does support private keys. See the readme for more details on using it.

Let me know if that works for you, and please re-open this issue if it doesn't!

sleighsoft commented 4 years ago

Great addition, really improved the usefulness of this plug in!