May 30, 2018 · Powershell ·

Powershell Remoting from a Mac to Windows Server

In our shop, we run the always-excellent PDQ Deploy from Admin Arsenal. However, I wanted a way to control the PDQ console using the command line on my day-to-day workstation, which is a Mac.

To do this, as it turns out, only requires working through some decent (slightly incomplete) documentation online. Amazingly, it's possible!

You'll need:
  • Powershell Core for MacOS
  • Powershell Core installed on the Windows server
  • The Win32 OpenSSH build installed on the Windows server
First, you'll need to configure the Windows server or workstation to allow incoming SSH connections via Powershell.
  1. Begin by installing the latest stable .msi of Powershell Core from the GitHub repo for your build of Windows.

  2. Once that's installed, you'll need to install Win32 OpenSSH. Download the .zip here.

  3. Extract contents of the latest build to C:\Program Files\OpenSSH

  4. In an elevated (Administrator) Powershell window, run the following:
    powershell.exe -ExecutionPolicy Bypass -File install-sshd.ps1 , where install-sshd.ps1 is the installer file located in the newly extracted directory. You'll need to cd there first.

  5. In the same elevated Powershell window, open the firewall for sshd.exe to allow inbound SSH connections:
    New-NetFirewallRule -Name sshd -DisplayName 'OpenSSH Server (sshd)' -Enabled True -Direction Inbound -Protocol TCP -Action Allow -LocalPort 22
    Note: New-NetFirewallRule is for Windows 2012 and above servers only. If you're on a client desktop machine (like Windows 10) or Windows 2008 R2 and below, try:
    netsh advfirewall firewall add rule name=sshd dir=in action=allow protocol=TCP localport=22

  6. Start sshd (this will automatically generate host keys under %programdata%\ssh if they don't already exist)
    net start sshd

  7. Setup sshd and ssh-agent to auto-start (optional)
    Set-Service sshd -StartupType Automatic
    Set-Service ssh-agent -StartupType Automatic

  8. Then you need to edit the sshd_config file at %ProgramData%\ssh\. Add a PowerShell subsystem entry as follows: Subsystem powershell c:/program files/powershell/6.0.2/pwsh.exe -sshs -NoLogo -NoProfile

  9. Restart the sshd service: Restart-Service sshd

  10. Add the path where OpenSSH is installed to your PATH environment variable. The path should be something like: C:\Program Files\OpenSSH\

Next, you'll need to install Powershell Core on the Mac you want to connect with.

Simply install the .pkg file for the stable build from the same GitHub repo.

Then, let's connect:

  1. Start Powershell in your terminal by typing pwsh.
  2. Enter a new PSSession remotely by typing:
    Enter-PSSession -HostName [server name] -UserName Domain\User -SSHTransport

And that's it! You should now be able to remotely execute Powershell as if you were using the GUI for the server.