0

I followed the instructions here in order to set up a private git server on my Amazon EC2 instance. However, I am having problems when trying to SSH into the git account. Specifically, I get the error "Permission denied (publickey)."

Here are the permissions of my files/folders on the EC2 server:

drwx------ 4 git git 4096 Aug 13 19:52 /home/git/
drwx------ 2 git git 4096 Aug 13 19:52 /home/git/.ssh
-rw------- 1 git git  400 Aug 13 19:51 /home/git/.ssh/authorized_keys

Here are the permissions of my files/folders on my own computer:

drwx------  5 CYT  staff   170 Aug 13 14:51 .ssh
-rw-------  1 CYT  staff  1679 Aug 13 13:53 .ssh/id_rsa
-rw-r--r--  1 CYT  staff   400 Aug 13 13:53 .ssh/id_rsa.pub
-rw-r--r--  1 CYT  staff  1585 Aug 13 13:53 .ssh/known_hosts

When checking my logs in /var/log/secure, I used to get the following error message every time I tried to SSH:

Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys

However, after making a few permission changes, I no longer get this error message. Despite this, I am still getting the "Permission denied (publickey)." message every time I try to SSH.

The command I am using to SSH is ssh -T git@my-ip.

Here is the full log I get when I run ssh -vT git@my.ip:

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: Connecting to my-ip [my-ip] port 22.
debug1: Connection established.
debug1: identity file /Users/CYT/.ssh/id_rsa type -1
debug1: identity file /Users/CYT/.ssh/id_rsa-cert type -1
debug1: identity file /Users/CYT/.ssh/id_dsa type -1
debug1: identity file /Users/CYT/.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_6.2
debug1: match: OpenSSH_6.2 pat OpenSSH*
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5-etm@openssh.com none
debug1: kex: client->server aes128-ctr hmac-md5-etm@openssh.com 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 08:ad:8a:bc:ab:4d:5f:73:24:b2:78:69:46:1a:a5:5a
debug1: Host 'my-ip' is known and matches the RSA host key.
debug1: Found key in /Users/CYT/.ssh/known_hosts:1
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
debug1: Next authentication method: publickey
debug1: Trying private key: /Users/CYT/.ssh/id_rsa
debug1: Trying private key: /Users/CYT/.ssh/id_dsa
debug1: No more authentication methods to try.
Permission denied (publickey).

I have spent a few hours going through threads on various sites, including SO and SF, looking for a solution. It seems that the permissions for my files are all okay, but I just can't figure out the problem. Any help would be greatly appreciated.

Edit:

EEAA: Here are the outputs you requested:

$ getent passwd git
git:x:503:504::/home/git:/bin/bash

$ grep ssh ~git/.ssh/authorized_keys | wc -l
grep: /home/git/.ssh/authorized_keys: Permission denied
0
  • @EEAA Please see the updated post. Thanks for your help. – Charles Aug 13 '14 at 20:48
  • @EEAA it returns "1" and that's it. – Charles Aug 14 '14 at 1:20
  • 1
    Are you sure you added the public key to authorized_keys properly? The keys should be one line per key... – EEAA Aug 14 '14 at 2:10
  • Yes, as you can see they are the same character length. I've doubled checked, both are on one line and the same. – Charles Aug 14 '14 at 4:10
1

I should have checked the logs more carefully. The location of my SSH key was not specified correctly. I used SSH -i to specify the correct directory and was able to successfully SSH.

0

This error

Authentication refused: bad ownership or modes for file /home/git/.ssh/authorized_keys

usually means that the permissions along the path chain are such that not only root and the server-side user ('git') could alter /home/git/.ssh/authorized_keys, but someone else too.

Whenever i have seen this error it turned out that either the authorized_keys file itself, or one of its parent directories was e.g. group- or world-writable. You listed the perms for /home/git/.ssh and /home/git, but not for /home and / !

You can relax this requirement by setting "StrictModes=no" serverside, see sshd_config(5)

0

This is the line with problem:

-rw-r--r--  1 CYT  staff   400 Aug 13 13:53 .ssh/id_rsa.pub

Your id_rsa.pub is public readable, and it would not be. Just chmod 600 .ssh/id_rsa.pub and it would work.

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.