2

I'm using the (relatively) new Git sshCommand:

git config core.sshCommand  'ssh -i ~/Documents/keydir/key.pem'

This results in the following config:

sshCommand = ssh -i ~/Documents/keydir/key.pem

But when I try to push to the server (btw I'm using the home directory. Does it have to be the www directory?)

[remote "origin"]
        url = ssh://ubuntu@myserver.com:22/home/ubuntu/myrepo.git

or

[remote "origin"]
            url = ssh://ubuntu@myserver.com/home/ubuntu/myrepo.git

It returns the:

git push remote master
fatal: 'remote' does not appear to be a git repository
fatal: Could not read from remote repository.

...error.

Haven't been able to figure it out.

I've tried using "~/myrepo.git" and "/home/ubuntu/myrepo.git" and I've also tried "url = ssh://ubuntu@myserver.com:/home/ubuntu/myrepo.git"

I've also tried starting a new git in the /var/www folder...

Nothing seems to work. And the myrepo.git is definitely there in the ubuntu home folder.

Any ideas?

EDIT: My complete .git/config file:

[core]
        repositoryformatversion = 0
        filemode = true
        bare = false
        logallrefupdates = true
        ignorecase = true
        precomposeunicode = true
        sshCommand = ssh -i ~/Documents/keydir/key.pem
[remote "origin"]
        url = ssh://ubuntu@myserver.com:22/home/ubuntu/mygit.git
        fetch = +refs/heads/*:refs/remotes/origin/*

EDIT: Updating both local (2.5.4) and remote (2.7.4) versions of Git to the latest version (2.16.1) solved the problem.

mystic cola
  • 1,465
  • 1
  • 21
  • 39

2 Answers2

0

I believe your git push command (“git push remote master“) is incorrect.

Try using git push origin master instead.

(You may also need to verify that the myrepo.git file is actually a git repo, initialized by the git command. The URL you’ve specified seems to follow the correct format as specified in the docs.)

Scott Swezey
  • 2,147
  • 2
  • 18
  • 28
0

You need first to check if you can ssh to that server:

ssh -Tv -i ~/Documents/keydir/key.pem ubuntu@myserver.com

In other words, you must make sure the key.pub public key to the ~ubunutu/.ssh/authorized_keys file.

Then the command must be:

 git push -u origin master

This is only for the first time you will push that branch: see "Why do I need to explicitly push a new branch?"

The URL is correct: adding or removing the port 22 does not matter, since it is the default SSH port.

As per discussion, both ends (local and remote) uses a fairly old version of Git (2.5.4 on MacOS and 2.7.4 on Ubuntu).
Upgrading them both has helped.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • I can "ssh -i" into the server just fine. But with "git push -u origin master" I'm getting: "Permission denied (publickey)."... which I don't get given that I can ssh onto the server just fine. Do I need to make a different key from the pem? Or is it because I'm in the home folder... or... – mystic cola Jan 27 '18 at 06:42
  • Do you have a GIT_SSH_COMMAND environment variable set? (https://git-scm.com/docs/git-config#git-config-coresshCommand) Or a GIT_SSH one (https://git-scm.com/docs/git#git-codeGITSSHcode) – VonC Jan 27 '18 at 06:44
  • ssh command is setup exactly like I had it in the question. sshCommand = ssh -i ~/Documents/keydir/key.pem – mystic cola Jan 27 '18 at 06:50
  • @mysticcola My point: what you have setup in your question would be overridden by an environment variable. Hence my question. – VonC Jan 27 '18 at 06:51
  • In that case the answer is "not to the best of my knowledge." I would flat-out say "no"... because I never set that... then again it's a used laptop so I can't be sure. I'd bet on "no" though. Is there a way I can check? – mystic cola Jan 27 '18 at 06:55
  • @mysticcola What is your local OS and Git version? The command `env` should help seeing environment variables. – VonC Jan 27 '18 at 06:58
  • Let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/163996/discussion-between-mystic-cola-and-vonc). – mystic cola Jan 27 '18 at 07:01