sudo open -e ~/.bash_profile Permission denied mac - macos

I am trying to edit bash_profile file to add path to my sdk through the following command on my mac machine.
sudo touch ~/.bash_profile; open -e ~/.bash_profile
It opens the file in TextEdit but does not allow me to edit it. Though i have given super-user permission and password while running the above command. It is giving me following message when i try to edit it.
"You don’t own the file “.bash_profile” and don’t have permission to write to it.
You can duplicate this document and edit the duplicate. Only the duplicate will include your changes."
I am new to mac. So please elaborate your answers.

The problem is that the file isn't owned by your user, but by root. You need to change the owner of the file to your user, then you can open and edit the file without the use of sudo:
sudo chown farheen ~/.bash_profile
This will, as the super-user, change the owner of the file back to you.

For Mac User Catalina,
.bash_profile not open, they need grant permission to edit this file. You can achieve by below steps
1) Open the terminal and enter below command ex: sudo chown iMac ~/.bash_profile
sudo chown {your username} ~/.bash_profile
2) Open editor in the terminal, here i used nano
nano .bash_profile
3) Edit your text you want.
4) To save the changes you've made, press Ctrl + O
5) To exit nano, press Ctrl + X
6) And finally to load your changes, enter below command
source .bash_profile

OR
You can give permission and make it executable file using like below:
That error likely means that 'bash_profile' isn't executable. If it's in the current directory, you can make it executable with chmod +x bash_profile.

Related

./bashrc permission denied on windows10

I have a ubuntu on windows10, and I have added some alias to ./bashrc
But then when I reopened ubuntu the colors of the text are all gone with -bash: /home/chikuma/.bashrc: Permission denied shown at the first line.
Typing bash also got denied.
I deleted all the stuff I've added in ./bashrc but it didn't make any changes.
What is happening ??
Windows 10 does not know about file permissions in Ubuntu subsystem.
If you want to edit .bashrc just use native Ubuntu nano or vim code editors.
To open .bashrc use:
sudo nano .bashrc
To set file permissions:
chmod 644 .bashrc
This permissions is equal to
rw-r--r--

How to open file as root in GUI text editor on mac os

I need all my files in certain directory to be accessible only by root. So I do the chown and chmod commands to set privileges to 700 template where file owner is root. After that if I open files with nano everything works ok: if I run it with sudo I can see contents of files and edit it; if not root then I can see just an empty file which I can't edit or modify. Then I try to open files with Sublime2 as subl 1.txt. With or without sudo it just appears to show an empty file. Then I try sudo open 1.txt to open with the default TextEditor and then I see a message that I don't have permissions. The same if I try anything like sudo open -a (any other text editor from my apps) 1.txt the permissions message is shown. I've tried to google for gksu for mac but people say that sudo is enough. Please guys, any ideas on the topic are welcome. Thank you much!

How to set .bash_profile, if it does not exist yet. I want to launch sublime from a command line in Mac

I want to launch sublime from a command line in Mac, using subl filename. It seems to involve dealing with .bash_profile. But I didn't locate the file. What steps to be taken?
A typical install of OS X won't create a .bash_profile for you. When you want to run functions from your command line, this is a must-have.
Start up Terminal
Type cd ~/ to go to your home folder
Type touch .bash_profile to create your new file.
Edit .bash_profile with your favorite editor (or you can just type open -e .bash_profile to open it in TextEdit.
Type . .bash_profile to reload .bash_profile and update any functions you add. Notice the space between the two dots!
Update
I'm on Mac OS Mojave.
Open Terminal.app and paste bellow line,
(1) touch .bash_profile
(2) open -a TextEdit.app .bash_profile
this will open a blank page in TextEdit.app , from here you can add,update,delete code.
I hope this will help someone.
just create a new file - it doesn't come default with your computer. all under your user directory - ex. /Users/username
touch .bash_profile
~/.bash_profile
Q1. How to check if .bash_profile exists or not in my mac?
Solution: If you're using macOS 10.14 (Mojave) or below. Then open the Terminal.app. Run the following command to check if the .bash_profile exists or not in your mac.
if [ -r ~/.bash_profile ];
then
echo "Yes, file exists"
else
echo "No, file does not exists"
fi
After running the above command if you get the following line - "Yes, file exists" printed in your Terminal.app. That means the file exists in your mac.
If you get the following line - "No, file does not exist" printed in your Terminal.app. That means the file does not exist in your mac.
To create a .bash_profile file in your mac. Run the following command,
touch ~/.bash_profile
To restrict access to the .bash_profile. Run the following command,
chmod 700 ~/.bash_profile
Q2. I want to launch sublime from a command line in Mac?
Solution: To launch sublime from mac. You can make a symlink to subl. Assuming you've placed Sublime Text in the Applications folder, and that you have a ~/bin directory in your path, you can run the following command:
ln -s "/Applications/Sublime Text.app/Contents/SharedSupport/bin/subl" ~/bin/subl
For more details visit the official sublime documentation

-bash: /Users/myname/.bash_profile: Permission denied

I installed rvm (ruby version manager) and it was success, but I got
WARNING: You have '~/.profile' file, you might want to load it, to do
that add the following line to '/Users/myname/.bash_profile': source
~/.profile
I am new to developing, terminals and all that jazz! But better late than never?!
I entered into terminal:
'/Users/myname/.bash_profile'
and got back the following line
-bash: /Users/myname/.bash_profile: Permission denied
myname-MacBook-Pro:~ myname$
And that is where I am stuck! I need vrm for Drupal (Omega development) and want to make sure that everything is working fine. Thanks for your help.
Enter the .bash_profile file by running this in your terminal:
vim ~/.bash_profile
If you still get permission denied, run sudo before the vim command
sudo vim ~/.bash_profile
From there , press insert button . then add the text source ~/.profile to .bash_profileand press esc and then hit :x on your keyboard to save and close the file. Opening a new terminal window should remove the error.
Entering a filename will try to execute it. Instead, you want to edit it.
Open TextEdit (or your favorite editor) and open the file /Users/myname/.bash_profile in it.
You can do this entirely through the UI, but if you want, you can start an editor from the terminal:
open -a TextEdit /Users/myname/.bash_profile
You can then add the line source ~/.profile to the file and save it.
Close the terminal and open it again to apply the changes.
In my issue when I try with ssh on server, I get this error :
-bash: /home/user/.bash_logout: Permission denied
for resolved your user home directory must has a execute permission.
chmod +x <user_home_directory>
you must relogin next. If you add .profile
export PATH+=:$HOME/bin
without .bash_profile as I do all time you'll insert ~/bin search dir not the end of PATH and in middle. So .profile call before local profile formed and some others system dirs will be added after. It's bad so priority for you home binaries will higher then some system one. And may change undesired behavior with same names. So you need to add PATH in .bash_profile, not to .profile It's guarantee to add your home bin dir at the end of PATH. But don't delete ~/.profile at all. It's need to add some other data. This file call once at first login and .bash_profile call every time when second login with su without -l and then return back. If don't bother You will get two home bin dirs in PATH, next tree and so on. It's not well. So you must correct like that:
p=:$HOME/bin && test `expr $PATH : '.*'"$p"` -gt 0 || export PATH+=$p || true
It's grantee that home bin dir will add only one independent how many times you login after change effective user with su and then return back.
true at end better write so if on some unpredictable reasons error occurs in
command export PATH+=$p(sometimes such occurs) your profile load stops and you can't login at all. It's grantee that this line will run with any error generate.

.bashrc: Permission denied

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

Resources