2

I know that a lot of similar questions exist here (and I read a lot of them before posting this one), but this one is different, so please stay with me for a while.

Few days ago I configured my remote git repository on amazon ec2. After hours of struggling I made it working and was able to push files there. I was working with it for a day or two pushing resources to it without any problems (I saw every update properly).

Today, for some reason I can not push anything to it from my local machine.

git push deploy ends up with the following error message (the same one I see when I try to get info about deploy: git remote show deploy):

warning: push.default is unset; its implicit value is changing in
Git 2.0 from 'matching' to 'simple'. To squelch this message
and maintain the current behavior after the default changes, use:

  git config --global push.default matching

To squelch this message and adopt the new behavior now, use:

  git config --global push.default simple

See 'git help config' and search for 'push.default' for further information.
(the 'simple' mode was introduced in Git 1.7.11. Use the similar mode
'current' instead of 'simple' if you sometimes use older versions of Git)
Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

The first part of it (before permission denied) I was able to see previously, but it was still pushing everything correctly back then.

Deploy exist because I can clearly see it with git remote -v:

deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)
deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (push)

I can correctly ssh to my server, also my private key has 0400 permissions. On both machines I have ubuntu 12.04 LTS.

I thought that may be there is some problem with my public key, so I went ahead and recreate it from private key: ssh-keygen -y -f key.pem > key.pub. Based on its sha it is identical to my previous public key: sha1sum key_prev.pub = sha1sum key.pub

I still went to the server and added a new key to authorized keys as well.

Still no changes. I can not push anything. Can anyone tell me what is the problem here and why it happened? Do I need to do anything with my local .ssh/known_hosts?

Also in one of the answers I found the following:

Please note that after restarting the instance, the dns name changed. I fell for this several times. The keyfile was still valid, but the "servername" changed.

I actually restarted my machine, so I think this is highly relevant. The problem is that I can not understand what should I change now.

After reading the answer of VonC.

I can not ssh to the server by doing ssh ubuntu@X.X.X.X (I got Permission denied (publickey).), but I can do this with ssh myAlias, where myAlias is defined in ~/.ssh/config

Host            myAlias
Hostname        X.X.X.X
User            ubuntu
IdentityFile    path/to/mypem/file.pem

When I have done git config --global push.default simple I have another problem when doing git push deploy:

fatal: The current branch master has no upstream branch. To push the current branch and set the remote as upstream, use

git push --set-upstream deploy master

I will try to do ssh -Tvv ubuntu@X.X.X.X and will tell how it goes.

Salvador Dali
  • 214,103
  • 147
  • 703
  • 753
  • When you get `Permission denied ` what is the log generated at `/var/log/auth.log` on your instance? – clement Mar 30 '14 at 03:51
  • @clement89 Here the output of tail. `timestamp username CRON[31495]: pam_unix(cron:session): session opened for user root by (uid=0) timestamp username CRON[31495]: pam_unix(cron:session): session closed for user root`. – Salvador Dali Mar 30 '14 at 04:10

1 Answers1

2

First, do yourself a favor, and type git config --global push.default simple in order to not see the first part of the error.

Second, if you can login successfully with ssh ubuntu@X.X.X.X, then your keys are fine, as well as the instance name.

If you can not, you can:

  • try a ssh -Tvv ubuntu@X.X.X.X to see what is going one, and
  • verify that by going to the server, stopping sshd and restarting it in debug mode (/usr/sbin/sshd -d): it will receive only one ssh connection: try a ssh ubuntu@X.X.X.X from your client, and you should see the sshd response.
    Then restart sshd normally.

In your case, you have to use your alias, defined in ~/.ssh/config, since your key isn't a standard one.

For the push to go smoothly, do a git push -u deploy master.

Since git remote -v returns:

deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (fetch)
deploy  ssh://ubuntu@X.X.X.X/home/ubuntu/repo (push)

That means you are not using the ssh alias.

Type:

git remote set-url deploy myAlias:/home/ubuntu/repo

(The syntax is important: myAlias: followed by the repo path)

And then try again the git push.

Community
  • 1
  • 1
VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • `ssh -Tvv myAlias` is working correctly, `git push -u deploy master` generates the same error with permission denied. – Salvador Dali Mar 30 '14 at 07:31
  • this is amazing, this fully solved the problem. Thank you. Can you please explain why your magic works? The thing is that I previously was able to everything with my previous `git push`. – Salvador Dali Mar 30 '14 at 08:30
  • 1
    @SalvadorDali your ssh url must use an scp syntax (as in http://stackoverflow.com/a/14423667/6309) if you want your `~/.ssh/config` to be taken into account, as I mentioned in http://stackoverflow.com/a/20596571/6309. – VonC Mar 30 '14 at 08:32