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
underC:\Program Files
- [x] Symlink created from
C:\Program Files\Gitx64
toC:\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]
- [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
- Check if SSH Authentication (Host Key Verification) passes for git@github.com:iPoetDev/Gobals1.git
- Change SSH Key Type from RSA to ECDSA
- Test for GitLab and/or Bitbucket if issue is replicated for each or is GitHub specific.
- Solution unknown and offered here below
- Log an issue with GitHub.com or Git or ...??
and not least
- 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
$Home/.ssh/agent.env
$Home/.ssh/id_rsa
$Home/.ssh/id_rsa.pub
$Home/.gitconfig
D:\Code\Gobals\Gobals1
&&Don't laugh, I mistyped and kept the pattern for testing
OpenSSH Authentication Agent Service (Automatic start)