SSH Key for GitHub not working (MacOS)
5 次查看(过去 30 天)
显示 更早的评论
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 个评论
Mike Kokko
2019-3-13
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
2019-3-13
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.
回答(3 个)
Timothy Koehler
2019-10-23
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 个评论
Francois Gardavaud
2020-11-12
This works. Thank Mister Koehler.
Tested on macOS Catalina 10.15.7 & Matlab 2020b.
Renato Busatto
2021-2-19
It took me hours to realise that the public key MUST be named "id_rsa". Any other name will give an "invalid privatekey" error.
Rubens Rossi
2019-9-6
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.
0 个评论
Colm Bates
2019-6-26
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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226407/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](https://www.mathworks.com/matlabcentral/answers/uploaded_files/226408/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 个评论
Jiyo Palatti
2019-9-6
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
2019-9-28
编辑:Dmitry Boltyanskiy
2019-9-28
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.
另请参阅
类别
在 Help Center 和 File Exchange 中查找有关 Startup and Shutdown 的更多信息
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!