Generate a new SSH key and add it to Github

Let’s generate a SSH key for Github.
Then add it to Github and connect it with Sourcetree.

1. Check if a SSH key exists

(For Mac, Linux) Open terminal.
(For Windows) Open Git Bash.

Then, type ls -al ~/.ssh on your environment.
If id_rsa and id_rsa.pub exist, you can pass step 2.

2. Generate a new SSH key

$ ssh-keygen -t rsa -b 4096 -C "<your email>"

You can see Generating public/private rsa key pair. and finish making your SSH key.

3. Copy the public key

(For Mac) pbcopy < ~/.ssh/id_rsa.pub
(For Linux) (1) xclip -sel clip < ~/.ssh/id_rsa.pub or (2) cat ~/.ssh/id_rsa.pub and copy the output.
(For Windows) cat ~/.ssh/id_rsa.pub | clip

4. Add to Github

Log in Github → Settings → SSH and GPG keys → New SSH key
Then, paste your public key to the box.

If you don’t use Sourcetree, you have finished it!
Test with ssh -T git@github.com to see the connection.

5. Connect it with Sourcetree

Tools → Options
Below SSH Client Configuration, change SSH Client to OpenSSH.


💬 Any comments and suggestions will be appreciated.

Leave a comment