-1

Hey guys I am just wondering why this bellow command will not work:

Nicholass-MBP:~ nicholasmaddren$ sudo cd ~/.ssh

So I run this command within terminal to try and access the .shh folder that has one of my private keys in.

I then run pwd to make sure I am in this folder:

Nicholass-MBP:~ nicholasmaddren$ pwd

However I am left with this result that means that I am not in that directory so I cant select my SHH key.

/Users/nicholasmaddren

Could someone just shed a little bit of light on this for me I would much appreciate it.

Thanks, Nick

2 Answers 2

0

Just curious. Why would you want to sudo into a folder in your home directory in the first place? Sudo is for accessing folders not owned by you, among other things (Super User Do)...

0

(None of this answer is Mac OSX specific, but is how BSD/Unix works. Since Mac OSX/Darwin is based on BSD/Unix, this is expected to apply and work fine for you, and would also apply to other Unixes.)

Yeah... the results you report are exactly what are expected.

Here's what happened: You ran "sudo". The "sudo" command tried to run "cd ~/.ssh", which probably failed because "cd" is an internal command. To make that command work, which won't accomplish what you are trying to do, you could use:

sudo -c ${SHELL} "cd ~/.ssh"
Then, the sudo command exits, and so you're back in your current directory, giving you the unwanted results you're getting.

You should have access to your own home directory, so your solution is to just drop the word "sudo", which helps you with permissions. If you were trying to get to another user's directory, you would probably want to create a sub-shell, so you would use:

sudo -c ${SHELL} "cd ~anotherUser/.ssh"

Then, your prompt will likely change to have a # instead of a $, since sudo gave you superuser privileges. When you're done doing your "rootly" things, type "exit" to change your prompt back to being unprivileged, showing a $ instead of a #.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .