Thursday, December 26, 2024Manage multiple SSH accounts
Keven Client A. Cataluña @LinkedIn
Introduction

This guide explains how to manage multiple SSH accounts by configuring different SSH keys for each account in the ~/.ssh/config file, testing the connection, and using the configured host in Git URLs when adding remote repositories.

Steps1. Open ~/.ssh/config file
    nano ~/.ssh/config
  
2. Add the SSH configurations
~/.ssh/config
    Host github_development
  HostName github.com
  IdentityFile ~/.ssh/github_development

Host github_work
  HostName github.com
  IdentityFile ~/.ssh/github_work
  
3. Test the SSH connection
    ssh -T git@github_development
  
      Enter passphrase for key '/home/development/.ssh/github_development': ••••••••
  Hi kevenclient! You've successfully authenticated, but GitHub does not provide shell access.
  
4. When adding a remote repository, use the configured Host instead of HostName in Git URL
    git remote add origin git@github_development:username/repository.git
  
5. Verify the remote URL
    git remote -v
  
      origin  git@github_development:username/repository.git (fetch)
  origin  git@github_development:username/repository.git (push)