Quick Summary: The error
WARNING: UNPROTECTED PRIVATE KEY FILE! Permissions 0644 for '~/.ssh/id_rsa' are too openoccurs when OpenSSH refuses to use a private key because its file permissions allow other local users or groups to read it. This frequently happens after copying keys from USB drives or cloud storage, restoring backups, or accessing SSH keys stored on a Windows NTFS partition from inside WSL2.
Understanding the Root Causes
OpenSSH enforces strict security hygiene on private keys: if a private key is readable by anyone other than the owning user (for example, 0644 or 0777), OpenSSH assumes the key may be compromised and aborts authentication with Load key "...": bad permissions. Common triggers include:
- Permissive File Transfer or Extraction: Downloading a
.pemorid_ed25519key via browser, SCP, or extracting from a ZIP archive defaults permissions to0644(world-readable) or0664. - WSL2 Accessing Windows /mnt/c/ Drives: Running
chmod 600 /mnt/c/Users/name/.ssh/id_rsainside WSL2 silently fails because the Windows NTFS mount (DrvFs) ignores Linux permission bits unless metadata support is explicitly enabled. - Insecure Parent Directory or Ownership: The
~/.sshdirectory itself has group/world write permissions, or the key file is owned byrootinstead of your active user.
Step 1: Quick Fix – Lock Down ~/.ssh Directory and Key Permissions
On native Linux and macOS filesystems, restrict the private key to owner read/write only (600 or 400) and secure the ~/.ssh folder:
# 1. Restrict permissions on the .ssh directory (owner rwx only)
chmod 700 ~/.ssh
# 2. Restrict permissions on your private key (owner rw only)
chmod 600 ~/.ssh/id_rsa
# Or for Ed25519 / PEM keys:
chmod 600 ~/.ssh/id_ed25519
chmod 400 ~/Downloads/my-ec2-key.pem
# 3. Ensure public keys and config files also have clean permissions
chmod 644 ~/.ssh/*.pub
chmod 600 ~/.ssh/config
Step 2: Fix Permissions Inside WSL2 When Key Resides on Windows
If chmod 600 runs without error but ls -l still shows -rwxrwxrwx (0777) on a file under /mnt/c/, move the key into the native Linux home directory inside WSL2:
# 1. Copy the private key from Windows /mnt/c/ into your Linux ~/.ssh directory
mkdir -p ~/.ssh
cp /mnt/c/Users/YourName/.ssh/id_ed25519 ~/.ssh/
# 2. Apply strict Linux permissions to the copied key
chmod 700 ~/.ssh
chmod 600 ~/.ssh/id_ed25519
# Optional: Enable Linux chmod metadata on /mnt/c in /etc/wsl.conf
sudo tee -a /etc/wsl.conf <<EOF
[automount]
options = "metadata"
EOF
# Restart WSL from PowerShell: wsl --shutdown
Step 3: Fix File Ownership Mismatches (sudo / Docker Mounts)
If you generated or copied the key using sudo or mounted it into a Docker container, OpenSSH may also reject it if the file owner does not match your current user:
# Verify current owner and permissions
ls -la ~/.ssh/
# Reassign ownership back to your current user and primary group
sudo chown -R $(whoami):$(id -gn) ~/.ssh
# Re-apply strict private key permissions
chmod 600 ~/.ssh/id_ed25519
Verification & Testing Steps
Confirm the exact octal permissions on your private key and test authenticating to your remote server:
# 1. Verify octal permissions (Linux stat)
stat -c "%a %U %n" ~/.ssh/id_ed25519
# On macOS BSD stat:
# stat -f "%Lp %Su %N" ~/.ssh/id_ed25519
# Expected output: 600 your_user /home/your_user/.ssh/id_ed25519
# 2. Test SSH authentication cleanly
ssh -i ~/.ssh/id_ed25519 -v user@192.168.1.50
Troubleshooting Summary Comparison
| Environment / Scenario | Primary Root Cause | Recommended Solution |
|---|---|---|
| Linux / macOS Terminal | Key has 0644 or 0777 permissions |
Run chmod 600 ~/.ssh/<key> and chmod 700 ~/.ssh |
WSL2 accessing /mnt/c/ |
NTFS DrvFs mount ignores chmod without metadata |
Copy key to ~/.ssh/ inside WSL2 and run chmod 600 |
AWS / Cloud .pem Key |
Browser download set world-readable permissions | Run chmod 400 my-key.pem before connecting |
Key created via sudo |
File owned by root instead of active user |
Run sudo chown $(whoami) <key> and chmod 600 |
Leave a Reply