type
Post
status
Published
date
May 7, 2026
slug
how-to-use-vscode-in-wsl2-from-mac
summary
A deep, step-by-step walkthrough of remote-developing inside WSL 2 from a Mac using VS Code—including how the client–server architecture works and the key performance pitfalls.
tags
Tools
Development
category
Tech Sharing
icon
password
URL
In the developer world, “Mac for daily work, Windows for compute” has become a common high-performance setup. But how do you make the two work together seamlessly? This guide breaks down the full workflow of using VS Code to remote-develop inside WSL 2 from a Mac.
1. The core idea: decoupling UI and runtime
VS Code Remote Development is not “remote desktop streaming.” Its core is a client–server architecture:
- Lightweight client (Mac): Responsible only for UI rendering, themes, and keybindings. No language runtimes required.
- VS Code Server (inside WSL 2): The real engine. When you connect, VS Code installs a dedicated server component in the Linux environment.
- Responsibilities: IntelliSense, debugging, Git operations, and extension execution.
- Why it’s great: Extensions run inside Linux, so they can use the host machine’s compilers/GPU without polluting your Mac environment.
2. Setup: step-by-step (beginner-friendly)
Step 1: Prepare the Windows host
- Enable OpenSSH Server: In Settings → Optional features, make sure OpenSSH Server is installed.
- Auto-start the service: Run PowerShell as Administrator:
Start-Service sshd; Set-Service -Name sshd -StartupType 'Automatic'- Update WSL: Run
wsl --updateto get the latest kernel and ensure virtualization is enabled.
Step 2: Create the SSH tunnel and “second hop” into WSL
- Install VS Code extensions (Mac): Install the Remote Development extension pack (Remote - SSH + WSL, etc.).
- Connect via SSH to Windows:
- Click the green
><icon in the bottom-left → Connect to Host... → enterssh <user>@<windows-ip>. - Key detail: After connecting, click the green icon again and choose WSL: Connect to WSL using Distro.
- VS Code will then “enter” WSL through the existing SSH session and install the server inside your Linux distro.
3. 2026 pitfalls and performance tips
To get a truly “local-like” experience, these details matter:
- Filesystem red line (crucial): Store your code in the native WSL filesystem (e.g.
/home/<user>/projects). Do not open projects from/mnt/c/.... Crossing filesystems can cause up to ~10× slower I/O.
- Networking/DNS: If DNS is flaky, disable
generateResolvConfin/etc/wsl.confand set a fixed DNS (e.g.1.1.1.1).
- File watchers: For large repos, exclude folders like
node_modulesviafiles.watcherExcludeto reduce server CPU usage.
4. Advanced: passwordless login and tunnels
SSH config aliases
Add this to your Mac’s
~/.ssh/config to avoid typing IPs:Host win-box
HostName 192.168.1.100
User dev_user
ForwardAgent yesThen you can simply run
ssh win-box.Passwordless login
Run on Mac:
ssh-copy-id -i ~/.ssh/id_rsa.pub <user>@<windows-ip>This prevents repeated password prompts during git pulls/sync scripts.
Alternative: Remote Tunnels
If your Windows machine sits behind NAT with no stable IP, VS Code Remote Tunnels is a mature option in 2026. It uses Microsoft dev tunnels to connect securely without manually configuring SSH port forwarding.
Summary
In 2026, VS Code + WSL 2 is still one of the best cross-system dev setups: Mac ergonomics + Windows hardware. Follow one principle—keep code inside Linux, avoid cross-filesystem paths—and you’ll get a near-perfect, local-like development experience.
上一篇
2026 Deep Guide: Mirrored Mode + Auto-Activation for Instant Mac → WSL 2 Remote Dev
下一篇
Obsidian + AI:打造你的第二大脑知识管理新范式
- 作者:airouter.me
- 链接:https://airouter.me/en/article/how-to-use-vscode-in-wsl2-from-mac
- 声明:本文采用 CC BY-NC-SA 4.0 许可协议,转载请注明出处。