6

When I try to clone a repo I get a git failed with exit code 128.

Also when I try to push/pull I get a git@gitlab.com public key denied.

In my ~/.ssh folder I have a config file that looks like this:

Host mycompany.gitlab.com
    HostName gitlab.com
    User git
    PreferredAuthentications publickey
    IdentityFile ~/.ssh/gitlab-company-bryan

git in the terminal works fine but Sublime Merge I am getting permissions errors.

What do I need to do so that Sublime Uses this public key? I'm super confused and get it to work at the moment.

bryan
  • 8,879
  • 18
  • 83
  • 166
  • What version of Git are you using from the terminal (where it is working)? – VonC Dec 11 '18 at 06:03
  • @VonC `git version 2.19.2` – bryan Dec 11 '18 at 15:18
  • Does `~/.ssh/gitlab-company-bryan` have 64 or 70 characters per line? – VonC Dec 11 '18 at 15:21
  • @VonC there is 70 characters per line – bryan Dec 11 '18 at 15:30
  • OK, then I know why (see https://stackoverflow.com/a/53645530/6309). But I can post an answer in two hours only. In the meantime, try and regenerate a private key with `ssh-keygen -m PEM -t rsa -P "" -f mynewkey`, and try again – VonC Dec 11 '18 at 15:35
  • @VonC unfortunately, from a Sublime Merge standpoint, that still did not fix the issue. Both keys I've generated work inside the terminal still, but not via the app. One is 64 and one is 70 characters in each line. Might have an issue to do with having a password but I really don't know – bryan Dec 11 '18 at 15:43
  • Yes, try a with my command: no passphrase to enter. – VonC Dec 11 '18 at 15:44
  • See also https://forum.sublimetext.com/t/sublime-merge-ssh-failing-when-key-has-password/40779/8 – VonC Dec 11 '18 at 15:45
  • @VonC that is my forum post that no one has answered. it always worked without a password. The issue I am trying to solve is doing it WITH a password. – bryan Dec 11 '18 at 15:47
  • Then you need an ssh-agent. Which one do you have set when working from command line? – VonC Dec 11 '18 at 15:48
  • @VonC both work via the command line (64/70 characters). With and without passwords. I just trying doing the following command and I finally got it working. `ssh-add -K ~/.ssh/[your-private-key]`. Thank you for pointing me in the right direction. Feel free to add my above line of code in your answer's explanation and I'll gladly accept it. – bryan Dec 11 '18 at 15:53
  • I will add an answer in about an hour. – VonC Dec 11 '18 at 15:58

2 Answers2

6

git in the terminal works fine but Sublime Merge I am getting permissions errors.

First:

The private key has been generated with Git 2.19.2, meaning an openssh 7.8+, which has just changed its private key default format, from PEM (64 characters per lines) to "OPENSSH" (70 characters per lines).
See "Jenkins: what is the correct format for private key in Credentials"

Try and regenerate a private key (and register it on GitLab), but this time with:

ssh-keygen -m PEM -t rsa -P "" -f mynewkey

That is to rule out any interpretation error of that key by Sublime Merge.

Second, as the OP discussed here, SSH private keys with passphrase don't seem to be supported, unless the ssh-agent is properly configured to cached said passphrase.

KeyChain on macOS handles everything for me (without any ssh config; I'm still using the default id_rsa for all of my repos).

The OP bryan confirms in the comments:

I finally got it working with:

ssh-add -K ~/.ssh/[your-private-key]

As explained on GitHub:

The -K option is in Apple's standard version of ssh-add, which stores the passphrase in your keychain for you when you add an ssh key to the ssh-agent.

VonC
  • 1,262,500
  • 529
  • 4,410
  • 5,250
  • Great explanation Von, thank you for taking the time to write this up! I appreciate the help. – bryan Dec 11 '18 at 19:26
  • for some reason doing the `ssh-add -K` keeps expiring. Meaning I have to run this command every couple of days for some reason. Do you know how to make this permanent? – bryan Dec 27 '18 at 15:23
2

For those interested, I got it working on Ubuntu 18.04 by first starting ssh-agent from the command line, then add my key to ssh-agent using the 'ssh-add' command, and then from within the same opened tty, launch Sublime Merge on the current directory with the following command: smerge . &

This way, every time Sublime Merge is using your ssh key, the ssh-agent process running in the background will handle the password entering for you.

VeagleEye
  • 21
  • 1