Skip to content

Instantly share code, notes, and snippets.

@wurin7i
Created May 22, 2025 01:48
Show Gist options
  • Save wurin7i/2ac763208cf38d25da45161c034c4ea1 to your computer and use it in GitHub Desktop.
Save wurin7i/2ac763208cf38d25da45161c034c4ea1 to your computer and use it in GitHub Desktop.
Share .ssh between Windows and WSL
#!/bin/sh
# Share .ssh between Windows and WSL
# https://superuser.com/a/1737216
# Create .ssh directory in home directory with proper permission
mkdir -m 700 ~/.ssh
# Get Windows user name
WINUSER=`cmd.exe /c 'echo %USERNAME%' | tr -d '\r'`
# Add a permanent mount entry for Windows user .ssh directory
cat << EOF | sudo tee -a /etc/fstab
C:\Users\\$WINUSER\.ssh\ /home/$USER/.ssh drvfs rw,noatime,uid=`id -u`,gid=`id -g`,case=off,umask=0077,fmask=0177 0 0
EOF
# Mount the .ssh
sudo mount /home/$USER/.ssh
# Reload fstab
sudo systemctl daemon-reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment