Git Config Deep Dive: Managing SSH Keys and Multiple SSH Keys with ssh_config

Difficulty: advanced
Est. Time: 90 minutes
Prerequisites:
  • Git Behind Firewalls and Proxies: Overcoming Connectivity Challenges
Git Config Deep Dive: Managing SSH Keys and Multiple SSH Keys with ssh_config
18 min
TUTORIAL
git
config
ssh
advanced

Git Config Deep Dive: Managing SSH Keys and Multiple SSH Keys with ssh_config

Git’s configuration system allows you to customize its behavior for optimal workflows. Managing multiple SSH keys is a common requirement for developers working on multiple projects or platforms. In this blog, we’ll explore advanced Git configuration options, SSH key management, and how to use ssh_config for seamless multi-key setups.

Table of Contents

  • Global vs Local Config
  • SSH Key Management
  • Configuring Git
  • Managing Multiple SSH Keys
  • Exercise: Configuring Git and SSH Keys

Global vs Local Config

Global config applies to all repositories (~/.gitconfig). Local config applies to a specific repository (.git/config).

SSH Key Management

Generate separate keys for different platforms:


  ssh-keygen -t rsa -C "github-email@example.com" -f ~/.ssh/id_rsa_github
  ssh-keygen -t rsa -C "gitlab-email@example.com" -f ~/.ssh/id_rsa_gitlab
          

Configuring Git

View current configurations:


  git config --list
  git config --local --list
          

Set global username and email:


  git config --global user.name "Your Name"
  git config --global user.email "your.email@example.com"
          

Managing Multiple SSH Keys

Edit ~/.ssh/config to specify keys for different hosts:


  Host github.com
      HostName github.com
      User git
      IdentityFile ~/.ssh/id_rsa_github
  
  Host gitlab.com
      HostName gitlab.com
      User git
      IdentityFile ~/.ssh/id_rsa_gitlab
          

Exercise: Configuring Git and SSH Keys

Practice SSH key management:

  • Create separate keys for GitHub and GitLab.
  • Configure ~/.ssh/config for multiple hosts.
  • Test SSH connections to GitHub and GitLab.

Coming Up Next

In the next part of this series, we’ll explore Git tagging strategies, including lightweight vs annotated tags, semantic versioning, and automating tagging workflows.

Part 19 of 24 in Git Mastery Series: From Beginner to Expert
All Posts in This Series