Filter löschen
Filter löschen

SSH Key for GitHub not working (MacOS)

9 Ansichten (letzte 30 Tage)
Javier Montemayor
Javier Montemayor am 19 Jan. 2019
Kommentiert: Renato Busatto am 19 Feb. 2021
I've done what's stated in this post to enable GitHub auth without having to enter username and password over and over https://www.mathworks.com/matlabcentral/answers/263934-every-time-i-push-to-the-remote-github-repository-i-have-to-re-input-my-username-and-password-is-t
Yet, when I try to push a commit, I get the following error message:
git@github.com:username/repository.git: invalid privatekey: **********
(There are some characters instead of the **********)
I'm running MATLAB R2017b on a MacBook Pro 15" 2018 with MacOS Mojave 10.14.2
I also have a config file inside my .ssh folder with the following text:
Host *
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_rsa
The contents of my id_rsa.pub are on my GitHub account's SSH keys.
Does anybody know a solution for this issue?
  4 Kommentare
Mike Kokko
Mike Kokko am 13 Mär. 2019
I'm having similar issues with R2018b. This integration worked nicely for me on other machines in the past. Git seems to be configured fine from the command line to use the public key but pushing from MATLAB results in an error:
git@github.com:user/repo.git: Auth fail
Javier Montemayor Mancías
Javier Montemayor Mancías am 13 Mär. 2019
I ended up using GitHub Desktop for my personal account (I now have my work account in the command line). Would be nice if the integration worked, though.

Melden Sie sich an, um zu kommentieren.

Antworten (3)

Timothy Koehler
Timothy Koehler am 23 Okt. 2019
Apparently, newer versions of Git (2.23) have key generation using OPENSSH private keys. If your key that gets generated starts with:
----BEGIN OPENSSH PRIVATE KEY----
then you may need to try using this option
-m PEM
when generating your keys. We have found that the following command for key generation will fix the problem.
ssh-keygen -m PEM -t rsa -b 4096 -C "yourmail@foo.com"
  4 Kommentare
Francois Gardavaud
Francois Gardavaud am 12 Nov. 2020
This works. Thank Mister Koehler.
Tested on macOS Catalina 10.15.7 & Matlab 2020b.
Renato Busatto
Renato Busatto am 19 Feb. 2021
It took me hours to realise that the public key MUST be named "id_rsa". Any other name will give an "invalid privatekey" error.

Melden Sie sich an, um zu kommentieren.


Rubens Rossi
Rubens Rossi am 6 Sep. 2019
Hello, I have also Git on my path but I still get "auth fail". It says that "The authenticity of host xxx can´t be established".
However, when I push or pull from the Bash I do not get any error.
I use Matlab 2019a on Windows, Git version Git-2.23.0-64-bit.

Colm Bates
Colm Bates am 26 Jun. 2019
I had the same problem on 2018a.
Local Git integration worked fine, however when trying to push to a remote Bitbucket repository I got the following error.
matlabGitError2.png
After researching and reading every Matlab Git article I could find and not finding a solution, I realised the solution was in the first place I looked: The Matlab Set-up source control guide.
This document requires that we install command line git. I ignored this, because I had command-line git installed since before I started using Matlab. This was a mistake. The following is very relavent.
  • 2. In the section on adjusting your PATH, choose the install option to Use Git from the Windows Command Prompt. This option adds Git to your PATH variable, so that MATLAB can communicate with Git.
One can investigate the PATH variable on Windows in Matlab with the following:
[status, output] = system("echo %PATH%");
mypath = split(output, ";");
mypath(~cellfun(@isempty,regexp( mypath, '.*Git.*')))
ans =
0×1 empty cell array
Which shows that there are no references to Git in the path. If you want you can scan through the elements of mypath to make sure.
So I uninstalled Git and reinstalled it. Then when I was presented with the below dialog, I chose the middle option, which states that you will allow Git to be used also from 3rd-party software.
GitConfigSetUp1.PNG
After this I closed Matlab and restarted my computer. And now it works!
I ran the above code and got hte following output:
ans =
1×1 cell array
{'C:\Program Files\Git\cmd'}
Which further suggests the PATH was the issue all along.
  2 Kommentare
Jiyo Palatti
Jiyo Palatti am 6 Sep. 2019
I do have Git on my PATH and I ge this when I run the command.
ans =
1×1 cell array
{'C:\Program Files\Git\cmd'}
But I still get the same error saying "Auth Fail"
Dmitry Boltyanskiy
Dmitry Boltyanskiy am 28 Sep. 2019
Bearbeitet: Dmitry Boltyanskiy am 28 Sep. 2019
Hm... strange idea. I have the same answer from Matlab: "ans = 0×0 empty cell array". But the command Git works in any directory (I work on Ubuntu). And unfortunately, I can see "Unable to pull in changes. git@github.com:MyUsername/MyProject.git: Auth fail". Also, this error appears only I try to use SSH-authorisation. HTTP-authorisation works, but I do not want to enter login-password every time.
Upd. The "git" command locates in /usr/bin/ folder in my case.

Melden Sie sich an, um zu kommentieren.

Kategorien

Mehr zu Startup and Shutdown finden Sie in Help Center und File Exchange

Produkte


Version

R2017b

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by