platform agnostic remote execution

tl;dr: ssh.

Background: We had to run a specific command across a few hundred systems of varying platforms and configurations.

For Linux systems, it's relatively easy - ssh is standard on nearly every distro (saying nearly because while I've never encountered a distro without it, I know someone out there has built some version of Linux without it).

Windows by default does not have ssh. You can use PowerShell and Invoke-Command to run a command on a remote machine, but that requires the host machine to be Windows.

While PowerShell is now supported on Linux/Posix systems, at the time of writing this, it does not support winrm to Invoke-Command.

I already have written a Golang application to execute commands across many systems in parallel, but it uses ssh to connect to the remote machines.

The application also includes an option to use PowerShell and Invoke-Command for remote Windows machines if the executing workstation is a Windows machine - but mine is not.

However, OpenSSH is supported by Windows - just not enabled by default. By installing the OpenSSH server, you can then connect to the remote machine through SSH and be dropped into the command prompt.

Installation - Chocolatey
choco install openssh -y -params "/SSHServerFeature"
Installation - PowerShell
# Install OpenSSH Client
Add-WindowsCapability -Online -Name OpenSSH.Client~~~~0.0.1.0

# Install OpenSSH Server
Add-WindowsCapability -Online -Name OpenSSH.Server~~~~0.0.1.0

Start-Service sshd
Set-Service -Name sshd -StartupType 'Automatic'


Connecting

Once the SSH server is running on the remote machine you will be able to connect just as ususal: ssh user@server.

If using an AD account: ssh domain:user@server.

last updated 2024-03-18