Linux – Bash on Ubuntu on Windows gives error “-bash: /home/user/.bashrc: Permission denied” on startup

bashbashrcpermissionswindows 10windows-subsystem-for-linux

So I was working with Bash on Unbuntu on Windows in order to learn Linux, so I attempted to edit the .bashrc file as a way of learning. To do this I went into the root folder in my C: drive and opened the .bashrc in VS Code. I added one line into the end of the file.

When I tried to run ubuntu I got this error (even though it still works), and the error still persists even after I went in to try undo what I did before. What is wrong?

Best Answer

What is wrong?

As you mentioned that you went to root folder in C: drive and opened .bashrc in VSCode, I am assuming that the VSCode you just used was installed on Windows, not on WSL. Now I would like to refer you to a blog post on the official blog of Microsoft that explains the exact situation that you have encountered. This will help too.

To revert the changes, I would suggest you to open the .bashrc in the same way you did previously and copy all its content to a different file say, on your desktop. Remove .bashrc file. Now open a text editor in WSL preferably vim or gedit, make a file with name .bashrc, save it in the home directory and copy all the text that you saved on your desktop to the new .bashrc and it is all done.

Related Question