Security Hardening
Lock down your WSL environment with firewall rules, SSH hardening, secrets management, and Windows Defender integration.
Firewall Rules for WSL
WSL 2 traffic passes through the Windows Firewall. You can control inbound and outbound access with standard firewall rules and the new Hyper-V firewall feature.
Enable WSL Firewall in .wslconfig
Block Inbound Connections to WSL
Linux-side Firewall with UFW
SSH Hardening
If you run an SSH server inside WSL for remote access, harden it beyond the defaults.
Generate Strong SSH Keys
Harden sshd_config
Secrets Management
Never store secrets in plain text inside WSL. Use credential helpers and environment isolation to keep tokens, API keys, and passwords safe.
Git Credential Manager
Use Windows Credential Manager from inside WSL so tokens are stored in the encrypted Windows vault.
Environment Variable Isolation
Prevent Windows environment variables from leaking into WSL by controlling the WSLENV variable and the interop settings.
SSH Agent Forwarding
Share your Windows SSH keys with WSL securely using 1Password, the Windows SSH agent, or keychain.
Windows Defender & WSL
Windows Defender can scan WSL file systems, but this can slow down build processes. Balance security with performance using targeted exclusions.
Add Performance Exclusions
Security trade-off: Only add exclusions for build directories you trust. Never exclude your entire WSL filesystem — keep Defender scanning downloads and untrusted files.
Enable Microsoft Defender for Linux (Enterprise)
For enterprise environments, Microsoft Defender for Endpoint can run inside WSL to provide real-time protection within the Linux filesystem.
Security Checklist
Quick reference for hardening a fresh WSL installation.
Keep Windows and WSL kernel updated (wsl --update)
Disable password authentication for SSH — use key-based auth
Set appendWindowsPath = false to limit path exposure
Use Git Credential Manager instead of storing tokens in dotfiles
Enable firewall=true in .wslconfig
Add Defender exclusions only for trusted build directories
Run regular package updates: sudo apt update && sudo apt upgrade
Audit open ports: ss -tlnp inside WSL
Use separate WSL distros for different trust levels
Next Steps
Networking Deep Dive
Configure networking modes and port forwarding securely.
Enterprise Playbook
Governance, compliance, and rollout strategies for enterprise WSL.
Best Practices
General tips for keeping your WSL environment clean and efficient.
Troubleshooting
Fix common security-related issues and permission errors.