Skip to content

Instantly share code, notes, and snippets.

@jabranr
Last active August 19, 2024 07:51
Show Gist options
  • Save jabranr/c56badc5d329206ad4f435540681e951 to your computer and use it in GitHub Desktop.
Save jabranr/c56badc5d329206ad4f435540681e951 to your computer and use it in GitHub Desktop.
ssh config boilerplate

Step 1

# ~/.ssh/config
Host {work}.bitbucket.com
HostName {work}.bitbucket.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/{work}

Host bitbucket.org
HostName bitbucket.org
PreferredAuthentications publickey
IdentityFile ~/.ssh/personal

Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/personal

# Using multiple SSH keys for same domain
# It works as alias. Use it for git clone for example "git clone git@other.github.com/USER/REPO"
Host other.github.com
Hostname github.com
PreferredAuthentications publickey
IdentityFile ~/.ssh/private

Step 2

# Generate keys to their specific files
ssh-keygen -t rsa -C "{email}" -f "{file_name}"

# or 
ssh-keygen -t ed25519 -C "{email}" -f "{file_name}"

Step 3:

Add keys to respective hosts

Step 4:

Test auth status using ssh -T git@github.com or ssh -T git@other.github.com

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment