MATLAB Answers

Why do I receive an "Auth fail" error when interacting with a Git remote over SSH in MATLAB or why does MATLAB keep asking for the password of git@myhost?

515 views (last 30 days)
When trying to clone my Git remote in MATLAB over SSH or when trying to interact with (push, pull, etc.) an already successfully cloned (using an external client) repository from within MATLAB, I get one of the following symptoms: 
MATLAB keeps on showing the dialog: "The authenticity of host 'myhost' can't be established" message, even if I have specified before that this identity is correct and this preference should have been saved. After this message I receive an error dialog saying "Auth fail". 
Instead of displaying this error, MATLAB may ask for the password of git@myhost every time I interact with the Git remote server. 

Accepted Answer

MathWorks Support Team
MathWorks Support Team on 8 Apr 2021
Edited: MathWorks Support Team on 20 Apr 2021
The "Auth fail" message is shown when all authentication mechanisms supported by the server failed; the password dialog will be shown if public key authentication failed but additional authentication methods are available on the server. One possible reason for this public-key authentication failure is MATLAB finding ~/.ssh/id_rsa or ~/.ssh/id_dsa or ~/.ssh/identity file(s) and attempting to authenticate over SSH with them, but none of these files contained a key which MATLAB was able to work with. Another possible reason is that MATLAB cannot find your ~/.ssh/id_rsa files(s) at all.
MATLAB's Git client requires your private key to be in the (older) RSA format and it cannot work with the (newer) OPENSSH format. Please open your private key file in a text editor; to be compatible with MATLAB it should start with:
And not with:
*Now why might you have different keys in different formats?*
This is a combination of factors:
- Older ssh-keygen versions always created keys in the RSA format, so then it would always have worked fine with MATLAB.
- Then at some point in time an "-o" option was added to ssh-keygen, when indeed called with this "-o" option, it would now produce keys in the OPENSSH format. At the time, online instructions (on websites like,,, etc.) about using ssh-keygen varied by website, some did instruct you to explicitly add "-o", some did not. If you did call ssh-keygen with "-o" you would have gotten a key incompatible with MATLAB, if you did not, the key was compatible with MATLAB.
- In current ssh-keygen versions the OPENSSH format is in fact the default, you no longer have to explicitly add "-o" to get a key in that format. Nowadays you explicitly have to add "-m PEM" to get a key in the RSA format. Most online instructions now instruct you to use ssh-keygen without the "-o" option (since it has no effect anymore anyway) but also without the "-m PEM" option. So nowadays when following most of the online instructions you would get a key which is incompatible with MATLAB.
*What is our advice right now?*
When creating new keys, you can in the basis follow online instructions for your preferred platform on how to use ssh-keygen, for example with regards to which key size to use; however:
- If these instructions include adding "-o" to the command-line then actually _omit_ this option.
- If these instructions do not include "-m PEM" then please do _add_ this option.
So you would for example get:
ssh-keygen -t rsa -b 4096 -m PEM
Further, it should be possible to convert from OPENSSH to RSA format if you had already created your key in the OPENSSH format:
ssh-keygen -p -m PEM -f ~/.ssh/id_rsa
Where you may need to replace ~/.ssh/id_rsa with your specific private key file.
If you are still experiencing this issue, make sure that your "HOME" environment variable is set as the parent folder of your .ssh folder. So if your .ssh folder is located in
set the HOME variable to:
To confirm the value of your "HOME" environment variable, run the MATLAB command:
More information about setting up Git over SSH is available here:
François LINANT
François LINANT on 5 Jul 2021
Thanks, this help me a lot.
One more thing : you have to generate the SSHkey without matlab running, or to restart matlab after the SSH key generation.

Sign in to comment.

More Answers (1)




Community Treasure Hunt

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

Start Hunting!