Created
May 22, 2025 01:48
-
-
Save wurin7i/2ac763208cf38d25da45161c034c4ea1 to your computer and use it in GitHub Desktop.
Share .ssh between Windows and WSL
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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