SSH from PowerShell
I’ve been using the Windows Subsystem for Linux to do most of my development in ruby these days. Despite this I always kept a VM running with tmux and SSHed into it using an SSH client on Windows.
I recently discovered cmder and then hyper. I’m leaning towards liking cmder slightly more in its current state, but both let me run bash and PowerShell tabs in the same terminal interface, which made me happy. However, the tab titles were bothering me. In an effort to find a nice workaround, I stumbled upon a quite amazing simple tip that makes SSHing from PowerShell possible, but as a side bonus you actually get updated tab titles as well.
First, locate your profile. In PowerShell, just type $profile to see the location, or if you have Sublime you can edit it directly by typing subl $profile
Now, add this function to your profile:
This simple function allows you to use ssh as if it were a native tool. Let’s break it down briefly to understand what’s going on:
Get Jonathan Johnson’s stories in your inbox
Join Medium for free to get updates from this writer.
Line 2 explicitly sets the WindowTitle which updates the tab. Although once connected, ssh will manage the title for you, this allows the tab to get a name while it’s connecting. Very minor, but I like it so I kept it.
The next line executes the windows executable that launches the bash prompt. We pass in -l to initiate a “login” shell. This means it will execute your profile/bashrc, so if you set up things like ssh-agent in your bash startup, ssh user agent forwarding will work for this command. -c executes a command inline, and of course we execute ssh passing in all of the arguments the function received. That’s it!
Example usage is:
PS > ssh -T git@github.com
Agent pid 247
Identity added: *****
Hi nilobject! You've successfully authenticated, but GitHub does not provide shell access.
PS >Note, you can also create a function like zsh using this same style of trick to launch an alternative shell directly as well, or to expose any other number of utilities directly. Me, personally, I think the big wins are for getting into zsh quickly and sshing quickly from a new tab. Otherwise I want to live in PowerShell or live in zsh.



