Bash on Ubuntu on Windows gives error "-bash: /home/user/.bashrc: Permission denied" on startup

3

1

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?

wjmccann

Posted 2018-05-02T04:40:32.343

Reputation: 133

Sounds like a permission problem. Can you try to do sudo chmod 644 /home/user/.bashrc and see if that helps. – Mikael Kjær – 2018-05-02T04:51:44.963

@Biswapriyo Why didn't you make that edit yourself? – DavidPostill – 2018-05-02T07:55:18.857

@MikaelKjær Would be helpful if this was posted as an answer; your comment worked for me. – Stardust – 2018-11-27T02:28:08.187

Answers

5

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.

DeusExMachina

Posted 2018-05-02T04:40:32.343

Reputation: 68

0

Once started the shell and you see this error, "reset" the permission(s) of that file(s).


Try this

1) Go there cd /home/{USER}/ and

2) Change permission chmod 644 .bashrc


Notes:

1) For me it was working without sudo

2) 644 means writable, readable and executable for the user and readable for groups and others


I had this issue because I edited some .bash*** files with Notepad++ on Windows. After saving the files there were not executable anymore with Ubuntu.

Instead of copying, saving, re-creating the changes, like @DeusExMachina mentioned, I wanted to see what just happened with the file permissions there.

I went into my home directory and checked the Permissions of each file and I saw that my edited files .bashrc and .bash_aliases now had permissions of 000 - so they got locked by Windows!

I changed the permissions for my edited files from 000 to 644 and it was working again.

Nico W.

Posted 2018-05-02T04:40:32.343

Reputation: 1

-1

I had this exact issue. To solve it, I simply used sudo chmod -R 777 /home/user/.bashrc and it worked.

MathuSum Mut

Posted 2018-05-02T04:40:32.343

Reputation: 109