I'm writing PowerShell modules that execute commands or scripts over SSH on remote Windows machines, and I'm looking for a way to transmit a password (or other sensitive information) over the connection. For example, imagine that we have a PowerShell script that contains this invocation:
ssh user@host powershell -Command Invoke-Foo -Password $password
As I learned from one of my previous questions, this example demonstrates poor security—the password, even though encrypted over SSH, appears as plain text on both systems. To protect against this, scripts store sensitive data as SecureString
or PSCredential
objects:
$password = Read-Host -AsSecureString
...which works fine on the local machine, but the scripts cannot pass the SecureString
objects over the text-based SSH protocol to a remote PowerShell process.
For background: I'm automating some processes that a person needed to type directly into a PowerShell session while connected to a machine over SSH, so the need for this did not exist before.
Unfortunately, we're walled-in with PowerShell 4, so the SSH facilities provided by newer PowerShell versions are not available, and, for non-technical reasons, we cannot use WinRM-based PowerShell remoting, as much as I'd like to. This means that I cannot rely on New-PSSession
or Invoke-Command
to serialize and send local objects to a remote session.
Within these constraints, how can I design PowerShell scripts to pass the sensitive data as text through SSH, and then receive the data remotely without exposing it? Is there a way to do it without installing encryption utilities and keys on every system?