ยท All Snippets

Manage Multiple SSH Keys With Different Hosts

Private and corporate github accounts and repositories may be set up with different SSH keys. This post outlines briefly how I configure SSH to make the switching transparent.

Multiple different SSH key pairs may have been imported or created with

ssh-keygen -t rsa -C ""

Create a local SSH config

touch ~/.ssh/config

Assuming we have two github accounts, a private one and a corporate one, I’d set the default to the keypair id_rsa here for the default host. Corporate repositories will use the repository url.

        IdentityFile ~/.ssh/id_rsa
        IdentityFile ~/.ssh/id_ed25519

We’d then clone repositories using the identifier host:

git clone

Or update the repository config under .git/config then gets the remote url set as follows:

[remote "origin"]
        url =
        fetch = +refs/heads/*:refs/remotes/origin/*

Go Private Dependencies

With the above setup Go private dependencies may fail on go mod tidy with:

go: finding module for package
go: downloading v0.0.0-20220309104613-82b02c89f961 imports verifying module: reading 410 Gone
        server response:
        not found: invalid version: git fetch -f origin refs/heads/*:refs/heads/* refs/tags/*:refs/tags/* in /tmp/gopath/pkg/mod/cache/vcs/f7223b0c74f927514a7dcf6437bf4284cb35c4f028686b6b2cd906e7379439d9: exit status 128:
                fatal: could not read Username for '': terminal prompts disabled

Ensure your ~/.gitconfig has the overrides in the order of matching from more details to less, e.g.:

[url ""]
	insteadOf =
[url ""]
	insteadOf =
[url ""]
	insteadOf =

Then mark the repository path as private, here on the entire corporation:

export GOPROXY=direct

Now go mod tidy should succeed.

Last modified on Wednesday, Mar 9, 2022.
Go back