Dear Git — A Quick guide to link Dev Ubuntu server with GitHub
I have done it literally countless time, but I always found myself googling how to create an ssh key on Ubuntu 20.XX depending on my server, however google returns a different article almost all the time which sucks because I know the steps I just want to avoid mistakes when typing. That push me to write this short tutorial using my saved commands over the years.
Create your SSH key — Assuming your on Ubuntu 20+
You can choose different algorithms for generating your ssh key, for simplicity I’ll go with RSA
ssh-keygen -t rsa -C "your@email.com"
your can name it whatever, I usually do
/home/<USERNAME>/id_rsa_<PROJECT_NAME> # make sure it's one word no space
Create config file
Create a config file in $nano /home/USERNAME/.ssh/config
and put the following contents
Host project_name.github.com
HostName github.com
User git
IdentityFile ~/.ssh/id_rsa_PROJECT_NAME
IdentitiesOnly yes
Copy the ssh public key and add to Deploy Keys on your GitHub repository under settings tab
Test your SSH key
ssh -T project_name.github.com
If you set everything correctly you should get
Hi your-github-username/your-project-repository! You've successfully authenticated, but GitHub does not provide shell access.
Clone your repository
Once you have linked your git, you can go ahead and clone your repository, if it’s already setup for git check tutorial on how to link GitHub repository and replace the URL with the below format, that’s beyond the scope of this tutorial
#format only ssh
git@project_name.github.com:your-git-username/your-project-repo.git# Clone
git clone git@project_name.github.com:your-git-username/your-project-repo.git
Make sure to replace PROJECT_NAME, GIT_USERNAME and PROJECT_REPO
Thanks for reading.