简体   繁体   中英

Permission Denied when editing .bash_profile

I'm still learning the CLI and the ins and outs of it, especially this .bash_profile. I feel overwhelmed with what I'm learning about this.

Anyways, I can access .bash_profile. If I do nano ~/.bash_profile then the file appears and I'm free to edit. And then I tried addingin the line I'm supposed to include:

export PATH="/usr/local/bin:/usr/local/sbin:/usr/local/mysql/bin:$PATH"

However, when I try to save the file (or whatever .bash_profile is), I get the following error: [ Error writing /home/myname.bash_profile Permission denied ]

While you can do sudo nano ~/.bash_profile to edit the file, I feel like it's a bit weird that your .bash_profile needs root to be modified.

If you try ls -la ~ | grep bash ls -la ~ | grep bash

-rw-------    1 Greg  staff    8622 27 Jun 16:06 .bash_history
-rw-r--r--    1 Greg  staff    2189 28 Jun 01:24 .bash_profile

You see my .bash_profile is owned by me, Greg, not root. I think you'll find that when you do this, your .bash_profile will be owned by root. This means that when you want to edit the file, you need to use sudo, but I don't.

If you don't want to have to use sudo all the time to modify this file, you can change the owner of the file sudo chown yourusername ~/.bash_profile

Now if you run the ls command I showed above, you should see your name as the owner of the file, instead of root.

You need root permissions to edit.

Edit it with sudo or login as root and edit.

Thanks,

Sandeep.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM