Using SSH keys to store passwords to multiple github accounts on my macos - Netlify LM doesn't like SSH?!?

UPDATE 2.19.2020: Well, I actually had installed git-lfs and NLM correctly. I figured this out by changing the remote url back to https and then I was able to git push origin master without issues. So, Netlify has issues with SSH.

HOWEVER I now have to type the username and password each time I want to push, for each of the github accounts I use on my machine. Which is highly annoying. If anyone has any suggestions on how to cache usernames and passwords for multiple github accounts using SSH & Netlify I’d love to hear them!

@fool or @luke y’all seem to be folks in the know. any suggestions?


Hello, I’m new to Netlify, use a custom url: https://www.desolidstate.com/, have my static site repo on GitHub and had no problems pushing to this specific Netlify site before today. DNS propagated successfully the night after the original post so the pushes I made before trying to set up NLM & git-lfs are now live. Whoo Hoo for that!

I have Netlify-CLI installed, just installed git-lfs, Netlify-LM, I’m following the docs

I’ve tracked a couple of files, they are listed when I run $ git lfs ls-files but I’m now having a problem when I push to github at the command line.

  • my repo is linked to Netlify and set up for continuous deployment but now when I git push origin master I get a prompt for my github password which fails every time. I’ve tripled-checked the password. Here is the error message - it lets me try 3 times before kicking me out:
$ git push origin master
Saving password to keychain failed
Saving password to keychain failed
Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists.
  • strangely enough, I’m using macos and I access two different GitHub accounts using this machine and use SSH keys to distinguish between the two so I don’t have to type the passwords. See the blog post for how I have it configured.
  • I’ve been using the SSH Config file technique - #4 in the post - for a while and haven’t had any problems. The account I use for my Netlify site is the secondary account - the work account in the post - thus is in the format:
$ git remote -v
origin git@github.com-work_user1:work_user1/repo_name.git 
  • it may be an NLM issue, but i doubt it - however i did manually reinstall git-credential-netlify
$ brew tap netlify/git-credential-netlify
$ brew install git-credential-netlify
  • and checked .gitattributes .lfsconfig & .gitignore and they look ok

I’m really at a loss and really think it has to do with the SSH keys, but only know enough about Netlify to get myself into trouble. :stuck_out_tongue:

Thanks,
Tim

Hi, @timcombs, and welcome to our Netlify community site. :slight_smile:

In most cases (not all but most) this is related to the Netlify Large Media Git LFS service requiring your Netlify credentials. This should be automatic if the credential helper is loaded. It appears to be clear that it is installed, but if it is loaded in the shell is another matter.

The credential helper is loaded when new shells are started by “sourcing” the helper. (In bash . is an alias for source.)

This is done by adding something similar to this to .bash_profile (or analogous file if you use a different shell):

. /Users/username/.netlify/helper/path.bash.inc

or

source /Users/username/.netlify/helper/path.bash.inc

You can also load the helper in the current shell by copying and pasting the required command above directly into the existing shell prompt. (Changing this command above to use the correct path for where the helper is installed for your system.)

On my system, this is the exact line below:

. /Users/luke/.netlify/helper/path.bash.inc

Would you please confirm that the helper is being loaded in this way?

If there are other questions about this or if this doesn’t resolve the issue, please let us know and we’ll be happy to troubleshoot further.

Thanks a lot for the welcome and the assist!

New platform, new challenges! So let’s get to refactoring the environment.

  1. I did not have the code in my .bash_profile to make sure that credential helper is loaded into the shell, so I added it. then made sure that path.bash.inc existed in the correct directory. Not sure how I missed this step, did i miss this step?
  2. I reset the remote
    git remote set-url origin git@github.com-deSolidState:deSolidState/desolidStateWeb.git
  3. I restarted Terminal and VSCode and tried again - same prompt from my OS and same error message when it didn’t accept the password.
  4. I deleted the public and private keys for this repo from my local and the public key from my github account then created new keys and added the new public key to my github account
    QUESTION when i generated the keys it asked for a passphrase, should I have done that?
  5. I restarted Terminal and VSCode and tried again - same prompt from my OS and a different error message AND it pushed the files to the repo!
$ git push origin master
Saving password to keychain failed
Identity added: /Users/<me>/.ssh/<key> (/Users/<me>/.ssh/<key>)
  1. added another file, git lfs track’d it and pushed - this time I didn’t get the OS prompt and it successfully pushed!
  2. :sweat_smile: :blush:YAY!!! :star_struck: :hugs:

But now I still have the constantly-asking-for-username-and-password issue with my other github account. However, none of those repos are connected to Netlify. hmmmmmm…

thanks so much for all the help!!
tim

So, still been working on this and discovered that if I take the following out of my global .gitconfig file I have no problem pushing to my other GitHub account.

# This next lines include Netlify's Git Credential Helper configuration in your Git configuration.
[include]
  path = /Users/<me>/.netlify/helper/git-config

However, removing them stops me from using Netlify, duh.

Luckily, Git starting at version 2.13 has an [includeIf] feature. so in my global .gitconfig file I replaced

[include]

with

[includeIf "getdir:~/<directory-with-repo>"]

This way I have a .gitconfig file that defaults to my main GitHub account and a conditional (of sorts) that will include Netlify Git Credential Helper when git is used inside the directory that contains the repo that is connected to Netlify on my local machine.

Most importantly, it all works!

:upside_down_face: :slightly_smiling_face:¡¡YAY!! :slightly_smiling_face::upside_down_face:

Thanks again - besides getting my repos connected properly to my various github and my netlify account I learned tons more about git and keychain credentialing and shell configuration files. This is why i love platforms like Netlify, i get lost, someone nudges me in the right direction, i learn more, i become less lost!

tim

tim, thank you so much for sharing your process as you worked through this! This will absolutely help someone else in the future!

1 Like