Executing basic SSH tasks using PoSH-SSH on Windows 10.
Note: PoSH-SSH is no replacement for a standard interactive ssh sessions. Better use products like Putty, MobaXterm or use buildin ssh support of the Windows Subsystem for Linux (WSL). Have a look at the documentation and use-cases below to find out if PoSH-SSH fits your requirements.
- Windows 10
- MS Powershell
Installing using NuGet Provider
PS C:\users\wer> Find-Module PoSH-SSH
Version Name Repository Description
------- ---- ---------- -----------
2.0.2 Posh-SSH PSGallery Provide SSH and SCP functionality for executing commands against remote hosts.
PS C:\users\wer> Find-Module PoSH-SSH | install-module
A list of avialable commands commands is displayed with 'get-command -module posh-ssh'.
Help for each command is available usong using get-help <CommandName> [-Detailed]
PS C:\users\wer> get-command -module posh-ssh
CommandType Name Version Source
----------- ---- ------- ------
Function Get-PoshSSHModVersion 2.0.2 Posh-SSH
Function Get-SFTPChildItem 2.0.2 Posh-SSH
Function Get-SFTPContent 2.0.2 Posh-SSH
Function Get-SFTPLocation 2.0.2 Posh-SSH
Function Get-SFTPPathAttribute 2.0.2 Posh-SSH
Function Get-SFTPSession 2.0.2 Posh-SSH
Function Get-SSHPortForward 2.0.2 Posh-SSH
Function Get-SSHSession 2.0.2 Posh-SSH
Function Get-SSHTrustedHost 2.0.2 Posh-SSH
Function Invoke-SSHCommand 2.0.2 Posh-SSH
Function Invoke-SSHCommandStream 2.0.2 Posh-SSH
Function Invoke-SSHStreamExpectAction 2.0.2 Posh-SSH
Function Invoke-SSHStreamExpectSecureAction 2.0.2 Posh-SSH
Function New-SFTPFileStream 2.0.2 Posh-SSH
Function New-SFTPItem 2.0.2 Posh-SSH
Function New-SFTPSymlink 2.0.2 Posh-SSH
Function New-SSHDynamicPortForward 2.0.2 Posh-SSH
Function New-SSHLocalPortForward 2.0.2 Posh-SSH
Function New-SSHRemotePortForward 2.0.2 Posh-SSH
Function New-SSHShellStream 2.0.2 Posh-SSH
Function New-SSHTrustedHost 2.0.2 Posh-SSH
Function Remove-SFTPItem 2.0.2 Posh-SSH
Function Remove-SFTPSession 2.0.2 Posh-SSH
Function Remove-SSHSession 2.0.2 Posh-SSH
Function Remove-SSHTrustedHost 2.0.2 Posh-SSH
Function Rename-SFTPFile 2.0.2 Posh-SSH
Function Set-SFTPContent 2.0.2 Posh-SSH
Function Set-SFTPLocation 2.0.2 Posh-SSH
Function Set-SFTPPathAttribute 2.0.2 Posh-SSH
Function Start-SSHPortForward 2.0.2 Posh-SSH
Function Stop-SSHPortForward 2.0.2 Posh-SSH
Function Test-SFTPPath 2.0.2 Posh-SSH
Cmdlet Get-SCPFile 2.0.2 Posh-SSH
Cmdlet Get-SCPFolder 2.0.2 Posh-SSH
Cmdlet Get-SFTPFile 2.0.2 Posh-SSH
Cmdlet New-SFTPSession 2.0.2 Posh-SSH
Cmdlet New-SSHSession 2.0.2 Posh-SSH
Cmdlet Set-SCPFile 2.0.2 Posh-SSH
Cmdlet Set-SCPFolder 2.0.2 Posh-SSH
Cmdlet Set-SFTPFile 2.0.2 Posh-SSH
Most of the commands require the input of username/password credentials. For non-interactive use, create a a PSCredential object and pass it to the command using the -credential option
The username is the login-name on the remote site.
When passwort authentication is used on remote machine, the passwort is the password the user logs in with. When keyfile authentication is used, the password is the password of the keyfile.
(Set-SCPFile | Get-SCPFile) -ComputerName <hostnameOrIp> -LocalFile <localFileName> -RemoteFile <remoteFileName>
Example:
Set-SCPFile -ComputerName myCloudServer -LocalFile c:\tmp\json.config -RemoteFile /tmp/json.config
Note: Use Get-SCPFolder to copy from remote to local folder
(Set-SCPFolder | Get-SCPFolder) -ComputerName <hostnameOrIp> -KeyFile <keyFile> `
-LocalFolder <windowsPath> -RemoteFolder <linuxPath>
Example:
Set-SCPFolder -ComputerName myCloudServer -KeyFile ~/.ssh/id_rsa -LocalFolder c:\tmp\deploy `
-RemoteFolder ~/deploy