Take the 2-minute tour ×
Webmasters Stack Exchange is a question and answer site for pro webmasters. It's 100% free, no registration required.

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: Server host key: RSA [STRING OF NUMBERS AND LETTERS SEPARATED BY SEMI-COLONS]
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_REQUEST sent
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]
[[SERVER NAME]]$ 
share|improve this question
    
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
add comment

2 Answers

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).

share|improve this answer
    
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
add comment
up vote 1 down vote accepted

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.

share|improve this answer
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
    
Ok, that makes a lot of sense now. Thanks for the clarification. I'm going to have to wait until tomorrow to accept the answer due to webmaster.se's restriction. –  Nathan Arthur Nov 4 '13 at 13:36
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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