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, 2014 at 19:36

2 Answers 2


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! Apr 12, 2016 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, 2016 at 17:42

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.

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, 2017 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.