.bashrc: Permission denied
Asked Answered
R

7

28

I try to work with a project in vagrant. I have made the command vagrant ssh, and connected to VM. Now I need to edit .bashrc file to set path to the source code. But first I couldn't find that file. So I googled and find that the way is call command ~/.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. I can't find the .bashrc file. When I try to make command ls -a I get following:

[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. Pls, see illustrations, they reflect relations between directories vagrant and cygwin. enter image description here

Reaper answered 2/11, 2013 at 12:43 Comment(0)
S
44

.bashrc is not meant to be executed but sourced. Try this instead:

. ~/.bashrc

or, equivalently

source ~/.bashrc

See the reference about the . (aka source) builtin.


Note that if what you're looking for is to restart your Bash session after modifying your ~/.bashrc file, you might as well use:

exec bash

That will replace your current Bash session (thanks to exec) by a new session.

Spracklen answered 2/11, 2013 at 12:44 Comment(6)
I did it, but seems that happend nothing. Just shows me next input: **[vagrant@nupic-vagrant:~]$ ** so how to get it edited?Reaper
@Reaper Nothing seems to happen, but it was sourced! To edit it, errr, just edit it with your favorite editor. If you like vim, just do vim ~/.bashrc if you like nano just do nano ~/.bashrc and if you like ed, you probably know what to do :).Spracklen
Yes, it looks very stupid, I know. But I never worked with vagrant, linux env etc. I never faced situation when a file exists but I can edit it only after running some text editor from command line. Pls, consider that I worked only on Windows. I have some editors here like notepad++ but have no idea how to use it in command line. Should I set a path variable to make it possible?Reaper
@Reaper It's just a regular file, edit it with the editor you like best! you don't need any command line at all to edit it. Just locate it in you explorer and edit it.Spracklen
I can't see that file (.bashrc). I checked whole vagrant directory. Or it may be somewhere else? If I try command ls (or dir) it shows me only those: cleanup.sh minimize.sh sshd.sh vagrant.shReaper
@Reaper In a linux environment, you'd need ls -a to show hidden files. You could also locate .bashrc. But very likely, .bashrc is located in user's home dir: cd; ls -a should get you there and show you the file.Spracklen
H
26

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. If you want to execute the code inside of it, you can source it like follow:

source ~/.bashrc

or simple:

. ~/.bashrc 
Haggis answered 2/11, 2013 at 12:55 Comment(6)
I have no nano/gedit. And my OS is windows. If understand right this can work if those editors' paths are set in env path variables? Or there is some another way to reach result?Reaper
both of command that you pointed out lead to nothing - it just shows me the next input line.Reaper
Try xdg-open ~/.bashrc. ...You should have an text editor installed.Trifle
[vagrant@nupic-vagrant:~]$ . ~/.bashrc [vagrant@nupic-vagrant:~]$ xdg-open ~/.bashrc /usr/bin/xdg-open: line 402: htmlview: command not found /usr/bin/xdg-open: line 402: firefox: command not found /usr/bin/xdg-open: line 402: mozilla: command not found /usr/bin/xdg-open: line 402: netscape: command not found /usr/bin/xdg-open: line 402: links: command not found /usr/bin/xdg-open: line 402: lynx: command not found xdg-open: no method available for opening '/home/vagrant/.bashrc'Reaper
@Reaper What about: nano ~/.bashrc or vi ~/.bashrc or vim ~/.bashrc or ed ~/.bashrc or joe ~/.bashrc or pico ~/.bashrc... Ther should be one editor installed. If not, try to install one.Trifle
[vagrant@nupic-vagrant:~]$ ed ~/.bashrc Newline appended 464Reaper
S
12

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:

sudo nano .bashrc

chmod 777 .bashrc 

it is worthless

Strangles answered 2/11, 2013 at 21:59 Comment(0)
T
0

The .bashrc file is in your user home directory (~/.bashrc or ~vagrant/.bashrc both resolve to the same path), inside the VM's filesystem. This file is invisible on the host machine, so you can't use any Windows editors to edit it directly.

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 .bashrc

  2. Copy .bashrc out to /vagrant (which is a shared directory) and edit it using your Windows editors. Make sure not to save it back with any extensions.

    cp .bashrc /vagrant ... edit using your host machine ... 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.

You (the vagrant user) are the owner of your home .bashrc so you do have permissions to edit it.

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).

Transilluminate answered 9/11, 2013 at 16:20 Comment(0)
D
0

Please find the step to fix bash restricted error on Linux servers.

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”

Fix : To release bash restriction error use the highlighted command in Linux server -bash -f

As same if wants to restrict the permission use the highlighted command - 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.

Drobman answered 21/8, 2022 at 19:53 Comment(0)
P
0

There all your nvm already installed. please check on the current bash you are on and rename it and make sure you use that bash(terminal).Please detail here

Parfleche answered 7/1 at 3:35 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Mellins
K
-1

Your current user dont have permission to access ~/.bashrc

Kindly provide access to that for the user who need to login

sudo chown -R <user1> /home
sudo chmod 766 /home

Here in first command we are reassigning home directory's owner and in next command we're providing access permission for that directory to that user

Kickapoo answered 24/6 at 10:26 Comment(1)
Suggesting to change whole /home ownership is a nonsense. Even suggesting to do it on users' own home dir would be, while we are discussing a single file.Supplemental

© 2022 - 2024 — McMap. All rights reserved.