I'm attempting to setup a git repository on my Dreamhost web server by following the "Setup: For the Impatient" instructions here. I'm having difficulty setting up public key access to the server.

After successfully creating my public key, I ran the following command:

cat ~/.ssh/[MY KEY].pub | ssh [USER]@[MACHINE] "mkdir ~/.ssh; cat >> ~/.ssh/authorized_keys"

...replacing the appropriate placeholders with the correct values.

Everything seemed to go through fine. The server asked for my password, and, as far as I can tell, executed the command. There is indeed a ~/.ssh/authorized_keys file on the server.

The problem: When I try to SSH into the server, it still asks for my password. My understanding is that it shouldn't be asking for my password anymore. What am I missing?

EDIT: SSH -v Log:

Macbook:~ michaeleckert$ ssh -v [USER]@[SERVER URL]
OpenSSH_6.2p2, OSSLShim 0.9.8r 8 Dec 2011
debug1: Reading configuration data /etc/ssh_config
debug1: /etc/ssh_config line 20: Applying options for *
debug1: /etc/ssh_config line 53: Applying options for *
debug1: Connecting to [SERVER URL] [[SERVER IP]] port 22.
debug1: Connection established.
debug1: identity file /Users/michaeleckert/.ssh/id_rsa type -1
debug1: identity file /Users/michaeleckert/.ssh/id_rsa-cert type -1
debug1: identity file /Users/michaeleckert/.ssh/id_dsa type -1
debug1: identity file /Users/michaeleckert/.ssh/id_dsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.2
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.5p1 Debian-6+squeeze3
debug1: match: OpenSSH_5.5p1 Debian-6+squeeze3 pat OpenSSH_5*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Host ‘[SERVER URL]' is known and matches the RSA host key.
debug1: Found key in /Users/michaeleckert/.ssh/known_hosts:2
debug1: ssh_rsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/michaeleckert/.ssh/id_rsa
debug1: Trying private key: /Users/michaeleckert/.ssh/id_dsa
debug1: Next authentication method: password
[USER]@[SERVER URL]'s password: 
debug1: Authentication succeeded (password).
Authenticated to [SERVER URL] ([[SERVER IP]]:22).
debug1: channel 0: new [client-session]
debug1: Requesting no-more-sessions@openssh.com
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = en_US.UTF-8

 Welcome to [SERVER URL]

Any malicious and/or unauthorized activity is strictly forbidden.
All activity may be logged by DreamHost Web Hosting.

Last login: Sun Nov  3 12:04:21 2013 from [MY IP]
  • You might be seeing a password prompt for your key and not for the SSH connection. Did you password protect your key when you created it? If so, your local machine – not the server – will ask you for a password ("Enter passphrase for key") when you try to connect to a server using that key. You can only use passwordless SSH logins for keys without a password. (i.e. When creating your key, don't password-protect it. This is less secure, but more convenient – it depends if security or convenience is more important to you.) – Nick Nov 3 '13 at 16:22
  • I didn't password protect my key. I was under the impression that a passwordless-key would work better setting up my server with Git. Am I correct in thinking this? – Nathan Arthur Nov 3 '13 at 16:42
  • You should get password-less login if the key file is unprotected. I've added some things to check below. – Nick Nov 3 '13 at 17:25
  • Looking at the ssh -v log I just added, it seems to have tried "id_rsa" and "id_dsa" before giving up. Why is it trying these file names? Should I name my public key one of these names? – Nathan Arthur Nov 3 '13 at 21:44
  • Turns out I should. See the comments below my answer for more info. – Nathan Arthur Nov 4 '13 at 13:38


On Client side:

  • open configuration file /etc/ssh/ssh_config;
  • here look for PreferredAuthentications;
  • make sure password comes after publickey and not viceversa

In my case password was written before publickey, so ssh would prompt me for password even though I had copied my pub_key onto server.

This problem can be found out easily using verbose:

ssh -v compute@compute1 ... ... debug1: Authentications that can continue: publickey,password debug1: Next authentication method: password

As you can see password is chosen before trying to use publickey.

Edit /etc/ssh/ssh_config by moving password after publickey

PreferredAuthentications keyboard-interactive,publickey,password,hostbased,gssapi-with-mi

Now you can login without being prompt for pwd.


Some things to check:

On the server:

  1. Change the ~/.ssh/authorized_keys file permissions using:
    chmod 600 ~/.ssh/authorized_keys

  2. Change the ~/.ssh/authorized_keys file owner using:
    chown `whoami` ~/.ssh/authorized_keys

  3. Check that the ~/.ssh/authorized_keys file is not empty:
    (cat ~/.ssh/authorized_keys should display some output)

(Steps one and two are recommended in the OpenSSH FAQ.)

On the client

  1. Are you logging in with the same user account as the one you added the key for on the server? (i.e. Is the user in the ssh USER@ip command you're using to connect the same as the USER in the command you copied the file to the server with?)

  2. Connect using SSH verbose mode (ssh -v user@ip) and edit your question to add the output (with any IP addresses, usernames and hostnames masked).

  • I tried server 1 and 3 with no luck yet. Regarding 2: Would this be the same username I'm attempting to login with? Also, what character is that username surrounded with? Client 1: I believe I'm using the same user. 2: I'm going to try that now. PS: +1 for the very actionable answer! – Nathan Arthur Nov 3 '13 at 20:07
  • SSH -v log added to OP. – Nathan Arthur Nov 3 '13 at 20:17

Turns out the solution was very simple: rename my two public key files to id_rsa and id_rsa.pub. I have no idea why this is what they have to be called. Please feel free to edit this answer to make it more informative.

  • 1
    Aha! SSH2 expects key files to be named id_rsa or id_dsa. It will not look for other files unless you explicitly pass the path to the key file with the -file flag. So, if you renamed your key files after creating them or called them something different to begin with, that would explain why you couldn't use key-based authentication. Well done for solving it. You should mark this answer as the correct one so others know your question is solved. – Nick Nov 3 '13 at 23:58

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.