If you possess multiple computers and operating systems, say a Macbook for MacOS applications, a Windows PC for gaming, and a Linux PC or virtual machine for work, moving files between them quickly becomes a headache. You could use a USB drive with exFAT file system format but most USB drives are limited in capacity. You could also use cloud storage but it adds latency and a third-party dependency for files that never need to leave your home network. The most reliable and scalable solution is to buy a dedicated NAS if you have a few hundred dollars to spare, or you could set up your own file sharing system for free.
Introducing SMB (Server Message Block): it is a network file-sharing protocol supported natively by macOS, Windows, and Linux that lets every device on your local network access shared folders as if they were local drives — no format compatibility concerns, no internet required, and full read/write speed over your LAN. Mobile operating systems (iOS and Android) also support SMB through apps like Files and VLC, so the same share can serve your phone too.
This guide covers the specific setup and daily workflow for bi-directional file sharing between a Mac and a Windows machine running WSL2 Ubuntu, which is just about as complicated as it can get, but the concepts apply to any combination of SMB-capable platforms.
Architecture
There are two sharing directions to set up. The first makes WSL2 files visible on the Mac; the second makes Mac files visible inside WSL2.
Mac → WSL2 direction
Mac (macOS)
|
| smb://WINDOWS_LAN_IP:4445/wsl-home
v
Windows Host (port 4445)
| netsh portproxy --> WSL2 IP:445
v
WSL2 Ubuntu (smbd on port 445, shares /home/your-linux-username)
WSL2 → Mac direction
WSL2 Ubuntu
|
| /mnt/mac-share (CIFS mount)
v
Mac (port 445, shares /Users/YourMacUsername)
Port 4445 is used for the Mac → WSL2 direction to avoid
clashing with Windows' own SMB service on port 445. A
netsh portproxy rule on Windows forwards traffic from
port 4445 on the Windows LAN IP to port 445 on the WSL2 IP. For the
WSL2 → Mac direction no proxy is needed: the Mac is
directly reachable on its own LAN IP at port 445.
Setup
Finding your IPs
You will need three IP addresses during setup. Run these commands once and note the results — WSL2's IP changes on every restart, but once step 7 is complete the portproxy script will handle that automatically.
WSL2 terminal
ip addr show eth0 | awk '/inet / {print $2}' | cut -d/ -f1
Mac terminal
ipconfig getifaddr en0
PowerShell
ipconfig | findstr /i "IPv4"
Use the Wi-Fi or Ethernet line — not vEthernet WSL.
Samba on WSL2
This makes your WSL2 home directory accessible from the Mac. All commands run inside WSL2 unless stated otherwise.
0. Enable systemd in WSL2
The Samba service is managed by systemd. Many WSL2 installations
ship with systemd disabled, which would cause
systemctl enable smbd (step 4) to silently fail. Check
first:
WSL2 terminal
cat /etc/wsl.conf
If you see [boot] with systemd=true
underneath, you're good — skip to step 1. If not, add it:
WSL2 terminal
sudo tee -a /etc/wsl.conf <<'EOF'
[boot]
systemd=true
EOF
Then restart WSL2 from a Windows PowerShell window (this closes all WSL2 sessions):
PowerShell
wsl --shutdown
Reopen your WSL2 terminal and confirm systemd is running before continuing:
WSL2 terminal
systemctl is-system-running
The output should be running (or degraded,
which is also fine). If it says offline, the
/etc/wsl.conf change did not take effect — double-check
the file and try wsl --shutdown again.
1. Install Samba and CIFS utilities
WSL2 terminal
sudo apt update && sudo apt install -y samba cifs-utils
2. Define the share in /etc/samba/smb.conf
Open the file in a text editor:
WSL2 terminal
sudo nano /etc/samba/smb.conf
Scroll to the very end and append the following block, replacing
your-linux-username with your actual WSL2 username.
Save with Ctrl+O, confirm, then exit with
Ctrl+X:
[wsl-home]
path = /home/your-linux-username
browseable = yes
read only = no
valid users = your-linux-username
3. Set a Samba password for your user
WSL2 terminal
sudo smbpasswd -a your-linux-username
This is separate from your Linux login password. You will use it when the Mac asks for credentials.
4. Enable and start smbd
WSL2 terminal
sudo systemctl enable smbd
sudo systemctl start smbd
5. Store Mac credentials for the reverse mount
Create /etc/samba/mac-credentials with your Mac account
details. Replace YourMacUsername with your macOS
account name and YourMacPassword with your
macOS login password (the same password you use to
unlock the Mac — not a separately configured SMB password):
WSL2 terminal
sudo tee /etc/samba/mac-credentials <<'EOF'
username=YourMacUsername
password=YourMacPassword
EOF
Lock down the file so only root can read it:
WSL2 terminal
sudo chmod 600 /etc/samba/mac-credentials
6. Add the Mac share to /etc/fstab
First create the mount point:
WSL2 terminal
sudo mkdir -p /mnt/mac-share
Next, find your Linux user ID and group ID — you will need them for the fstab entry:
WSL2 terminal
id your-linux-username
The output looks like
uid=1000(your-linux-username) gid=1000(your-linux-username)
.... Note the numeric values. Now open /etc/fstab:
WSL2 terminal
sudo nano /etc/fstab
Append the following line at the end, substituting
MAC_LAN_IP, YourMacUsername, and the
uid/gid values you just noted. Save and
exit (Ctrl+O, Enter, Ctrl+X):
//MAC_LAN_IP/YourMacUsername /mnt/mac-share cifs credentials=/etc/samba/mac-credentials,uid=1000,gid=1000,x-systemd.automount,noauto 0 0
The x-systemd.automount,noauto flags mean the share is
not mounted at boot (which would hang if the Mac is off) but is
mounted transparently on the first access. Reload systemd so it
picks up the new mount unit:
WSL2 terminal
sudo systemctl daemon-reload
Windows port proxy
How does this work?
WSL2 runs inside a lightweight VM with its own internal IP address. From the Mac's perspective, it cannot reach that IP directly — only the Windows machine's LAN IP is visible on your network. We therefore set up a port proxy rule on Windows: the Mac connects to port 4445 on the Windows LAN IP, and Windows silently forwards those packets to port 445 on the WSL2 VM. Port 4445 (not 445) is used because Windows already occupies port 445 for its own SMB service.
The WSL2 VM gets a fresh IP on every restart, so a hard-coded proxy rule would break after reboots. The fix is a short PowerShell script that looks up the current WSL2 IP and rewrites the proxy rule each time it runs. We save that script to disk and register it with Windows Task Scheduler so it fires automatically at every logon and startup.
All steps below run in Windows PowerShell opened as Administrator — search for "PowerShell" in the Start menu, right-click → Run as administrator.
1. Create the Scripts folder
We will store the portproxy script at
C:\Scripts\update-wsl2-portproxy.ps1. Create the folder
if it does not already exist:
PowerShell (Admin)
New-Item -ItemType Directory -Force -Path C:\Scripts
2. Create the portproxy script
The following command writes the script file directly from PowerShell. It reads the current WSL2 IP, removes any stale proxy rule on port 4445, then adds a fresh one pointing at the new IP:
PowerShell (Admin)
@'
$wsl2ip = (wsl hostname -I).Trim()
netsh interface portproxy delete v4tov4 listenport=4445 listenaddress=0.0.0.0 2>$null
netsh interface portproxy add v4tov4 listenport=4445 listenaddress=0.0.0.0 connectport=445 connectaddress=$wsl2ip
'@ | Set-Content C:\Scripts\update-wsl2-portproxy.ps1
To confirm the file looks right, open it in Notepad:
PowerShell (Admin)
notepad C:\Scripts\update-wsl2-portproxy.ps1
3. Open port 4445 in the Windows Firewall
Without this, Windows will silently drop inbound packets from the Mac before they ever reach the proxy rule:
PowerShell (Admin)
New-NetFirewallRule -DisplayName "WSL2 SMB" -Direction Inbound -Protocol TCP -LocalPort 4445 -Action Allow
4. Run the script once now
This creates the proxy rule immediately without needing a reboot.
PowerShell's default execution policy may block unsigned scripts —
the -ExecutionPolicy Bypass flag overrides it for this
single run:
PowerShell (Admin)
powershell.exe -ExecutionPolicy Bypass -File C:\Scripts\update-wsl2-portproxy.ps1
Verify that the rule was created:
PowerShell (Admin)
netsh interface portproxy show all
You should see a row with listen port 4445 and a
connect address matching the WSL2 IP you noted earlier.
5. Register with Task Scheduler
This ensures the proxy rule is refreshed automatically on every Windows logon and startup, even after WSL2's IP changes:
PowerShell (Admin)
$action = New-ScheduledTaskAction `
-Execute "powershell.exe" `
-Argument "-NonInteractive -ExecutionPolicy Bypass -File C:\Scripts\update-wsl2-portproxy.ps1"
$trigger = @(
$(New-ScheduledTaskTrigger -AtLogOn),
$(New-ScheduledTaskTrigger -AtStartup)
)
Register-ScheduledTask `
-TaskName "\WSL2\WSL2-Samba-PortProxy-Update" `
-Action $action `
-Trigger $trigger `
-RunLevel Highest `
-Force
To confirm, open Task Scheduler (search Start menu), navigate to Task Scheduler Library → WSL2, and verify WSL2-Samba-PortProxy-Update is listed there.
File Sharing on Mac
This makes your Mac home directory (or any folder you choose) accessible from WSL2.
- Open System Settings → General → Sharing and toggle File Sharing on.
-
Under Shared Folders, click +
and add your home folder (
/Users/YourMacUsername) or whichever directory you want WSL2 to reach. - Under Users, confirm your Mac account has Read & Write access. New shares default to Everyone: Read Only — if that's the case, click your user entry, click the dropdown next to it, and change it to Read & Write.
-
The share name defaults to your Mac username — this is the name
used in the
/etc/fstabline above (//MAC_LAN_IP/YourMacUsername).
File Sharing persists across reboots once enabled; no further configuration is needed on the Mac side.
Daily Workflow
Mac → WSL2 (access WSL2 files from Mac)
-
In Finder press Cmd+K and enter
smb://WINDOWS_LAN_IP:4445/wsl-home. -
Log in with username
your-linux-usernameand your Samba password. - The WSL2 home directory mounts in Finder — drag, drop, edit in place, or copy freely.
To skip step 1 permanently, right-click the mounted share in the Finder sidebar and choose Add to Login Items.
WSL2 → Mac (access Mac files from WSL2)
Just use the path — no manual mount is needed because the share is
configured to auto-mount on first access via
/etc/fstab:
ls /mnt/mac-share/
cp ~/file /mnt/mac-share/Desktop/
cat /mnt/mac-share/.zshrc
rsync -av ~/project/ /mnt/mac-share/project/
After restarts
| Event | Action needed |
|---|---|
| Windows / WSL2 restart | None — Task Scheduler updates the portproxy rule, systemd starts smbd |
| Mac restart | None — File Sharing re-enables automatically |
| Finder mount dropped | Cmd+K and reconnect |
Common Commands
# Copy file from Mac to WSL2
cp /mnt/mac-share/somefile ~/
# Copy file from WSL2 to Mac Desktop
cp ~/somefile /mnt/mac-share/Desktop/
# Sync folder Mac -> WSL2
rsync -av /mnt/mac-share/project/ ~/project/
# Sync folder WSL2 -> Mac
rsync -av ~/project/ /mnt/mac-share/project/
# Check Samba is running
sudo systemctl status smbd
# Manually remount Mac share (if automount failed)
sudo mount /mnt/mac-share
# Check WSL2 is listening on port 445
ss -tlnp | grep 445
Key Files
| File | Purpose |
|---|---|
/etc/samba/smb.conf |
Samba config — defines the wsl-home share |
/etc/samba/mac-credentials |
Mac login credentials for the CIFS mount (chmod 600) |
/etc/fstab |
Persistent Mac share mount with
x-systemd.automount
|
C:\Scripts\update-wsl2-portproxy.ps1 |
Windows script that refreshes the portproxy rule on each restart |
Windows Task Scheduler
\WSL2\WSL2-Samba-PortProxy-Update
|
Runs the portproxy script at logon and startup |
Troubleshooting
| Symptom | Fix |
|---|---|
| Mac Finder "Connection Failed" |
Check smbd is running in WSL2:
sudo systemctl status smbd. Then in Windows run
netsh interface portproxy show all to confirm the
4445 rule exists
|
| Mac auth error |
Run sudo smbpasswd -e your-linux-username in WSL2
to re-enable the Samba account
|
/mnt/mac-share empty or permission denied |
Verify File Sharing is enabled on the Mac; run
ping MAC_LAN_IP from WSL2 to confirm connectivity
|
| Mount hangs on boot | The Mac was off — automount retries on first access, no action needed |
| After WSL2 restart, Mac can't connect |
The Task Scheduler script may not have fired yet; wait 10 s or
run the script manually from an Administrator PowerShell:
powershell.exe -ExecutionPolicy Bypass -File
C:\Scripts\update-wsl2-portproxy.ps1
|
Comments