Originally part of the posh-git project, posh-sshell is a PowerShell module that provides utilities for working with SSH connections within PowerShell.
Before installing posh-sshell make sure the following prerequisites have been met.
PowerShell 5 or higher. Check your PowerShell version by executing
Script execution policy must be set to either
Unrestricted. Check the script execution policy setting by executing
Get-ExecutionPolicy. If the policy is not set to one of the two required values, run PowerShell as Administrator and execute
Set-ExecutionPolicy RemoteSigned -Scope CurrentUser -Confirm.
Installing posh-sshell via PowerShellGet
Execute the following command to install from the PowerShell Gallery:
PowerShellGet\Install-Module posh-sshell -Scope CurrentUser
You may be asked if you trust packages coming from the PowerShell Gallery. Answer yes to allow installation of this module to proceed.
Note: If you get an error message from
Install-Module about NuGet being required to interact with NuGet-based repositories, execute the following commands to bootstrap the NuGet provider:
Install-PackageProvider NuGet -Force Import-PackageProvider NuGet -Force
Then retry the
Install-Module command above.
After you have successfully installed the posh-sshell module from the PowerShell Gallery, you will be able to update to a newer version by executing the command:
After you have installed posh-sshell, you need to configure your PowerShell session to use the posh-sshell module.
Step 1: Import posh-sshell
The first step is to import the module into your PowerShell session.
You can do this with the command
Step 2: Import posh-sshell from Your PowerShell Profile
You do not want to have to manually execute the
Import-Module command every time you open a new PowerShell prompt.
Let's have PowerShell import this module for you in each new PowerShell session.
We can do this by either executing the command
Add-PoshSshellToProfile or by editing your PowerShell profile script and adding the command
If you want posh-sshell to be available in all your PowerShell hosts (console, ISE, etc) then execute
This will add a line containing
Import-Module posh-sshell to the file
If you want posh-sshell to be available in just the current host, then execute
This will add the same command but to the file
If you'd prefer, you can manually edit the desired PowerShell profile script.
Open (or create) your profile script with the command
In the profile script, add the following line:
Save the profile script, then close PowerShell and open a new PowerShell session.
Posh-Sshell has several features:
SSH Connection Manager
The SSH connection manager allows you to work with hosts defined in your
~/.ssh/config file. Typing
Connect-Ssh will display all the hosts in the file, and allow you to connect to one of them. For example, if you have the following in your config file:
Host Server1 HostName server1.jeremyskinner.co.uk User jeremy Host Server2 HostName server1.jeremyskinner.co.uk User jeremy
Connect-Ssh will present you with the following interface where you can select a connection:
You can also connect directly to a particular session, by using
Connect-Ssh <server name>, eg
Adding and removing connections
As well as displaying connections, you can add new connections directly to your ssh config file using,
Add-SshConnection -Name Server1 -Uri server1.jeremyskinner.co.uk -User jeremy
You can also use a short-hand syntax:
Add-SshConnection Server1 email@example.com
Similarily, you can remove connections with
Automatically start the SSH Agent
Posh-Sshell can automatically start your SSH agent by adding a call to
Start-SshAgent -Quiet in your profile.
If you are using the Windows-native version of OpenSSH that ships with Windows 10 1803 or newer, then this will simply start the agent service if it's not already running and add your keys. You will be prompted once to enter your key passphrase. Once the service is running, you will not be prompted again.
If you are using the version of OpenSSH that comes with Git for Windows, then you will be prompted to enter your key the first time you open a Powershell session following a restart.
If you are using Pageant as your SSH agent, then Pageant will be automatically started and your keys will be added.