Skip to main content

[Note #1] How to configure SSH Github

Updated 2 min readMarkdown
[Note #1] How to configure SSH Github

In short just follow Generate ssh key and Add the key to Github. This note using Mac in the journey.

Generate SSH key

  • Open terminal.
  • Use command below to generate ssh key. Use an email that signup with Github.
$ ssh-keygen -t ed25519 -C "your_email@example.com"
  • Press enter
> Enter a file in which to save the key (/Users/you/.ssh/id_algorithm): [Press enter]
  • Press enter until end or type a passphrase for ssh key (not your Github's password).
> Enter passphrase (empty for no passphrase): [Enter / Type a passphrase]
> Enter same passphrase again: [Enter / Type passphrase again]

If you do until this line you have generated your ssh key for securing your communication with Github or other platform by encrypt/decrypt data using ed25519 algorithm.

Adding SSH key to the ssh-agent

  • Start agent process in background.
$ eval "$(ssh-agent -s)"
  • Create a ssh config file.
$ touch ~/.ssh/config

For using passphrase.

Host *
  AddKeysToAgent yes
  UseKeychain yes
  IdentityFile ~/.ssh/id_ed25519

Without using passphrase.

Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519

Add your SSH private key to the ssh-agent.

$ ssh-add -K ~/.ssh/id_ed25519

Adding a new SSH key to Github

  • Copy all the contain in ~/.ssh/id_ed25519.pub
  • Paste the contain in key form by navigate to Github's Profile > Settings > "Access" section > SSH and GPG keys > New SSH key

image.png

  • Then click "Add SSH key" and confirm with your password.

Configure Github to using SSH even link was https

$ touch ~/.gitconfig
$ open ~/.gitconfig
# Enforce SSH
[url "ssh://git@github.com/"]
  insteadOf = https://github.com/

If you want to setup for other site this was an example.

# Enforce SSH
[url "ssh://git@github.com/"]
  insteadOf = https://github.com/
[url "ssh://git@gitlab.com/"]
  insteadOf = https://gitlab.com/
[url "ssh://git@bitbucket.org/"]
  insteadOf = https://bitbucket.org/

Reference

Cover Photo by Roman Synkevych 馃嚭馃嚘 on Unsplash

About the author

  • A hobby developer, he love explore new things and sharing his note with others.

No comments yet. Be the first to comment.