11

When I type in cd .ssh in terminal, it returns with -bash: cd: .ssh/: Permission denied. Now I cannot add my ssh keys to ssh.

When I type ssh-add ~/.ssh/idname it says /Users/Dan/.ssh/idname: Permission denied.

I think it has to do with me typing ls -d because it worked before I typed this into terminal?

  • What is the output of id;ls -ld ~/.ssh? – michas Jul 23 '14 at 19:36
23

Since you have "Permission denied" on a directory, it is likely that the directory does not have execute permissions. Similarly, to traverse a directory tree to get at a file, you would need execute permissions on each directory in between the root and the file (hence the same error for the other command).

Try setting the execute permissions on the directory

chmod u+xr,go-rwx ~/.ssh

Then see if you can run those statements again.

  • Such an easy and elegant command. Worked right away on my Mac! – IgorGanapolsky Apr 12 '16 at 15:41
  • a drawback of chmod u+xr,go-rwx is how the user needs to confirm which settings need to be added or subtracted beforehand. on the other hand, it is more comprehensive than using a number code, e.g. chmod 1755 . – noobninja Jun 9 '16 at 17:42
1

In addition to Arcege's answer, you can also use
sudo su <enter password> cd .ssh
The sudo command (without another user name) allows you to run commands as the super-user (root), provided you are a sudo-er (your user name is in /etc/sudoers with the correct fields) and know the password to that sudo-enabled user.

Warning:
Operating as the super-user may be dangerous if you don't know what you're doing. You may inadvertently modify or destroy essential files. Use sudo with caution.

  • Yes, this worked when chmod wouldn't do the trick. – Pro Q May 11 '17 at 5:10

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.