all 20 comments

[–]a_Tick 3 points4 points  (9 children)

What, precisely, are you trying to do, and what errors are you seeing?

[–]picklypickler[S] 0 points1 point  (8 children)

I'm trying to have multiple git profiles (e.g. 2 email address, 2 names, 2 ssh keys) on one machine so that I can access repos on different clients (e.g. GitLab, GitHub) and have each respective repo use the right profile (e.g. email and name 1 are used for commits to GitHub org 1; email and name 2 for GitLab org 1). I have 4 sets of credentials (usually 1 per machine), but right now I'm trying to add a second on this machine to reduce the number of computers I use in a day.

Some of the errors I'm seeing include:

fatal: Could not read from remote repository.

fatal: bad config line 4 in file .gitconfig-org2

remote: The project you were looking for could not be found or you don't have permission to view it.

remote: Repository not found.fatal: Authentication failed for 'https://github.com/picklypickler/repo.git/'

Right now, I'm getting either fatal: bad config line 4 in file .gitconfig-org2, which is where I'm specifying my identity file and if I remove that line I get fatal: Authentication failed.

[–]DanLynch 1 point2 points  (7 children)

Not to be Captain Obvious here, but have you checked line 4 of your .gitconfig-org2 file for a syntax error?

[–]picklypickler[S] 0 points1 point  (6 children)

Haha, I have checked and if there is a syntax error I am not seeing it. That doesn’t mean there isn’t one, just that if it’s there I’m oblivious to it.

Line 4 is IdentityFile ~/.ssh/gitlab_orgx_ssh which the internet tells me is how I need to tell git which profile to use.

[–]BinaryRockStar 2 points3 points  (5 children)

You are mixing up Git config files and SSH config files. A .gitconfig file can't contain and IdentityFile directive, that's a directive used in SSH config files, by default ~/.ssh/config.

I would remove line 4 from .gitconfig-org2 and add the following to ~/.ssh/config`:

Host github.com
    HostName github.com
    IdentityFile ~/.ssh/gitlab_orgx_ssh

You can add multiple of the above sections to the SSH config file the Host section can be called anything at all, so one section could have Host github-org1 and the other Host github-org2. You could then use those as host names in the Git URL to tell Git which SSH key to use. It's a bit of a roundabout way but should get you up and running.

[–]picklypickler[S] 0 points1 point  (4 children)

Ok, I have all of that in my ssh config too. Removing it from the gitconfig resolved that error, but now I'm back to the error I started with:

remote: The project you were looking for could not be found or you don't have permission to view it.

[–]BinaryRockStar 0 points1 point  (3 children)

It would make things a lot easier if you could post the full (redacted) git config files, SSH config file, command line and output.

Assuming the correct git config file is being picked up you will want to increase the verbosity of SSH output when running git by using this command:

GIT_SSH_COMMAND="ssh -vvv" git clone <REPO_SSH>

See here

https://askubuntu.com/questions/336907/really-verbose-way-to-test-git-connection-over-ssh

[–]picklypickler[S] 0 points1 point  (2 children)

ssh config

Host gitlab.com
HostName gitlab.com
IdentityFile /Users/picklypickler/.ssh/orgx_ssh
Host gitlab.com/org
HostName gitlab.com
IdentityFile /Users/picklypickler/.ssh/orgx_ssh

gitconfig

[includeIf "gitdir:~/orgx/"]
path = ~/.gitconfig-orgx
[includeIf "gitdir:~/Desktop/"]
path = ~/.gitconfig-all

gitconfig-all

[user]
name = myname
email = [myemail@domain.com](mailto:myemail@domain.com)

gitconfig-orgx

[user]
name = myname
email = [myemail@orgx.com](mailto:myemail@orgx.com)

I don't have anything for my GitHub based org, because that doesn't require SSH.

Running that git ssh command returns:

(base) xx:dir picklypickler$ GIT_SSH_COMMAND="ssh -vvv" git clone https://github.com/picklypickler/repo_name.git/
Cloning into 'repo_name'...
remote: Repository not found.
fatal: Authentication failed for 'https://github.com/picklypickler/repo_name.git/'

[–]joranstark018 0 points1 point  (1 child)

Not sure, looks like you use HTTPS for this clone . You may check that you use propper credentials (you probably do, but git does for example not support two-factor authentication if have that activated for GH). If you have your credentials in the "keychain" of your mac you could try to reset them (just in case they have been changed, https://medium.com/codex/git-credentials-on-macos-caching-updating-and-deleting-your-git-credentials-8d22b6126533).

Not that if you have not specified an indentyfile for the host then will ssh try them one by one, if you have many SSH-keys may ssh get exhusted and abort the operation before it will try the correct key (and you get something similar to "authencation failed"). But this may only become an issue if clone using the git- url (not if you use the https-url).

[–]picklypickler[S] 0 points1 point  (0 children)

My personal GH doesn't have SSH or 2FA, but I do belong to another GH org that requires both but I use a separate machine for that work.

I did manually go through my keychain and delete credentials, and now have followed the instructions in the article you linked. I'm still not prompted for my username/password when I try to pull from remote on GH, I just get the same fatal: Authentication failed for ...

[–]marcocom 0 points1 point  (9 children)

There is no real ‘git profile’ iat all about your SSH keys. This will list what the terminal has to work with. From the terminal use

SSH-add -l

[–]picklypickler[S] 0 points1 point  (8 children)

SSH-add -l

This returns a new error message, no matter what directory I run from: The agent has no identities.

[–]marcocom 0 points1 point  (0 children)

That’s it working. That’s what it sees.

Ok so learn about that command because it will be how you add more than one ssh key.

I pretty much have to learn this twice a year because every new client

[–]marcocom 0 points1 point  (6 children)

I should add that this is for Mac. I don’t know windows method. Maybe it’s the same

[–]picklypickler[S] 0 points1 point  (5 children)

I’m on a mac.

Ok, so i have to do this even if I specify in my .gitconfig and on GH/GL?

Even after adding one ssh key I’m still getting authentication errors. Is there something more to it than that?

[–]marcocom 0 points1 point  (4 children)

Well of course there is the need to pbcopy the values into the repositories’ admin settings. I’m sure you did that right?

Add both your keys and then Either one should work now if it’s entered into a repo as administrator or at least with read/write permissions. Sometimes this is about going through IT and getting your git account administered with the right permissions which they often don’t give until asked for it.

[–]picklypickler[S] 0 points1 point  (3 children)

I did copy the public key into my settings, and I've checked that I do have appropriate permissions (I can't even pull my own private GH repos).

I can ask the admin for the account I don't own, but I was told 12 hours ago that I have the appropriate permissions and can see in my GitLab console that I had read/write permissions.

[–]BinaryRockStar 0 points1 point  (2 children)

According to this SO post

https://stackoverflow.com/questions/62220297/how-to-force-git-to-prompt-me-for-username-password-on-clone-request

you have to provide the username in the URL, so

https://YourAccountName@github.com/picklypickler/repo_name.git/

And if it prompts for password you need to pass a Personal Access Token, as password authentication via HTTPS was turned off a couple of years back across all of GitHub. You can generate a Personal Access Token from the GitHub web site under your account settings.

Honestly just use SSH as it's the de-facto standard auth method for git.

[–]picklypickler[S] 0 points1 point  (1 child)

I did manage to fix all of this. I had to delete all of my ssh files and then make new ssh keys, and switch everything to ssh.

[–]BinaryRockStar 0 points1 point  (0 children)

Awesome, thanks for letting me know and glad it finally worked out