# [Note #1] How to configure SSH Github

In short just follow [Generate ssh key](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent) and [Add the key to Github](https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account). 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.

```bash
$ ssh-keygen -t ed25519 -C "your_email@example.com"
```

- Press enter

```txt
> 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).

```txt
> 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.

```bash
$ eval "$(ssh-agent -s)"
```

- Create a ssh config file.

```bash
$ touch ~/.ssh/config
```

- Configure OpenSSH to try using the generated key with [every host](https://man.openbsd.org/ssh_config#Host) while [automatic add key to ssh agent](https://man.openbsd.org/ssh_config) by edit file `~/.ssh/config`.

For using passphrase.

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

Without using passphrase.

```toml
Host *
  AddKeysToAgent yes
  IdentityFile ~/.ssh/id_ed25519
```

Add your SSH private key to the ssh-agent.

```bash
$ 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](https://cdn.hashnode.com/res/hashnode/image/upload/v1659273175162/p3Cem67DV.png align="left")
- Then click "Add SSH key" and confirm with your password.

# Configure Github to using SSH even link was https

```bash
$ touch ~/.gitconfig
```

```bash
$ open ~/.gitconfig
```

```toml
# Enforce SSH
[url "ssh://git@github.com/"]
  insteadOf = https://github.com/
```

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

```toml
# 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 <a href="https://unsplash.com/@synkevych?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Roman Synkevych 🇺🇦</a> on <a href="https://unsplash.com/s/photos/github?utm_source=unsplash&utm_medium=referral&utm_content=creditCopyText">Unsplash</a>
