Невозможно получить доступ к папке .shh в терминале

386
Christopher

Эй, ребята, мне просто интересно, почему эта нижеуказанная команда не будет работать:

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

Поэтому я запускаю эту команду в терминале, чтобы попытаться получить доступ к папке .shh, в которой есть один из моих закрытых ключей.

Затем я запускаю pwd, чтобы убедиться, что я нахожусь в этой папке:

Nicholass-MBP:~ nicholasmaddren$ pwd 

Однако я остаюсь с этим результатом, что означает, что я не в этом каталоге, поэтому я не могу выбрать свой ключ SHH.

/Users/nicholasmaddren 

Может ли кто-то просто пролить немного света на это для меня, я был бы очень признателен.

Спасибо ник

-1

2 ответа на вопрос

0
cseder

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
TOOGAM

(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 $ "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 $ "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 #.

Похожие вопросы