Despite being SSH Authenticated to GitHub, terminal (Bash, PWSH) Git created repo's will not Push, Fetch remote - but GitHub Desktop created will

Viewed 79

Despite being SSH Authenticated to GitHub, terminal (Bash, PWSH) Git created repo's will not Push, Fetch remote - but GitHub Desktop created will.

Date: From 16/09/22 - 18/09/22: Two days of effort.

This post is subject to future edits and refinements as questions arise

Pre-requisites: Local

  • [x] Git (Windows) installed in custom folder Gitx64 under C:\Program Files
  • [x] Symlink created from C:\Program Files\Gitx64 to C:\Program Files\Git
  • [x] OpenSSH (Windows) and ssh_config at $Home/.ssh/config
  • [x] Git (Windows) Global config and at $Home/.gitconfig
  • [x] ssh-agent (Windows) is on automatic start.
  • [x] ssh-add -L checks for loaded keys.
    • [x] ~/.ssh/id_rsa key is loaded as off 18/09/2022
  • [x] Focusing on ~/.gitconfig (Global user)
  • [NO] As yet, not using system git/config.

Pre-requisites Terminal Profiles

.bash_profiles / .bashrc
  • [ ] No terminal checking, , onload, for ssh-agent (yet, removed for reset of troubleshooting)

  • [] No terminal checking, onload, for ssh-add (yet, removed for reset of troubleshooting)

  • [?] To be added or incorporated, have some shell scripts

  • [] Removed, so to check if there was a way to not add passphrase in at start of the shell .

  • [] Maybe that is what is missing: the passphrase authentication to the shell??

Powershell $Profiles

Pre-requisites: Remote

  • [x] GitHub.com Account: User: iPoetDev
  • [x] SSH Key added (16/09/22)
  • [x] Interactive, via browser, authentication
    • [x] Via Going to www.github.com
    • [x] GitHub CLI interactive gh auth login
  • [x] PAT Token configured
  • [x] Can Create Remotely and clone locally
  • [x] Remote Repo does exits on GitHub.com (Challenged 19/09)

Problem Statement

Note: I have a juicy issue as I have been switching between bash | pwsh for Git and GH CLI and GitHub Desktop and SourceTree trying to diagnose and resolve for 2 days.

For creating, not cloning, a local repo and creating a remote repository from command line/terminal works but interacting with Git Push | Fetch | Pull does not**

Thinks that it is not a repository or am not authenticated or have correct rights/identity.

  • I can authenticate to GitHub.com with SSH and a (RSA) Public Key via command line SSH and GH CLI tooling.

  • I can, with git remote add <remote_name> <remote_repo_url>

    • But this does not appear on GitHub.com (i.e., like it is an internal or ...?)
  • I can, with GitHub CLI, creates a remote repo successfully (see below)

    • But GitHub CLI does not want to add a remote at <remote_repo_url>
  • GitHub Desktop throws:

    • Not authenticated error (see screenshot with annotations) [GitHub Desktop Auth error, ++Annotations][1]
  • Bash: git push or fetch generates the following error:

      $ git fetch
      fatal: 'git@github.com/iPoetDev/Gobals1.git' 
      does not appear to be a git repository
      fatal: Could not read from remote repository.
      Please make sure you have the correct access 
      rights and the repository exists.

    $ git push fatal:'git@github.com/iPoetDev/Gobals1.git' does not appear to be a git repository fatal: Could not read from remote repository. Please make sure you have the correct access rights and the repository exists.

And yet

$ git remote get-url mains 
->
git@github.com/iPoetDev/Gobals1.git

If it is TL/DR, pm me or I will follow up with a Loom link to visualise in further detail. I will also see if I can get this as an Issue on my GitHub (via a functional repo) as an issue for off Stack Overflow concern.



Git Global Config

  • Not using system file
  • Not using per repo (Can if I need to)
  • Not using (yet) command line configurations

NOTE

  • Added in for background and further information.

Config Directives

Selected Directives from Global Config at $Home/.gitconfig

[user]
    name = <GitHub Name>
    email = <GitHub secondary email address in use>
    # Options: 1: 51715025+iPoetDev@users.noreply.github.com
    # Options: 2: <GitHub primary email address in use>
[core]
    # Commented Out
    # sshCommand = ssh -i ~/.ssh/id_rsa -F /dev/null

[init]
    defaultBranch = main
[push]
    default = current
    # removes git push -u
    autoSetupRemote = true 
[credential "helperselector"]
    selected = manager-core
[credential "https://github.com"]
    #username = git
    username = iPoetDev
    helper = 
    helper = D:\\.Tools\\.scoop\\apps\\gh\\current\\bin\\gh.exe auth git-credential

#   As explained, Git only allows you to access repositories owned by yourself, i.e. the user who is running Git, by default.
[safe]
     directory = D:/Code/Gobals/* 
     directory = D:/Code/Gobals/Gobals
     directory = D:/Code/Gobals/Gobals1

GitHub CLI && Repo Management

Authenticates with GitHub CLI (Interactively)

  • No PAT Token, but have one ready

  • Switches from https to ssh for authentication

     gh auth login
    ? What account do you want to log into? GitHub.com
    ? You're already logged into github.com. Do you want to re-authenticate? Yes   
    ? What is your preferred protocol for Git operations? SSH
    ? Upload your SSH public key to your GitHub account? $Home\z.ssh\id_rsa.pub  
    ? Title for your SSH key: ```<Added Title>```
    ? How would you like to authenticate ```<Added Title>```? Login with a web browser
    
    ! First copy your one-time code: ```<One Time Code>```
    Press Enter to open github.com in your browser... 
    āœ“ Authentication complete.
    - gh config set -h github.com git_protocol ssh
    HTTP 422: Validation Failed (https://api.github.com/user/keys)
    key is already in use
    

Authenticates with GitHub CLI (Interactively)

Note: To be updated. Clipping lost in translation and write up. Come back later, when the post is updated. Need to replay and reproduce remote git repo creation by GH CLI.

==========

Possible Components To follow Up

Adding SSH Agent start in .bash_profile (A suggested option)

Add the following snippet to ~/.bash_profile to automaticall start ssh agent so you don't have to reauth git with every remote command.

  • Source - Credit: RayWongJR@Github.com

    # ssh agent
    # -------------------
    SSH_ENV=$HOME/.ssh/environment
    
    function start_agent {
        echo "Initializing new SSH agent..."
        # spawn ssh-agent
        /user/bin/ssh-agent | sed 's/^echo/#echo/' > "${SSH_ENV}"
        echo succeeded
        chmod 600 "${SSH_ENV}"
        . "${SSH_ENV}" > /dev/null
        /usr/bin/ssh-add
    }
    
    if [ -f "${SSH_ENV}" ]; then
        . "${SSH_ENV}" > /dev/null
        ps -ef | grep ${SSH_AGENT_PID} | grep ssh-agent$ > /dev/null || {
            start_agent;
        }
    else
        start_agent;
    fi
    

Solution Options | Remedies?

Goal Aim is to have secured ssh traffic between all local and remotes, regardless of interaction.

Objective 1 To be able to switch between GUI and Terminal, inc GitHub Desktop, SourceTree and VCode, GitBash, Powershell, without issue.

Objective 2 Not to use two+ valuable days on one issue and end up in negative cost-benefit for other concerns.

Objective 3 Was to Learn about advanced SSH, GitHub CLI, Git-Bash Git usage and finalise baseline Dev Env configuration with VSCode.

OPTIONS
  1. Check if SSH Authentication (Host Key Verification) passes for git@github.com:iPoetDev/Gobals1.git
  2. Change SSH Key Type from RSA to ECDSA
  3. Test for GitLab and/or Bitbucket if issue is replicated for each or is GitHub specific.
  4. Solution unknown and offered here below
  5. Log an issue with GitHub.com or Git or ...??

and not least

  1. Switch back to HTTPS authentication and repeat tests.

Extras

References

  • Added as needed
SSH Config (Selected View)
Host github.com
Hostname github.com 
AddKeysToAgent=yes
IdentityFile ~/.ssh/id_rsa
IdentitiesOnly=yes 
PubkeyAuthentication=yes
Files && Locations
3 Answers

You're trying to push to a remote repo that doesn't exist. That's all there is to it, and it has nothing to do with the details of your local configuration. To create a repo on GitHub you can go to https://github.com/new (log in if necessary) and fill in the requested information. Once it's created, you can push to it. Other hosts are, of course, different.

Folks, visibility is key, and I found it in the log view Output of VSCode Output for the git. I supercharged VSCode with as many extension I could last night and went looking.

Methinks GitHub CLI and git.exe via ~/.gitconfig are not playing ball.

In my git config, see it is useful, I have my credential.helpers configured. Optimally I seek to use either windows credential manager or GitHub link into it, via their official CLI, which is user friendly.

The analayis here is that GitHub Desktop is configured to use the Windows Credential Manager, by default; and git.exe is not but does install with the newest windows credential manager. So having GH.exe take over and be error prone is a blocker. I can revert to simpler config and test.

Nice to have: Prefer GH CLI, but must have: seamless authentication bu ssh and windows's credential helper. No, not the cache or store or local or plantext

git.exe is the calling program and the VSCode output is the log viewer for git.exe.

[2022-09-19T16:36:33.903Z] D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential get: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found
D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential erase: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found

remote: Invalid username or password.
fatal: Authentication failed for 'https://github.com/iPoetDev/Gobals.git/'

D:\.Tools\.scoop\apps\gh\current\bin\gh.exe auth git-credential get: line 1: D:.Tools.scoopappsghcurrentbingh.exe: command not found
__\_____\_____\___\__\______\___\__.exe

Part 2 of the Problem Statement (same issue: authentication)

Something is stripping out the path separators and my authentication is failing per repo on the command line.

But who is the culprit. BTW I did not manually add the gh.exe to the git config, it was automatically done at install and first run, I think.

Solve for this and solve for git remote add, (above) I think...

Secondly, I have credential.user = iPoetDev, should I switch this over to credential.user = git for ssh, given all ssh is anonymous via git@github.com/iPoetDev

VSCode Output

This final response is due. TBA

Related