Files
MajorWiki/05-troubleshooting/networking/windows-openssh-wsl-default-shell-breaks-remote-commands.md
Marcus Summers daa771760b wiki: add WSL OpenSSH default shell + Ansible world-writable mount articles
Two new troubleshooting articles from today's MajorRig/MajorMac Ansible setup:
- Windows OpenSSH WSL default shell breaks remote SSH commands
- Ansible silently ignores ansible.cfg on WSL2 world-writable mounts

Article count: 76

Co-Authored-By: Claude Opus 4.6 (1M context) <noreply@anthropic.com>
2026-04-03 10:23:02 -04:00

2.8 KiB

title, domain, category, tags, status, created, updated
title domain category tags status created updated
Windows OpenSSH: WSL as Default Shell Breaks Remote Commands troubleshooting networking
windows
openssh
wsl
ssh
majorrig
powershell
published 2026-04-03 2026-04-03

Windows OpenSSH: WSL as Default Shell Breaks Remote Commands

Problem

SSH remote commands fail with:

Invalid command line argument: -c
Please use 'wsl.exe --help' to get a list of supported arguments.

This happens on every remote command — ssh-copy-id, ssh user@host "command", scp, etc. Interactive SSH (no command) may still work if it drops into WSL.

Cause

Windows OpenSSH's default shell is set to C:\Windows\System32\wsl.exe. When SSH executes a remote command, it invokes:

<default_shell> -c "<command>"

But wsl.exe does not accept the -c flag. It expects -e for command execution, or no flags for an interactive session. Since OpenSSH hardcodes -c, every remote command fails.

Fix

Change the default shell to PowerShell. Run this in an elevated PowerShell on the Windows host:

New-ItemProperty -Path "HKLM:\SOFTWARE\OpenSSH" -Name DefaultShell -Value "C:\Windows\System32\WindowsPowerShell\v1.0\powershell.exe" -PropertyType String -Force
Restart-Service sshd

If you need to run this from within WSL (e.g., over an interactive SSH session):

powershell.exe -Command "Start-Process powershell -Verb RunAs -ArgumentList '-Command New-ItemProperty -Path HKLM:\\SOFTWARE\\OpenSSH -Name DefaultShell -Value C:\\Windows\\System32\\WindowsPowerShell\\v1.0\\powershell.exe -PropertyType String -Force; Restart-Service sshd'"

After the Fix

  • Remote SSH commands now execute via PowerShell
  • To run Linux commands, prefix with wsl:
    ssh user@host "wsl bash -c 'cd /mnt/d/project && git pull'"
    
  • Interactive SSH sessions land in PowerShell (use wsl to enter Linux)
  • ssh-copy-id still won't work for WSL's authorized_keys — Windows OpenSSH reads from C:\Users\<user>\.ssh\authorized_keys, not the WSL home directory

Key Notes

  • This registry key is the only supported way to change the OpenSSH default shell on Windows
  • The change persists across reboots and Windows Updates
  • If you previously set the default shell to wsl.exe to get a Linux-first SSH experience, be aware that it permanently breaks all remote command execution
  • Tools like Ansible, scp, rsync, and ssh-copy-id all depend on -c working