# Update packages
sudo apt update && sudo apt upgrade -y
# Install OpenSSH server
sudo apt install openssh-server -y
# Configure SSH to start automatically
sudo systemctl enable ssh
sudo systemctl start ssh
# Check SSH status
sudo systemctl status ssh
Edit the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Make sure these settings are configured:
Port 2222 # Use a different port to avoid conflicts with Windows SSH
PasswordAuthentication yes # Initially, we'll set up keys later
PubkeyAuthentication yes
Restart SSH:
sudo systemctl restart ssh
On your WSL Ubuntu:
# Create .ssh directory if it doesn't exist
mkdir -p ~/.ssh
chmod 700 ~/.ssh
ssh-keygen -t ed25519 -C "[email protected]"
# Press Enter to accept default location
# Enter a passphrase (recommended) or leave empty
First, get the IP address of your Windows machine on the local network. You'll need this, not the WSL IP.
# Copy your public key (you'll paste this in WSL)
cat ~/.ssh/id_ed25519.pub
Then SSH into your WSL instance (replace WINDOWS_IP
with your Windows machine's IP):
ssh -p 2222 your-wsl-username@WINDOWS_IP
Add your public key to authorized_keys on WSL:
# On WSL, add the public key
echo "YOUR_PUBLIC_KEY_HERE" >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
On your Windows machine, you need to allow the SSH port through the firewall:
- Open Windows PowerShell as Administrator
- Run:
New-NetFirewallRule -Name "WSL2 SSH" -DisplayName "WSL2 SSH" -Direction Inbound -LocalPort 2222 -Protocol TCP -Action Allow
Create a PowerShell script on Windows to forward ports:
# Save as wsl-port-forward.ps1
$wslIP = wsl hostname -I | ForEach-Object { $_.Trim() }
netsh interface portproxy delete v4tov4 listenport=2222 listenaddress=0.0.0.0
netsh interface portproxy add v4tov4 listenport=2222 listenaddress=0.0.0.0 connectport=2222 connectaddress=$wslIP
Run this script as Administrator whenever you start WSL.
Edit .wslconfig
in your Windows user folder:
[wsl2]
networkingMode=bridged
vmSwitch=WSL
In Cursor, install the "Remote - SSH" extension if it's not already installed.
- Open Command Palette (Cmd+Shift+P)
- Type "Remote-SSH: Add New SSH Host"
- Enter:
ssh -p 2222 your-wsl-username@WINDOWS_IP
- Select the SSH config file to update (usually
~/.ssh/config
)
- Open Command Palette (Cmd+Shift+P)
- Type "Remote-SSH: Connect to Host"
- Select your WSL host
- Cursor will open a new window connected to your WSL instance
Add this to ~/.ssh/config
on your Macbook for easier connection:
Host wsl-ubuntu
HostName WINDOWS_IP
Port 2222
User your-wsl-username
IdentityFile ~/.ssh/id_ed25519
Then you can simply use ssh wsl-ubuntu
to connect.
-
Check Windows IP address:
- On Windows:
ipconfig
in Command Prompt - Look for IPv4 address on your network adapter
- On Windows:
-
Verify SSH is running in WSL:
sudo systemctl status ssh
-
Check Windows Firewall:
- Ensure port 2222 is allowed
- Temporarily disable firewall to test
-
Test connection from WSL to itself:
ssh -p 2222 localhost
Create a scheduled task on Windows to run the port forwarding script at startup.
- Use WSL2 for better performance
- Store your projects on the WSL filesystem (not /mnt/c/)
- Use
.gitignore
to exclude large files and node_modules
If you have issues with SSH, you can also use:
- code-server: Web-based VS Code that runs on WSL
- GitHub Codespaces: If your project is on GitHub
- Tailscale: For secure remote access without port forwarding
This setup will give you a seamless development experience, allowing you to work on your WSL projects from your Macbook using Cursor with full IntelliSense, debugging, and terminal access.