Skip to content

Instantly share code, notes, and snippets.

@exanup
Last active December 29, 2021 15:03
Show Gist options
  • Save exanup/1271c89cfe4b6367a762a53fdca2a62f to your computer and use it in GitHub Desktop.
Save exanup/1271c89cfe4b6367a762a53fdca2a62f to your computer and use it in GitHub Desktop.
Switchable SSH Profiles for Github

Switchable SSH Profiles for Github

In your rc file:

alias gitp="git config --global core.sshCommand \"ssh -F ~/.ssh/config-personal\" && \
            git config --global user.email personal_email@example.com && \
	    git config --global user.name \"My Name\" && \
            git config --global commit.gpgsign true && \
            git config --global user.signingkey XXXXXXXXXXXXXXXX && \
            echo \"Switched git to personal profile\""

alias gitw="git config --global core.sshCommand \"ssh -F ~/.ssh/config-work\" && \
            git config --global user.email work_email@example.com && \
            git config --global user.name \"My Name\" && \
            git config --global commit.gpgsign true && \
            git config --global user.signingkey XXXXXXXXXXXXXXXX && \
            echo \"Switched git to work profile\""

Example config files:

~/.ssh/config-personal

Host *
	IgnoreUnknown UseKeychain
	UseKeychain yes
	AddKeysToAgent yes
	IdentityFile ~/.ssh/id_ed25519-personal
	IdentitiesOnly yes

~/.ssh/config-work

Host *
	IgnoreUnknown UseKeychain
	UseKeychain yes
	AddKeysToAgent yes
	IdentityFile ~/.ssh/id_ed25519-penji
	IdentitiesOnly yes
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment