Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Enhancement: SSH Terminal to folder #26

Closed
Elektrolott opened this issue Jul 13, 2018 · 36 comments
Closed

Enhancement: SSH Terminal to folder #26

Elektrolott opened this issue Jul 13, 2018 · 36 comments
Labels
enhancement New feature or request

Comments

@Elektrolott
Copy link

It would be great if the extension could provide a SSH Terminal window for a configured remote directory.

@SchoofsKelvin
Copy link
Owner

That's something I'm planning on doing quite soon.

It's a little bit of a challenge, as the extension API requires me to spawn a process, e.g. the ssh or plink programs. As I have to assume not everyone has ssh/PuTTY installed and on their path, and have it be compatible with all the config options, I'll most likely have to write a simple (proxy) program to either proxy the connection to the extension, or start the SSH connection itself.

The requirement to have a custom program, while assuming node/ssh/plink isn't available, seems like the biggest challenge here. It's definitely something I'm planning on finishing soon.

@SchoofsKelvin SchoofsKelvin added the enhancement New feature or request label Jul 13, 2018
@Elektrolott
Copy link
Author

Great!
I'm looking forward to that :)

@SchoofsKelvin
Copy link
Owner

Probably gonna wait until the TerminalRenderer API (microsoft/vscode#52833) is released, or at least more finalized, as using this seems a much better approach than creating a program/process.

@nunure
Copy link

nunure commented Oct 17, 2018

It's a little bit of a challenge, as the extension API requires me to spawn a process, e.g. the ssh or plink programs. As I have to assume not everyone has ssh/PuTTY installed and on their path, and have it be compatible with all the config options, I'll most likely have to write a simple (proxy) program to either proxy the connection to the extension, or start the SSH connection itself.

Well, my function assume that you have an ssh client install on your computer.

@WSLUser
Copy link

WSLUser commented Oct 17, 2018

Any way of making use of the SSHTerminal extension? Maybe combining the two together?

@nunure
Copy link

nunure commented Oct 18, 2018

I tried to use the SSHTerminal extension, but the issue is that you need to configure SSHTerminal as weel with your credentials. I have plenty of configurations and maintain a config for each extension is not possible.

The function I wrote use the same method as SSHTerminal Extension, it is simply writing in the VSCode default terminal, "ssh hostname -l username and some other params if necessary".

Moreover, It allow you to open a terminal using the same method as opening a workspace with SSH FS, right click and choose the action you want. With SSHTerminal you couldn't do that.

@SchoofsKelvin
Copy link
Owner

Feedback added to your pull request (#61)

Short version: The requirement of having ssh available (along with "breaking" some config options, e.g. proxying) makes me not wanna merge it, at least not right away. Also, I'm hoping that the new TerminalProvider API will be released in vscode, which would help with this a lot.

@WSLUser
Copy link

WSLUser commented Oct 19, 2018

So for Win 10, ssh.exe does exist by default thanks to OpenSSH being ported though that is still a WIP, but works well enough on it's own minus some edge cases of course. But for previous versions of Windows, you'll need to install manually from the project download page. If you want to automate that installation somehow if they aren't running Win 10 that would be helpful. if they are running win 10 then it's simply a matter of enabling the feature and running updates.

@nunure
Copy link

nunure commented Oct 19, 2018

In my case I do not have ssh install on my computer. I use git bash that does the work pretty well.

@WSLUser
Copy link

WSLUser commented Oct 19, 2018

That is an acceptable workaround. I'll eventually need to get it...but sometimes I need to ssh without the use of git for other purposes (i have a multi-purpose role) so a MS solution for ssh is preferred as it doesn't have any dependencies other than running a .ps1 to install.

@SchoofsKelvin
Copy link
Owner

I'm running Windows 10 but don't have OpenSSH (or any ssh.exe I can find). The only thing related that I have are plink (from PuTTY) and WinSCP.

Right now, with the extension supporting PuTTY sessions, it's easy to use those for the extension, while also allowing you to open a terminal and run plink "Session name as configured in PuTTY", which, unless you have annoying session names, is quite quickly and painless.

@WSLUser
Copy link

WSLUser commented Oct 19, 2018

Ok so not all versions of Windows 10 have it but you can install under Features and Components. you'll find it isn't far from the WSL feature. But if you're running a version of Win 10 that doesn't have the enabling feature, same steps apply as other windows versions for installing openssh. Recommend the latest build if possible as it's first appearance as beta was in 16299 I believe. There are steps to update from what's passed into the kernel for installing as a feature that apply to all windows OS's without having to download again. https://github.com/PowerShell/Win32-OpenSSH/wiki/How-to-retrieve-links-to-latest-packages

@SchoofsKelvin
Copy link
Owner

I don't have that feature available yet, but a quick search uncovered that I require the April 2018 update, which I haven't installed yet. But again, it's unlikely people can use this and have it enabled. I'm looking forward to TerminalProvider, which would be a solid solution that makes implementing this enhancement (for all systems) possible.

@WSLUser
Copy link

WSLUser commented Oct 19, 2018

Using the latest PSCore 6.1 (because it's better than Win-PS for 7), navigating to the directory that ssh.exe lives in, I successfully managed to use ssh to my Linux box and view my project. Time to get rid of that sshterminal extension.

@Morgy93
Copy link

Morgy93 commented Nov 9, 2018

Is it somehow possible to pass config values to the terminal?

I'd like to run something like: wlinux run "ssh {username}@{host}" or bash -c "ssh {username}@{host}"
So that the shell automatically connects to the server.

@Morgy93
Copy link

Morgy93 commented Nov 9, 2018

I just had another great idea.
Maybe you can add a context menu option like "Open in terminal" and then you send a customized command to the terminal for example bash -c "ssh -t {username}@{host} 'cd {path} ; bash'"
Maybe it's easier to grab the config values via context menu.

@WSLUser
Copy link

WSLUser commented Nov 9, 2018

@Morgy93 you actually want wsl.exe not bash -c or a specific distro binary such as wlinux. Bash -c is only needed in builds below 16299 (FCU). If you want usable wsl, you need 16299 at a minimum anyways (you really want the latest one for the most fixes and features).

@eugeneniemand
Copy link

Has there been any update on this?

@SchoofsKelvin
Copy link
Owner

Based on the milestones in microsoft/vscode#67923, the TerminalRenderer API won't be officially released before March, assuming the planned milestone doesn't change.

@sudoJoe
Copy link

sudoJoe commented Mar 18, 2019

I don't particular need this functionality (I arrived in this thread by mistake while looking for a solution to a different problem that I'm having) but I have an idea that seems simpler and easier to implement than what hasbeen suggested so far.

While I gather the original request is for spawning an external SSH Terminal window, if there are no objections to using the integrated terminal, you could simply shift focus to that and execute a call to ssh, piping the appropriate parameters from the SSH-FS config..?

I'm not sure how you store/access the configuration settings, but if it's in a json file on the local filesystem, you could import/require that file, read the ssh settings, and then call workbench.action.terminal.sendSequence("ssh " + args). Probably need to check if there is an active terminal and create one if there isn't. This assumes that ssh is present on the system and registered, but that should be the case for most people using SSH-FS. (For example, having OpenSSH installed on Windows 10 makes it available.)

@sudoJoe
Copy link

sudoJoe commented Mar 18, 2019

Just realized, since this is functionality being added to the SSH-FS extension, you probably already have the address, port, and security config loaded into the extension.

Also, it shouldn't be hard to spawn an external shell either.

@SchoofsKelvin
Copy link
Owner

Also, it shouldn't be hard to spawn an external shell either.

The problem isn't the SSH shell itself, as part of initiating the filesystem is creating a SFTP session over a SSH session. It's having it be rendered in the integrated terminal. Currently the extension API only allows creating terminals for external programs/shells. Remember that this has to be cross-platform, and not every computer, especially Windows ones, don't have the (same) ssh command available on path. I currently can't create a SSH connection and have it "render" in the integrated terminal. Not yet, at least (microsoft/vscode#67923)

@sudoJoe
Copy link

sudoJoe commented Mar 19, 2019

  • Hijacking an already running terminal like I suggested is out of the question?

  • "ssh" is available to you for the purpose of initiating the SFTP session.. oh, I think I see the problem now. I honestly had no clue how this extension works (though I'm using it with immense satisfaction now :) so my apologies for the ignorant comment.

I suppose you could try 'ssh' and just report to the user that it's missing from their path if it fails, but that would definitely be a sub-optimal workaround compared to what you're trying to achieve.

Again, sorry for sticking my nose into things without doing any research.

@SchoofsKelvin
Copy link
Owner

  • "ssh" is available to you for the purpose of initiating the SFTP session.. oh, I think I see the problem now. I honestly had no clue how this extension works (though I'm using it with immense satisfaction now :) so my apologies for the ignorant comment.

I suppose you could try 'ssh' and just report to the user that it's missing from their path if it fails, but that would definitely be a sub-optimal workaround compared to what you're trying to achieve.

Part of the problem is indeed it missing for some users. Another problem, although I doubt a less common one, is that some ssh installations might be missing certain command line parameters, or parse/handle them differently.

Another "issue" is that I'd want to use the ssh2 library I use for creating the SFTP session. For the SFTP session, I first also create a SSH session. Programming wise, it seems weird to use two different ways of starting SSH (library packed in the extension VS ssh on the local system), especially since that might lead to issues of SFTP working but not the SSH terminal, and the other way around.

Basically, it's better to wait until vscode adds an API that allows me to connect the ssh2 library I use to the terminal, without the need for an external program. And since they're already working on such a feature (microsoft/vscode#67923), it's definitely better to wait until that feature is released, instead of basically "hacking" this together using local ssh binaries, proxy programs, ...

@Morgy93
Copy link

Morgy93 commented Mar 20, 2019

I'd really love to have this configurable, to not get forced on something.
For the general purpose of this extension I don't really mind how it works, but the terminal / shell is something that users customize for their own experience and I'd love to stick with ssh inside my WSL.

@SchoofsKelvin
Copy link
Owner

Similar to how there is a sftpCommand (and sftpSudo to go along with it) option, I tried adding a sshCommand. This would, instead of starting the ssh connection using the library, open a shell, run the given command, and wrap it in a SSHStream. That last part doesn't work, which robs me of the ability to use channels, e.g. for multiple shells and also kind of SFTP.

While this is fine for just a terminal, it's difficult to implement and doesn't have much use. If it's just for a ssh terminal, you're better off manually running the command, or adding it as a task in vscode.

@Morgy93
Copy link

Morgy93 commented Mar 20, 2019

The task thingy looks interesting.
My only concern is that I'm running like 20 different ssh configurations and I can't remember all hosts and users (at least I'm using private key so I don't have to use passwords) so writing ssh user@host gives me a headache already.
Is it possible somehow to grab these values from the extension config? That's really all I would need.

@SchoofsKelvin
Copy link
Owner

I've quickly looked into providing command variables, e.g. allowing ${command:sshfs.get:config.host} or something similar.

After a bit of investigating, it seems like using "command": "${command:sshfs.get:config.host}" etc can be supported, but only if you're using one of these per task. Otherwise if you have two of them, I basically have no way of knowing which one is currently being parsed. Might be a "bug" in vscode.

What I could implement, is something like this:

{
    // See https://go.microsoft.com/fwlink/?LinkId=733558
    // for the documentation about the tasks.json format
    "version": "2.0.0",
    "tasks": [
        {
            "label": "ssh",
            "type": "shell",
            "command": "ssh ${input:username}:${input:host}",
            "group": {
                "kind": "build",
                "isDefault": true
            }
        }
    ],
    "inputs": [
        {
            "type": "command",
            "command": "sshfs.echo",
            "id": "username",
            "args": {
                "field": "username"
            }
        },
        {
            "type": "command",
            "command": "sshfs.echo",
            "id": "host",
            "args": {
                "field": "host"
            }
        }
    ]
}

Alternatively, I could do something like "command": "ssh ${command:sshfs.parse:%config.username%@%config.host%} -c echo 'test'" or similar, so you only have to use a single commad:sshfs.parse, solving the problem of not being able to distinguish several ones.

Basically, there just isn't an easy way to implement this.


If you're on Windows and are using PuTTY, you can use a ssh fs config with "putty": "sessionname" and just use plink @sessionname to start a SSH shell, without having to copy your PuTTY config into vscode. If you're not on Windows, or using OpenSSH or so, you'll have to wait until I implement #107 to be able to "easily" use that. Otherwise have a ssh config and "duplicate" vscode config.

Also, "command": "plink '${workspaceFolderBasename}'" (or with ssh) could be used, if your folder has the same name as your PuTTY (or SSH) session. Not really related to the extension, though.

@sudoJoe
Copy link

sudoJoe commented Mar 20, 2019

My other idea was to expose the extension's internal mechanism for creating ssh extensions as a callable, i.e. some function or command the user can simply execute from the terminal.

I looked through the extension API docs for a while though and didn't see anyway to do this. I was thinking something like how a npm module can be called from the command line.

@WSLUser
Copy link

WSLUser commented Jul 3, 2019

@SchoofsKelvin Aside from my note on the related PR, there's another new API that may be of interest that we may need or want: microsoft/vscode#75455 which implements a Shell API. To get idea of how it should look, the python extension is already done most of the work on getting it implemented on their end: microsoft/vscode-python#6403

@rdvo
Copy link

rdvo commented Sep 19, 2019

any updates on this? I love how i can edit a remote file but if i want to run it in the terminal its not the remote server its my local

@Morgy93
Copy link

Morgy93 commented Sep 19, 2019

I really honor the work of @SchoofsKelvin here, but basically this extension is now obsolete because of an extension by Microsoft itself:

https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.vscode-remote-extensionpack

https://github.com/Microsoft/vscode-remote-release

I thinks it's fair to "advertise" here since it's done by Microsoft itself and we're all a friendly and forward thinking open source community.
However, big thanks again to @SchoofsKelvin for his awesome work!

@WSLUser
Copy link

WSLUser commented Sep 19, 2019

we're all a friendly and forward thinking open source community

Indeed, and you do realize that the remote ssh extension is NOT open source. So an open source alternative would be preferable for many. The terminal is part of this but the major drawback is the remote-ssh extension does allow other extensions to be installed onto the remote host so they can be used. This is not currently possible with this extension. Still should be possible to get the extensions to work in an open-source implementation. We just need someone willing to contribute other than @SchoofsKelvin .

@WiFiUncle
Copy link

any updates on SSH Terminal ?

@foxfabi foxfabi mentioned this issue Jun 17, 2020
@SchoofsKelvin
Copy link
Owner

Terminal got added in v1.18.0 (dea6a03...e8ffe0e)

I've made use of vscode's new PseudoTerminal API to allow creating terminals that directly make use of the existing connection algorithms. If your configuration works for file systems, it should work for terminals too. No extra hassle.

The new feature still lacks a few quality of live improvements. Opening a terminal will use the user's home directory as working directory, similar to what would happen if you connected to a server directly over ssh. In the future, I might add the "Right click folder in explorer > Open remote terminal" feature, along with that opening a terminal for a host should actually set the working directory to its root directory.

@SchoofsKelvin
Copy link
Owner

Added in ffef5c6, soon available in v1.18.1 of the extension:

  • SSH FS view has a context menu item "Open a remote SSH terminal" that opens a shell at root on the host
  • Explorer view has the same menu item for directories in ssh:// file systems (replacing the missing built-in "Open in terminal")

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

9 participants