Github Deploy Key

Jim Kang
2 min readMar 3, 2022

Let’s say Micky Mouse use his github account on a server, and then next day he was fired from Disney, wouldn’t that be something if you’re taking over the deployment? This is why you need github deploy key — A key you use on server to do git stuff.

basically deploy key = server public ssh key

1. Generate SSH Key

We want to generate a new ssh key instead of using the default id_rsa because github doesn’t allow same key to be used twice. Maybe you have 2+ repo in same server, then sharing the same deploy key will not work. To generate new key, run the following:

DO NOT COPY AND PASTE FOLLOWING BLATANTLY

> cd ~/.ssh 
> ssh-keygen -t ed25519 -C "team-email@company.com" -f "REPO-NAME-HERE"

New public and private key will be generated inside ~/.ssh I am using repo-name as the key file name so that it’s better for me to extinguish.

2. Add Public Key to Github Repo

Navigate to your github repo and look under Settings > Deploy Keys. Find Add deploy key button and add the content your newly-generated-key.pub there.

3. Setup SSH Config

Now let’s match which repo use which private ssh key (repo <=> private key). If you don’t have ~/.ssh/config you can create one:

> touch ~/.ssh/config 
> chmod 600 ~/.ssh/config

Inside the config file, enter these

DO NOT COPY AND PASTE FOLLOWING BLATANTLY

Host ALIAS-NAME-1 
HostName github.com
IdentityFile ~/.ssh/private-key-1
Host ALIAS-NAME-2
HostName github.com
IdentityFile ~/.ssh/private-key-2

4. Clone Project or Configure Git

Now you can clone using

DO NOT COPY AND PASTE FOLLOWING BLATANTLY

> git clone git@ALIAS-NAME-1:OWNER/THE-GIT-REPO.git

or if you already have the repo, navigate to the repo and

DO NOT COPY AND PASTE FOLLOWING BLATANTLY

> git remote set-url origin git@ALIAS-NAME-1:OWNER/THE-GIT-REPO.git

After the above setup you’ll be able to git pull (or fetch)

--

--

Jim Kang

love writing bit sized programming memo, acoustic guitarist, proud daddy of 5 and great listener (to my kids)