简体   繁体   English

.bashrc:权限被拒绝

[英].bashrc: Permission denied

I try to work with a project in vagrant.我尝试使用 vagrant 中的项目。 I have made the command vagrant ssh , and connected to VM.我已经发出命令vagrant ssh并连接到VM。 Now I need to edit .bashrc file to set path to the source code.现在我需要编辑.bashrc文件来设置源代码的路径。 But first I couldn't find that file.但首先我找不到那个文件。 So I googled and find that the way is call command ~/.bashrc .所以我google了一下,发现方法是调用命令~/.bashrc But doing this I get message, that I have no access to it:但是这样做我会收到消息,我无法访问它:

[vagrant@nupic-vagrant:~]$ ~/.bashrc
-bash: /home/vagrant/.bashrc: Permission denied

So what to do now?那么现在该怎么办呢?

UPD. UPD。 I can't find the.bashrc file.我找不到 .bashrc 文件。 When I try to make command ls -a I get following:当我尝试制作命令ls -a时,我得到以下信息:

[vagrant@nupic-vagrant:~]$ ls -a
.              .bash_logout   cleanup.sh   sshd.sh        .veewee_params
..             .bash_profile  minimize.sh  vagrant.sh     .veewee_version
.bash_history  .bashrc        .ssh         .vbox_version  .zsh_profile
[vagrant@nupic-vagrant:~]$ locate .bashrc
/etc/skel/.bashrc
/home/vagrant/.bashrc
/var/chef/backup/etc/skel/.bashrc.chef-20130614181911
/var/chef/backup/home/vagrant/.bashrc.chef-20130614181912
[vagrant@nupic-vagrant:~]$

But only the place where I can find some of those files is the directory where cygwin is installed.但只有我能找到其中一些文件的地方是安装 cygwin 的目录。 Pls, see illustrations, they reflect relations between directories vagrant and cygwin.请看插图,它们反映了目录 vagrant 和 cygwin 之间的关系。在此处输入图像描述

.bashrc is not meant to be executed but sourced. .bashrc并不是要执行,而是要获取。 Try this instead: 尝试以下方法:

. ~/.bashrc

Cheers! 干杯!

If you want to edit that file (or any file in generally), you can't edit it simply writing its name in terminal. 如果要编辑该文件(或通常的任何文件),则不能仅在终端中写入其名称就不能对其进行编辑。 You must to use a command to a text editor to do this. 您必须使用文本编辑器的命令来执行此操作。 For example: 例如:

nano ~/.bashrc

or 要么

gedit ~/.bashrc

And in general, for any type of file: 通常,对于任何类型的文件:

xdg-open ~/.bashrc

Writing only ~/.bashrc in terminal, this will try to execute that file, but .bashrc file is not meant to be an executable file. 在终端中仅写入~/.bashrc ,这将尝试执行该文件,但是.bashrc文件并不意味着是可执行文件。 If you want to execute the code inside of it, you can source it like follow: 如果要在其中执行代码,则可以按照以下方式获取它的源代码:

source ~/.bashrc

or simple: 或简单:

. ~/.bashrc 

If you can't access the file and your os is any linux distro or mac os x then either of these commands should work: 如果您无法访问该文件,并且您的操作系统是任何linux发行版或mac os x,则以下任何一个命令都应该有效:

sudo nano .bashrc

chmod 777 .bashrc 

it is worthless 这是毫无价值的

The .bashrc file is in your user home directory (~/.bashrc or ~vagrant/.bashrc both resolve to the same path), inside the VM's filesystem . .bashrc文件位于您的用户主目录(〜/ .bashrc或〜vagrant / .bashrc都解析为同一路径)中, 位于VM的文件系统内 This file is invisible on the host machine, so you can't use any Windows editors to edit it directly. 该文件在主机上不可见,因此您不能使用任何Windows编辑器直接对其进行编辑。

You have two simple choices: 您有两个简单的选择:

  1. Learn how to use a console-based text editor. 了解如何使用基于控制台的文本编辑器。 My favourite is vi (or vim), which takes 15 minutes to learn the basics and is much quicker for simple edits than anything else. 我最喜欢的是vi(或vim),它需要15分钟的时间来学习基础知识,并且进行简单的编辑要比其他任何东西都要快得多。

    vi .bashrc vi .bashrc

  2. Copy .bashrc out to /vagrant (which is a shared directory) and edit it using your Windows editors. 将.bashrc复制到/ vagrant(这是一个共享目录)中,然后使用Windows编辑器对其进行编辑。 Make sure not to save it back with any extensions. 确保不要将其与任何扩展名一起保存。

    cp .bashrc /vagrant ... edit using your host machine ... cp /vagrant/.bashrc . cp .bashrc / vagrant ...使用主机编辑... cp /vagrant/.bashrc。

I'd recommend getting to know the command-line based editors. 我建议您了解基于命令行的编辑器。 Once you're working inside the VM, it's best to stay there as otherwise you might just get confused. 在VM中进行操作后,最好留在其中,否则可能会感到困惑。

You (the vagrant user) are the owner of your home .bashrc so you do have permissions to edit it. 您(无业游民的用户)是home .bashrc的所有者,因此您确实有权编辑它。

Once edited, you can execute it by typing source .bashrc I prefer to logout and in again (there may be more than one file executed on login). 编辑后,您可以通过键入source .bashrc来执行它,我更喜欢注销然后再次登录(登录时可能会执行多个文件)。

vim. vim。 bashrc is defined as $PATH=/home/user/NBO/NBO6. bashrc 定义为 $PATH=/home/user/NBO/NBO6。 And then i can not find vim editor.然后我找不到vim编辑器。 Any command, for instance, when exec /home/user/.任何命令,例如,当 exec /home/user/ 时。 bashrc is written, it gives me "access denied". bashrc 是写的,它给了我“拒绝访问”。 İ want to remove this path and to recover my Ubuntu terminal to the previous case.我想删除此路径并将我的 Ubuntu 终端恢复到以前的情况。 What can i do?我能做什么? Pls, write your reply clearly because i am a new Ubuntu user.请写清楚你的回复,因为我是一个新的 Ubuntu 用户。 Thanks谢谢

Please find the step to fix bash restricted error on Linux servers.请在 Linux 服务器上找到修复 bash 受限错误的步骤。

If you are getting below restricted message while try to login to the server by using your credentials, then it might be an issue with lack of directory permissions in the server.如果您在尝试使用您的凭据登录服务器时收到以下受限消息,则可能是服务器中缺少目录权限的问题。

Because of this permission issue we were unable to navigate to required directories and getting error “bash: cd: restricted”由于这个权限问题,我们无法导航到所需的目录并收到错误“bash:cd:restricted”

Fix: To release bash restriction error use the highlighted command in Linux server -bash -f修复:要释放 bash 限制错误,请使用 Linux 服务器中突出显示的命令 -bash -f

As same if wants to restrict the permission use the highlighted command - bash -r同样,如果要限制权限,请使用突出显示的命令 - bash -r

Once you executed the bash -f command the restrictions will be released from the directories and we can able to proceed with patch scripts.一旦你执行了 bash -f 命令,限制将从目录中释放,我们可以继续使用补丁脚本。

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

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