Add a New GitHub SSH Key Automatically 🔑

date
Oct 2, 2022
slug
add-a-new-github-ssh-key-automatically
status
Published
tags
GitHub
Productivity
summary
introduce handmade CLI tool - gh-ssh-keygen
type
Post
Every time you get a new machine and want to connect GitHub with SSH, it's so annoying to set up. Generate the SSH key after googling for a while and then manually copy & paste it to GitHub on their webpage.
Is it possible to do this whole process on the command line? Yes!
Today I'll introduce this brilliant CLI tool - gh-ssh-keygen.

How to use gh-ssh-keygen

There're two ways available.
Simply run this command if you don't want to install anything.
Otherwise, you can install the whole command.
If this command has already been installed, it'll skip or upgrade if the new version is available.
Then, run
After a few interactive steps, SSH key would be added to your GitHub account 🎉
If you want to know more about how to use it, checkout this video for detail!

How this command works

Internally, it is powered by Official GitHub CLI which provides API to upload ssh keys.
Except that, I connect the whole process with the MacOS (and Linux) package manager brew and OpenSSH auth utils ssh-keygen together.
Also, this command handles lots of package installation things and implement some extra validation for user input. Therefore, feel free to use it if you need to add SSH key to your GitHub account next time!
 

© maxam 2023 - 2024