I set the lines PasswordAuthentication yes and PubkeyAuthentication yes in /etc/ssh/sshd_config. I also disabled root login for security purposes. I can now SSH with a user's password without specifying my private key. However I am now unable to deploy over ssh to my server from a script because I would need to specify the password. Therefore I would like the option to ssh into my server without a password by just specifying the private key. However I am always being asked for the password, even if I pass the private key to the -i option. How can I set this up?

Please note that this is not a passphrase associated with the private key, but rather the password associated with the user. It's the password created with the passwd command.

  • Please look in your log file, obviously you have something misconfigured. – NickW May 24 '13 at 16:25
  • @NickW Can you please explain? – Justin Meltzer May 24 '13 at 16:27
  • If it is a passwordless private key, you will not get a password prompt, unless you either 1. created a private key with a password or 2. have wrong permissions on a file, or put a carriage return in the public key, or one of many things the log will tell you about quite quickly. – NickW May 24 '13 at 16:31
  • @NickW I really don't think it's the passphrase attached to the private key but rather the password that is associated with the user account. It's the password that was created by running the passwd command. – Justin Meltzer May 24 '13 at 16:32
  • When you used ssh-keygen, did you put a password in? If not, just look at /var/log/secure (or the log for sshd on your system) it will have a fairly descriptive error message. – NickW May 24 '13 at 16:34

If the SSH key isn't passphrase locked, the most likely problem is permissions on the destination user's ~/.ssh directory or ~/.ssh/authorized_keys (or ~/.ssh/authorized_keys2) file. I usually set those 600 and 644 respectively, and things work for me.

  • Yeah, I think this is it. The .ssh folder is actually only in the root user's home and not in the user's home that I'm using for SSH. The .ssh folder has 700 right now so that would explain the password. Would you recommend changing it to 777 since I disabled root ssh, or should I instead change the owner of the directory to the new user and make it 700? – Justin Meltzer May 24 '13 at 16:38
  • If you're going to log in as a user, that user needs to have a .ssh/ directory, and an authorized_keys file with the permissions that John suggested. The authorized keys file needs to contain the contents of the public part of the key. – NickW May 24 '13 at 16:43
  • @NickW Ok so I can just copy the authorized_keys file from the root directory? – Justin Meltzer May 24 '13 at 16:44
  • Yeah, just chown it to the new user, and chmod it 644. – NickW May 24 '13 at 16:48
  • 1
    NEVER set ~/.ssh or any contents to 777. That's bad juju. You should have a /root/.ssh directory and a /root/.ssh/authorized_keys file - if SSH'ing as root works, copy the authorized_keys file to /home/$USER/.ssh/, make sure the permissions are the same, and you should be good to go. – John May 24 '13 at 16:48

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.