How to use different ssh key for github

Yang Li
Jul 17, 2023

--

  1. Generate new key and add to agent:
$ ssh-keygen -t ed25519 -C "your_email@example.com"
$ eval "$(ssh-agent -s)"
> Agent pid 59566
$ ssh-add ~/.ssh/id_ed25519

2. Create a config file in ~/.ssh and add below content:

cd ~/.ssh
vi config
# below is the content of config file
Host github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_ed25519

3. Add the public key to github

4. Run below command to see which github account is used:

$  ssh -T git@github.com
Hi <User>! You've successfully authenticated, but GitHub does not provide shell access.

5. If git push command still asking for username and password, you may need to change the URL in the git config file, following this doc: https://mkyong.com/git/github-keep-asking-for-username-password-when-git-push/

--

--

No responses yet