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>
70 lines
2.8 KiB
Markdown
70 lines
2.8 KiB
Markdown
---
|
|
title: "Windows OpenSSH: WSL as Default Shell Breaks Remote Commands"
|
|
domain: troubleshooting
|
|
category: networking
|
|
tags: [windows, openssh, wsl, ssh, majorrig, powershell]
|
|
status: published
|
|
created: 2026-04-03
|
|
updated: 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:
|
|
|
|
```powershell
|
|
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):
|
|
|
|
```bash
|
|
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`:
|
|
```bash
|
|
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
|
|
|
|
## Related
|
|
|
|
- [Windows OpenSSH Server (sshd) Stops After Reboot](windows-sshd-stops-after-reboot.md) — sshd service startup issues
|
|
- [Microsoft Docs: OpenSSH DefaultShell](https://learn.microsoft.com/en-us/windows-server/administration/openssh/openssh-server-configuration#configuring-the-default-shell-for-openssh-in-windows)
|