# Set single SSH key & multi-SSH keys for GitHub
> Date : 2017/08/30
> Author : Traveler
> Email : gotraveltoworld@gmail.com
---
## Steps
1. Create GitHub account.
2. Generate SSH key for Github
```bash
ssh-keygen -t rsa -b 4096 -C "name@xxx.com" -f ~/.ssh/github
```
3. Look and copy SSH public key.
```bash
cat ~/.ssh/github.pub
```
4. Import SSH public key on GitHub.
1. copy the public key(plain text)
2. paste the public key on Github settings page.
5. Generate SSH config for Github
```bash
vi ~/.ssh/config
```
Copy below config for Github
```bash
HostName github.com
User git
IdentityFile ~/.ssh/github
Port 22
```
6. Checking SSH connection.
```bash
# base syntax
ssh -T user@hostname
# An example by default.
ssh -T git@github.com
# An example by github config
ssh -T github
# An example by self-defined host name,
# noticed: you should set Host: githib.com-hello, for example: Host git@github.com-hello
ssh -T git@github.com-hello
# If you intend to test connection by verbos, just attach -v, for example,
ssh -vT git@github.com
```
If connection is ok, you can see `Hi (your name)! You've successfully authenticated, but GitHub does not provide shell access.`
7. If you need to set multi SSH keys, you can try to add config file. That will be separted from Host(a kind of alias).
```bash
touch ~/.ssh/config
vi ~/.ssh/config
```
And then you can add below configure into the config file.
```bash
Host hello
HostName github.com
User git
IdentityFile ~/.ssh/github
```
Below is a command for customized Host.
```bash
ssh -T hello
ssh -vt hello
```
### Reference
1. [GitHub設定指引](http://wiki.csie.ncku.edu.tw/github)
2. [SSH Keys for GitHub](https://jdblischak.github.io/2014-09-18-chicago/novice/git/05-sshkeys.html)
3. [多重 SSH Keys 與 Github 帳號](https://kuanyui.github.io/2016/08/01/git-multiple-ssh-key/)