3

I need to use my company GitHub from my local machine.
I prefer to use SSH.

I have a private GitHub account that is already using SSH with the local default key (~/.ssh/id_rsa.pub).
I use Windows.

I'm logged in with my company account and I can see the repositories.
If I do git clone <git url> or git clone <https url> I receive: "repository not found".

With git -T [email protected] I see that I'm autenticated with my personal GitHub account.

I tried to regiter the local default SSH key (id_rsa.pub) on the company GitHub account but it says the key is already in use (I imagine it refers to my personal account).
I registered another key (id_rsa_test.pub) but I can't find any parameter in git to pass a different key/credentials?

How can I use git, with SSH, from my local PC without replacing my personal SSH key with a specific SSH key?

As a temporary solution I tried to put this in the GIT config, but does not work (still "Repository not found" error)

Host GitHub
    HostName github.com
    User alex-company-user
    IdentityFile c:\Users\alex\.ssh\new_key_rsa

ssh-add <path to the new key file> returns "Error connecting to agent: No such file or directory" I think because on this machine I don't have Git-Bash installed. (as I understood it is practically mandatory to have a up and running ssh-agent all the time?)

GIT_SSH_COMMAND='ssh -i C:\Users\alex\.ssh\new_key_rsa' returns "'GIT_SSH_COMMAND' is not recognized as an internal or external command"

[Temporary solution: GitHub Desktop]

As a temporary solution I'm usaing GitHub Desktop.
It ALWAYS authenticate with the browser (also after you passed the user/password and entered the verification code received by SMS !!) and it ALWAYS use the alredy logged in user in the browser.
So, I enter the username and password of my company account, click "sign in", receive the SMS with the verification code, OK. It says I have to authenticate with the browser, click "continue"... it opens the browser and I'm automatically authenticated with my personal account!
So, I have to log out on the browser from my personal account, repeat the procedure after been logged in with my company account in the browser.
(I opened an Issue for this)
It lets me choose the repository to clone from a list. I cloned it and I found it is using the HTTPS URL (repo/.git//config):

[remote "origin"]
    url = https://github.com/<my-company-repo>.git

(maybe I can change this to the SSH, I'll try) So, I hope this solution does not require me to switch the user in the browser often. I still like to know how to do it using git directly (without a 3rd party tool).

2
  • There's no real reason to reuse your personal key with your company account. Just generate a new pair.
    – chepner
    Commented May 28, 2020 at 0:52
  • The problem is that when I do git clone <my-company-repo> that repo is not visible because GIT does not allow to pass the "other" SSH key. That's what I think is the reason for the "Repository not found error". My company repo is obviously private.
    – Alex 75
    Commented May 28, 2020 at 9:02

1 Answer 1

1

As a temporary solution I tried to put this in the GIT config, but does not work

To use that configuration, you would need to:

  • change the user to git (an SSH connection to GitHub always uses 'git': the private key will authenticate the actual user)
  • change your URL

So:

Host GitHub
    HostName github.com
    User git <<=== not alex!
    IdentityFile c:\Users\alex\.ssh\new_key_rsa

And:

cd C:\path\to\repo
git remote set-url GitHub:<me>/<myrepo>

The key part if to use the rigth private key in association to [email protected]

Here the config entry is named GitHub (but it could be named xxx).
That is why the URL must become GitHub:<company>/<comany-repo>.git in order to use that ~/.ssh/config entry "GitHub".

You can define many entries for the same [email protected], as I illustrated 8 years ago in "How to work on personal GitHub repo from office computer whose SSH key is already added to a work related GitHub account?"

9
  • I corrected the user. I already tried with git, I was indecise about my-user or git because for GitLab it is set with my-user. I'm using this URL: [email protected]:<my-company-repo>.git . I'm not changing a repository from HTTPS to SSH, I need to clone it for the first time. Still have "Repository not found" when call git clone [email protected]:<my-company-repo>.git. (same error with the HTTPS url too).
    – Alex 75
    Commented May 28, 2020 at 9:12
  • @Alex75 That seems normal: an actual GitHub URL involves a user or organization, followed by a repository: [email protected]:<my-company>/<my-company-repo>.git
    – VonC
    Commented May 28, 2020 at 9:28
  • @Alex75 Check first with ssh -Tv GitHub if you are correctly authenticated
    – VonC
    Commented May 28, 2020 at 9:30
  • PS D:\temp> ssh -Tv GitHub OpenSSH_for_Windows_7.7p1, LibreSSL 2.6.5 debug1: Reading configuration data C:\\Users\\alex/.ssh/config debug1: C:\\Users\\alex/.ssh/config line 10: Applying options for GitHub [cut] debug1: identity file c:\\Users\\alex\\.ssh\\<new_key> type 0 debug1: key_load_public: No such file or directory debug1: identity file c:\\Users\\alex\\.ssh\\<new_key>-cert type -1 debug1: Local version string SSH-2.0-OpenSSH_for_Windows_7.7 debug1: Remote protocol version 2.0, remote software version babeld-f24cc9ea debug1: no match: babeld-f24cc9ea [continue...]
    – Alex 75
    Commented May 28, 2020 at 11:11
  • @Alex75 As long as ssh -Tv GitHub (with "GitHub" being the Host entry name in your ~/.ssh/config file ) does not end up with "Welcome xxx", nothing else will work.
    – VonC
    Commented May 28, 2020 at 11:13

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.