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

Auto generate profile from .ssh/config #9031

Closed
hanxi opened this issue Feb 4, 2021 · 16 comments · Fixed by #14042
Closed

Auto generate profile from .ssh/config #9031

hanxi opened this issue Feb 4, 2021 · 16 comments · Fixed by #14042
Labels
Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.

Comments

@hanxi
Copy link

hanxi commented Feb 4, 2021

Description of the new feature/enhancement

Dynamic profiles like "Windows.Terminal.Wsl", "Windows.Terminal.Azure", "Windows.Terminal.PowershellCore"

eg:

If .ssh/config like this:

Host 251
    HostName 192.168.29.251
    Port 22
    User hanxi
Host 252
    HostName 192.168.29.252
    Port 22
    User hanxi

Then generate profile like this:

  {
      "guid": "{a060905f-d089-43d9-9422-cd748e7f0230}",
      "name": "ssh251",
      "commandline": "powershell.exe ssh 251",
      "closeOnExit" : true
  }
  {
      "guid": "{a060905f-d089-43d9-9422-cd748e7f0231}",
      "name": "ssh252",
      "commandline": "powershell.exe ssh 252",
      "closeOnExit" : true
  }

Proposed technical implementation details (optional)

Also support disabledProfileSources setting.

"disabledProfileSources": ["Windows.Terminal.Wsl", "Windows.Terminal.Azure", "Windows.Terminal.PowershellCore", "Windows.Terminal.SSH"]

If OpenSSH not installed, then auto disable "Windows.Terminal.SSH" .

@hanxi hanxi added the Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. label Feb 4, 2021
@ghost ghost added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting Needs-Tag-Fix Doesn't match tag requirements labels Feb 4, 2021
@zadjii-msft
Copy link
Member

I don't hate this. What I'm most worried about is the full path to .ssh/config - how consistent is that across various different methods of installing ssh? I'm worried that there's different paths for the built-in ssh, vs the version you'd get from the win32-openssh github repo, vs the one you'd install from winget, vs the one from scoop, vs chocolatey, vs git bash.... and now the logic gets way funkier.

That being said, I could be entirely wrong and it might just be a static path. That would certainly make this easier.

@zadjii-msft zadjii-msft added Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Product-Terminal The new Windows Terminal. labels Feb 4, 2021
@ghost ghost removed the Needs-Tag-Fix Doesn't match tag requirements label Feb 4, 2021
@zadjii-msft zadjii-msft added this to the Terminal Backlog milestone Feb 4, 2021
@hanxi
Copy link
Author

hanxi commented Feb 5, 2021

@zadjii-msft I test this ssh version use .ssh/config from %HOMEPATH%/.ssh/config

  • built-in ssh
  • win32-openssh github repo
  • winget no openssh
  • scoop install failed
  • chocolatey install failed
  • git bash

So I think .ssh/config is a static path.

@skyline75489
Copy link
Collaborator

Do we still accept new profile generators? I thought we have moved pass that period. That being said I don't hate the idea, either. Also I'd love to see #7774 landed.

@zadjii-msft
Copy link
Member

I'm thinking that this is one of those cases where a proto-extension actually won't work super well. They've got their config in this file already, but then would need to add another service to watch that file for changes. That's the only way I could imagine changes to that file being automatically picked up and turned into new profiles. Plus, I really doubt ssh as a project would ship anything like a proto-extension.

So this one seems simple enough, and with win32-openssh being shipped in-box, it's first-party enough. I'll bring it up in team discussion Monday, but this seems like a good idea to me.

@skyline75489
Copy link
Collaborator

skyline75489 commented Feb 7, 2021

@zadjii-msft I'd argue Visual Studio is also first- party. But generally I see what you mean.

@zadjii-msft
Copy link
Member

@skyline75489 VS definitely is first party, which is why we're gonna try and get that PR merged this month 😉

@DHowett DHowett removed the Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting label Feb 12, 2021
@DHowett
Copy link
Member

DHowett commented Feb 12, 2021

This will be an excellent first-party extension. I'm hesitant to do it as a built-in generator (since I don't think we need more of those), but it can come in soon after.

@DHowett DHowett added Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting and removed Needs-Triage It's a new issue that the core contributor team needs to triage at the next triage meeting labels Feb 12, 2021
@DHowett

This comment has been minimized.

@DHowett

This comment has been minimized.

@mveril
Copy link

mveril commented Mar 3, 2021

Currently I mainly use ssh through WSL to connect me to servers. I use custom profiles for that.
It would be interesting to be able to choose if we want to generate profile for ssh from windows or from WSL.

@Kytech
Copy link

Kytech commented Apr 8, 2021

I also find myself adding SSH configs to my terminal profiles regularly. However, it could be nice to have a way to setup an includelist/excludelist since I have some configs that just alias some server addresses to a nicer name, but I would have an unusually long profile list if I couldn't opt-out/opt-in which profiles are displayed. That sort of mechanism may be useful for other profile generators as well in case people want to have even finer-grained control over them. I also have some ssh configs that "chain" options (ex. a profile that applies to all 10.0.1.* servers), so I wouldn't necessarily want those kind of configs to show up and a include/exclude list could help with that. Another alternative would be only adding profiles for ssh configs that have a HostName field.

Another thought on this: Since people may have a number of different openssh installs/install locations (as mentioned above), would this just default to using the openssh version in their PATH? That would make sense, though I know that some people may use the git bash/git-bundled ssh along with its agent, which reads from the same .ssh\config as the built-in OpenSSH, but don't share agent-held keys without some extra configuration since each of these SSH installs has its own agent. Those may want to point their profiles to the git-bundled ssh executable if they use the git-bundled ssh's agent. I'm thinking we could make those profiles take an alternate ssh executable path as the commandline config option, or we can have the feature stick to relying on whatever is in the PATH environment variable and document that behavior somewhere. It's easy enough to choose which ssh version you want by placing it higher up in the PATH list and it should work out of the box for most people since most default Windows installs will have some SSH executable in their path.

@hanxi
Copy link
Author

hanxi commented Apr 21, 2021

I found a plugin in vscode for ssh. It use .ssh/config file.

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

image

@OlafvdSpek
Copy link

  "commandline": "powershell.exe ssh 251",

For anyone trying this with MS PS, the cmd is pwsh -c ssh <host>

This feature would be nice to have.

@mrtnd
Copy link

mrtnd commented May 28, 2022

Plus 1 on that one. I would very much appreciate such feature! I use vscode and terminal pretty much every day for remote development etc. VSCode already uses the .ssh/config. Terminal doesn’t. Which means I need to maintain two different config files. Kinda inconvenient. How is the progress going btw?

@zadjii-msft
Copy link
Member

How is the progress going btw

There's no one currently working on this. If you'd like to contribute, I think we'd welcome the contribution.

There may be some continued debate as to whether this should be bundled with the application or supported as a "3rd party" extension. At the moment we don't really have a LoS on 3rd party extensions like this though. I'm in the camp of "probably okay to ship with the Terminal for now".

jonthysell added a commit to jonthysell/terminal that referenced this issue Sep 20, 2022
This PR looks for the presense of OpenSSH config files and creates
profiles from the hosts present.

CLoses microsoft#9031
jonthysell added a commit to jonthysell/terminal that referenced this issue Sep 20, 2022
This PR looks for the presense of OpenSSH config files and creates
profiles from the hosts present.

Closes microsoft#9031
jonthysell added a commit to jonthysell/terminal that referenced this issue Sep 20, 2022
This PR looks for the presence of OpenSSH config files and creates
profiles from the SSH hosts present.

Closes microsoft#9031
@ghost ghost added the In-PR This issue has a related PR label Sep 20, 2022
jonthysell added a commit to jonthysell/terminal that referenced this issue Sep 20, 2022
This PR adds a new `SshHostGenerator` inbox dynamic profile generator. When run, it looks for an install of our [Win32-OpenSSH](https://github.com/PowerShell/Win32-OpenSSH) client app `ssh.exe` in all of the (official) places it gets installed. If the exe is found, the generator then looks for and parses both the user and system OpenSSH config files for valid SSH hosts. Each host is then converted into a profiles to call `ssh.exe` and connect to those hosts.

Closes microsoft#9031
@ffes
Copy link

ffes commented Oct 5, 2022

I see that #14042 is opened to fix this. Great that someone put in the work!!!

But with over 20 hosts in my .ssh/config that is going to pollute my menu very much. I hope that my suggestion mentioned in #1571 (comment) gets solved before that PR lands.

@zadjii-msft zadjii-msft modified the milestones: Backlog, Terminal v1.17 Oct 26, 2022
zadjii-msft pushed a commit that referenced this issue Dec 9, 2022
)

This PR adds a new dynamic profile generator which creates profiles to
quickly connect to detected SSH hosts.

This PR adds a new `SshHostGenerator` inbox dynamic profile generator.
When run, it looks for an install of our
[Win32-OpenSSH](https://github.com/PowerShell/Win32-OpenSSH) client app
`ssh.exe` in all of the (official) places it gets installed. If the exe
is found, the generator then looks for and parses both the user and
system OpenSSH config files for valid SSH hosts. Each host is then
converted into a profiles to call `ssh.exe` and connect to those hosts.

VALIDATION
Installed OpenSSH, configured host for alt.org NetHack server, connected
and played some NetHack from the created profile.

* [x] When OpenSSH is not installed, don't add profiles
* [x] Detected when installed via Optional Features (installs in
  `System32\OpenSSH`, added to PATH)
* [x] Detected when installed via the 32-Bit OpenSSH MSI from GitHub
  (installs in `Program Files (x86)\OpenSSH`, not added to PATH)
* [x] Detected when installed via the 64-Bit OpenSSH MSI from GitHub
  (installs in `Program Files\OpenSSH`, not added to PATH)
* [x] Detected when installed via `winget install
  Microsoft.OpenSSH.Beta` (uses MSI from GitHub)
* [x] With `"disabledProfileSources": ["Windows.Terminal.SSH"]` the
  profiles are not generated

Closes #9031

Co-authored-by: Carlos Zamora <[email protected]>
Co-authored-by: Mike Griese <[email protected]>
Closes #9031
@ghost ghost added Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release. Needs-Tag-Fix Doesn't match tag requirements and removed In-PR This issue has a related PR labels Dec 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Area-Extensibility A feature that would ideally be fulfilled by us having an extension model. Area-Settings Issues related to settings and customizability, for console or terminal Issue-Feature Complex enough to require an in depth planning process and actual budgeted, scheduled work. Needs-Tag-Fix Doesn't match tag requirements Product-Terminal The new Windows Terminal. Resolution-Fix-Committed Fix is checked in, but it might be 3-4 weeks until a release.
Projects
Status: Done
Development

Successfully merging a pull request may close this issue.

9 participants