Super User is a question and answer site for computer enthusiasts and power users. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I changed my permissions in my .ssh folder and now when I use a piece of software that uses my private key, I have to type my password each time. What should my permissions be on my id_rsa file to not have to type a password each time I use an app that uses it?

Currently my permissions are set to:

-rw-------@ 1 Jody  staff   114 Nov  4 23:29 config
-rw-------  1 Jody  staff  1743 Oct 21  2009 id_rsa
-rw-------@ 1 Jody  staff   397 Oct 21  2009 
-rw-------@ 1 Jody  staff  3855 Sep 13 22:35 known_hosts
share|improve this question

migrated from Nov 27 '10 at 2:02

This question came from our site for professional and enthusiast programmers.

Typically you want the .ssh directory permissions to be 700 (drwx------) and the public key (.pub file) to be 644 (-rw-r--r--). Your private key (id_rsa) should be 600 (-rw-------).

I am asssuming that you mean that you have to enter your system/user password each time, and that previously you did not have to. cdhowie's response is assuming you set a password/passphrase when generating your keys, and if you did then as he says you will have to enter your password every time unless you use an ssh agent.

share|improve this answer
I found elsewhere that if using the authorized_keys file, that it should be chmod'd to 640, ie -rw-r----- . – AnneTheAgile Sep 11 '14 at 21:19
Where I can find this info in man pages? – Sonique Nov 17 '14 at 15:56
I have come back to this post about 30 times now. I cant believe I cant remember it. – JREAM Apr 2 '15 at 21:35
You can also safely leave the .ssh directory permissions at 755 (drwxr-xr-x), as well as the id_*.pub and authorized_keys permissions at 644 (-rw-r--r--). Otherwise other users cannot lookup your public keys, but being able to do so is often convenient if they need to know your public keys to grant you access to some service. – Markus Kuhn Sep 30 '15 at 11:55
The only important things are that nothing in .ssh is writeable to anyone else and none of the secret keys are readable to anyone else. – Markus Kuhn Sep 30 '15 at 11:56

Also ensure that your home directory is not writeable by other users.

chmod g-w,o-w ~

share|improve this answer
FYI, this command assumes you are logged in as the user and not root – Alex W Jun 9 '15 at 18:40

I was struggling with this forever and finally figured out what is needed. Replace user everywhere with the SSH username you want to log into on the server. If you're trying to login as root you would need to use /root/.ssh etc., instead of /home/root/.ssh which is how it is for non-root users.

  • Home directory on the server should not be writable by others: chmod go-w /home/user
  • SSH folder on the server needs 700 permissions: chmod 700 /home/user/.ssh
  • Authorized_keys file needs 644 permissions: chmod 644 /home/user/.ssh/authorized_keys
  • Make sure that user owns the files/folders and not root: chown user:user authorized_keys and chown user:user /home/user/.ssh
  • Put the generated public key (from ssh-keygen) in the user's authorized_keys file on the server
  • Make sure that user's home directory is set to what you expect it to be and that it contains the correct .ssh folder that you've been modifying. If not, use usermod -d /home/user user to fix the issue
  • Finally, restart ssh: service ssh restart
  • Then make sure client has the public key and private key files in the local user's .ssh folder and login: ssh
share|improve this answer
Regarding your first paragraph, I am able to ssh with public/private keys with a user on my local linux box (e.g. abc), different from the user on the remote server (e.g. def@123.456.789). I just had to make sure the local user owned the local .ssh files (e.g. abc:abc, not root:abc)` – Cosmic DM Dec 22 '15 at 9:41
Thanks for putting all the steps and commands for newbies, Alex. Yours is one of the most helpful answers here. – Nav Mar 4 at 6:06

Permissions shouldn't have anything to do with this. Your private key is encrypted with the password, so you need to enter it for the private key to be decrypted and usable.

You might consider running an ssh agent, which can cache decrypted keys and will supply them to applications that need them.

share|improve this answer
Thanks for the additional info about the ssh agent. Looks like there is one built into Leopard so I think I'll do that. Having a bit of trouble with it but I'll ask another question. – Jody G Nov 26 '10 at 22:18
Do not underestimate permissions. They definitely still come into play. – Alex W May 15 '15 at 19:49
@AlexW They do come into play with other aspects of ssh, but not the one asked about in the question. – cdhowie May 24 '15 at 23:43
If you have no password on private keys (whink of automated remote called scripts), it won't help you. Permissions are necessary here. – nerdoc Jan 7 at 23:13

Felipe is correct -- the directory containing your .ssh directory must not be writeable by group or other. Thus chmod go-w ~ is the next logical thing to try if you are still prompted for a password when ssh'ing after running ssh-keygen -t rsa; cp ~/.ssh/ ~/.ssh/authorized_keys, assuming you don't assign a passphrase in the ssh-keygen command, and your .ssh directory is in your home directory.

share|improve this answer

You must log in to answer this question.

protected by JakeGould Dec 17 '15 at 4:57

Thank you for your interest in this question. Because it has attracted low-quality or spam answers that had to be removed, posting an answer now requires 10 reputation on this site (the association bonus does not count).

Would you like to answer one of these unanswered questions instead?