πLinux Tip: Managing File Permissions on WSL π
Last week during my session of the Ops&Bytes Terraform boot camp, I ran into an interesting challenge: setting up SSH access to an EC2 instance on my Windows machine using WSL. When I tried to change file permissions for my SSH key (chmod 400 public-instance-key.pem
), everything seemed fine until I checked with ls -ltrh
β the permissions still showed as -r-xr-xr-x
(555), not the expected 400. This caused an issue when trying to SSH into my EC2 instance! π¬
ποΈ Expected Flow
Below is the High Level expect traffic flow
π The Problem
Windows Subsystem for Linux (WSL) doesnβt fully support Unix-style permissions on files stored in Windows directories (/mnt/c/...
). This means chmod
commands may appear to work, but the permissions arenβt set the way they would be on a native Linux system, which SSH needs for secure connections.
π‘ Solution
The fix? Move the SSH key file to a native WSL directory (like ~/
) where Linux permissions are properly enforced:
Copy the file to your WSL home directory:
cp /mnt/c/path/to/your/public-instance-key.pem ~/
Change the permissions to read-only:
chmod 400 ~/public-instance-key.pem
Use the key from the WSL directory to SSH into your instance:
ssh -i ~/public-instance-key.pem your_ec2_user@your_public_ec2_ip
π¨πΏβπ» How did I get to the solution?
All it took was a carefully constructed prompt for ChatGpt to explain my issue.
β οΈ Caution
If you're working with WSL and need strict permission settings, always move sensitive files like SSH keys to WSL-native directories. This will save you some headaches and keep things secure! π
π Resources
Here is a link to my terraform BootCamp code: https://github.com/Thab310/terraform-bootcamp-week-2
Slack: https://lnkd.in/dV4sp7GB
Hope this helps others working with Terraform, WSL, and AWS!
Subscribe to my newsletter
Read articles from Thabelo Ramabulana directly inside your inbox. Subscribe to the newsletter, and don't miss out.
Written by
Thabelo Ramabulana
Thabelo Ramabulana
"Hey there! I'm Thabelo, π¨βπ» I am a DevOps enthusiast passionate about automation, containers, and all things cloud-native. In this publication, I'll be sharing my insights, tips, and tricks for building successful cloud projects. Whether you're interested in cloud infrastructure, cloud-native development, or just want to learn more about the cloud, I'm excited to share my knowledge with you. Let's explore the limitless potential of the cloud together and discover new ways to create, innovate, and connect in the digital age."