Git SSH Configuration Guide

Git SSH Configuration Guide

Nov 19, 2023
git, development

Git SSH Configuration Guide #

This guide is designed to help you configure local Git environment for your Socity account using Ed25519 SSH keys, without interfering with your existing GitHub account configurations.

Step 1: Generate SSH Key for Socity Account #

Generate a new SSH key specifically for your Socity account:

ssh-keygen -t ed25519 -C "your_email@socitydao.org"

When prompted, save the key to a specific path, for example:

~/.ssh/id_ed25519_socity

Step 2: Add SSH Key to ssh-agent #

Start the ssh-agent and add your new key:

eval "$(ssh-agent -s)"
ssh-add ~/.ssh/id_ed25519_socity

Step 3: Add SSH Public Key to GitHub Account #

  1. Open and copy your public key:

    cat ~/.ssh/id_ed25519_socity.pub
    
  2. Log in to your GitHub account.

  3. Navigate to Settings → SSH and GPG keys.

  4. Click New SSH key and paste your public key.

Step 4: Configure SSH #

Edit your ~/.ssh/config file to add a configuration block for the Socity account:

# Socity account
Host github.com-socity
  HostName github.com
  User git
  IdentityFile ~/.ssh/id_ed25519_socity

This ensures that your Socity account uses its specific SSH key.

Step 5: Test Connection #

Test your SSH connection to GitHub:

ssh -T git@github.com-socity

You should see a welcome message from GitHub.

Step 6: Repository Configuration #

Cloning New Repositories #

When cloning new repositories, use the github.com-socity Host alias instead of the standard github.com. This ensures SSH uses the correct key for authentication.

git clone git@github.com-socity:orgname/repo.git

Replace orgname/repo.git with the appropriate organization name(usually orgname===“SoCity-DAO”) and repository name.

Set the Git username and email for your local repository: #

git config user.name "Your Name"
git config user.email "your_email@socitydao.org"

(optional)Updating Existing Repositories’ Remote URL #

For repositories already cloned and you wish to use the Socity account configuration, update the remote URL:

git remote set-url origin git@github.com-socity:orgname/repo.git

This changes the remote repository URL to use the Socity account’s SSH key for future push and pull operations.