Issue Overview
While working on a Python project in WSL (Windows Subsystem for Linux) with Ubuntu, I faced an issue where I couldn't save changes to a file (app.py) using Notepad++ or even IDLE.
Subsystem path: \\wsl.localhost\Ubuntu\home\atif\tts-app
Error in Notepad++
When trying to save, the following message appeared:
Save failed
Please check whether the network where the file is located is connected.
Error in IDLE
In IDLE, the error was clearer:
Permission denied
This suggested that it might be a file ownership or permission issue.
Investigation and Debugging
To debug the issue, I opened the WSL terminal and navigated to the project folder:
cd ~/tts-app
ls -l
Here’s the output:
total 48
drwxr-xr-x 2 atif atif 4096 Jul 9 16:06 __pycache__
-rw-r--r-- 1 root root 4210 Jul 9 16:04 app.py
-rw-r--r-- 1 atif atif 4210 Jul 9 16:04 app.py.bak
drwxr-xr-x 2 root root 4096 Jul 9 16:03 backupCode
drwxr-xr-x 2 atif atif 12288 Jul 10 12:11 logs
drwxr-xr-x 3 atif atif 4096 Jul 9 15:42 static
drwxr-xr-x 2 root root 4096 Jul 9 15:41 templates
drwxr-xr-x 6 atif atif 4096 Jul 9 14:29 venv
As you can see, app.py and the backupCode directory were owned by root, not by the current user atif. This is why the file couldn’t be modified from regular editors like Notepad++ or IDLE — because they don’t run with root privileges.
Solution: Change File Ownership
To fix this, I changed the ownership of all files and folders inside the current directory to my user (atif) using the chown command:
sudo chown -R atif:atif .
After running this command, I verified again with ls -l:
total 56
drwxr-xr-x 2 atif atif 4096 Jul 9 16:06 __pycache__
-rw-r--r-- 1 atif atif 4210 Jul 9 16:04 app.py
-rw-r--r-- 1 atif atif 4211 Jul 10 13:37 app.py.bak
-rw-r--r-- 1 atif atif 4210 Jul 9 16:04 app.py.bak.bak
drwxr-xr-x 2 atif atif 4096 Jul 9 16:03 backupCode
drwxr-xr-x 2 atif atif 12288 Jul 10 12:11 logs
drwxr-xr-x 3 atif atif 4096 Jul 9 15:42 static
drwxr-xr-x 2 atif atif 4096 Jul 9 15:41 templates
drwxr-xr-x 6 atif atif 4096 Jul 9 14:29 venv
Now all files are correctly owned by atif, and I was finally able to save them through both Notepad++ and IDLE without any errors.
Final Notes
-
This issue typically occurs when files or directories are created or copied using
sudoor another tool that assigns ownership toroot. -
Always check file permissions using
ls -lwhen you encounter saving or editing issues in WSL. -
Use
chowncarefully — make sure you understand which directory you're applying it to.
Comments
Post a Comment