Skip to content

Instantly share code, notes, and snippets.

@PHPirates
Last active October 28, 2018 20:18
Show Gist options
  • Save PHPirates/77af557ed801d9dd77eac45a8fbb7ec3 to your computer and use it in GitHub Desktop.
Save PHPirates/77af557ed801d9dd77eac45a8fbb7ec3 to your computer and use it in GitHub Desktop.
Set up another git user with ssh
  1. Generate new ssh key pair

    ssh-keygen -t rsa -b 4096 -C "[email protected]"
  2. Give it a different name than default, e.g. id_rsa_iam.

  3. Add this key to the ssh agent, cd ~/.ssh and ssh-add id_rsa_iam

    If you get the error 'Could not open a connection to your authentication agent.' then start the ssh-agent with

    eval `ssh-agent -s`
    ssh-add
  4. Modify the ssh config: touch config (still in ~/.ssh) and put this into it:

    Host github.com
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_rsa
    
    # Github when impersonating Iam
    Host iam.github.com # can be anything, e.g. github-iam
        HostName github.com
        User git
        IdentityFile ~/.ssh/id_rsa_iam
  5. Add the public key to your GitHub account as usual.

  6. Clone a repo using the new host:

    git clone [email protected]:iam/repohere.git
    
  7. Go into the repo directory and set new user name and email:

    git config user.name "Iam Here"
    git config user.email "[email protected]"

This manual was adapted from StackOverflow.

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