简体   繁体   English

编辑.bash_profile时拒绝权限

[英]Permission Denied when editing .bash_profile

I'm still learning the CLI and the ins and outs of it, especially this .bash_profile. 我还在学习CLI及其中的细节,特别是这个.bash_profile。 I feel overwhelmed with what I'm learning about this. 我对自己所学到的东西感到不知所措。

Anyways, I can access .bash_profile. 无论如何,我可以访问.bash_profile。 If I do nano ~/.bash_profile then the file appears and I'm free to edit. 如果我执行nano ~/.bash_profile则文件出现,我可以自由编辑。 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 ] 但是,当我尝试保存文件(或任何.bash_profile)时,我收到以下错误: [ 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. 虽然你可以使用sudo nano ~/.bash_profile来编辑文件,但我觉得你的.bash_profile需要root来修改它有点奇怪。

If you try ls -la ~ | grep bash 如果你试试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. 你看我的.bash_profile归我所有,Greg,而不是root。 I think you'll find that when you do this, your .bash_profile will be owned by root. 我想你会发现,当你这样做时,你的.bash_profile将归root所有。 This means that when you want to edit the file, you need to use sudo, but I don't. 这意味着当你想编辑文件时,你需要使用sudo,但我没有。

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 如果您不想一直使用sudo来修改此文件,则可以更改文件的所有者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. 现在如果你运行我上面显示的ls命令,你应该看到你的名字作为文件的所有者,而不是root。

You need root permissions to edit. 您需要root权限才能进行编辑。

Edit it with sudo or login as root and edit. 使用sudo编辑它或以root身份登录并编辑。

Thanks, 谢谢,

Sandeep. 桑迪普。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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