πŸš€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:

  1. Copy the file to your WSL home directory:

     cp /mnt/c/path/to/your/public-instance-key.pem ~/
    
  2. Change the permissions to read-only:

     chmod 400 ~/public-instance-key.pem
    
  3. 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

Hope this helps others working with Terraform, WSL, and AWS!

0
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."