I'm Fabian and in this comprehensive guide I will show you step by step how you can: create a GitHub account, create an SSH Key, link your SSH Key with GitHub and finally test if your SSH Key is working.
GitHub is a service that allows you to upload, host, and manage your code using Git. Git is a version control system. GitHub and Git sound similar, but they are not the same thing or even created by the same company.
For this guide to work flawlessly you need to have Git installed on your machine. I don't have the time to teach this process in this guide, but no worries there are enough tutorials out there from more capable people than me teaching you how it's done.
Step 1: Signup
Go to GitHub.com and create an account! During the setup, it will ask you for an email address. This needs to be a real email and will be used by default to identify your contributions.
If you are privacy conscious, or just don’t want your email address to be publicly available, make sure you tick the following two boxes on the Email Settings page after you have signed in:
- Keep my email addresses private and
- Block command line pushes that expose my email
Having these two options enabled will prevent you from accidentally exposing your email address when working with Git and GitHub. You may also notice an email address under the Keep my email addresses private option, this is your private GitHub email address.
If you plan to use this, make note of it now as you will need it when setting up Git in the next step.
Step 2: Setup
For Git to work properly, we need to let it know who we are so that it can link a local Git user (you) to GitHub. When working on a team, this allows people to see what you have committed and who committed each line of code.
The following commands configure Git. Be sure to enter your own information inside the quotes (but include the quotation marks)!
git config --global user.name "Your Name"
git config --global user.email "yourname@example.com"
If you opted to use the private GitHub email address, the second command will look something like this:
git config --global user.email "123456789+example@users.noreply.github.com"
GitHub changed the default branch on new repositories from master
to main
. Change the default branch for Git using this command:
git config --global init.defaultBranch main
To enable colorful output with git
, type this:
git config --global color.ui auto
You’ll also likely want to set your default branch reconciliation behavior to merging:
git config --global pull.rebase false
To verify that things are working properly, enter these commands and verify whether the output matches your name and email address:
git config --get user.name
git config --get user.email
If you are a macOS user, run these two commands to tell Git to ignore .DS_Store files, which are automatically created when you use Finder to look into a folder. .DS_Store files are invisible to the user and hold custom attributes or metadata (like thumbnails) for the folder, and if you don’t configure Git to ignore them, pesky .DS_Store files will show up in your commits.
echo .DS_Store >> ~/.gitignore_global
git config --global core.excludesfile ~/.gitignore_global
Step 3: Create
An SSH key is a cryptographically secure identifier. It’s like a long password used to identify your machine.
First, we need to see if you have an Ed25519 algorithm SSH key already installed. Type this into the terminal and check the output with the information below:
ls ~/.ssh/id_ed25519.pub
If a message appears in the console containing the text “No such file or directory”, then you do not yet have an Ed25519 SSH key, and you will need to create one. If no such message has appeared in the console output, you can proceed to step 4. To create a new SSH key, run the following command inside your terminal.
ssh-keygen -t ed25519
When it prompts you for a location to save the generated key, just push Enter. Next, it will ask you for a password; enter one if you wish, but it’s not required.
Step 4: Link
Now, you need to tell GitHub what your SSH key is so that you can push your code without typing in a password every time.
Log into GitHub and click on your profile picture in the top right corner. Then, click on Settings
in the drop-down menu. Next, on the left-hand side, click SSH and GPG keys
. Then, click the green button in the top right corner that says New SSH Key
. Name your key something that is descriptive enough for you to remember what device this SSH key came from, for example, linux-ubuntu
.
Leave this window open while you do the next steps. Now you need to copy your public SSH key.
To do this, we’re going to use a command called cat
to read the file to the console.
cat ~/.ssh/id_ed25519.pub
Highlight and copy the entire output from the command. If you followed the instructions above, the output will likely begin with ssh-ed25519
and end with your username@hostname
. Now, go back to GitHub in your browser window and paste the key you copied into the key field. Keep the key type as Authentication Key
and then, click Add SSH key
.
You’re done! You’ve successfully added your SSH key!
Step 5: Test
When you test your connection, you'll need to authenticate this action using your password, which is the SSH key passphrase you created earlier.
-
First, open your terminal and enter the following:
ssh -T git@github.com
Now, you may see a warning like this:
> The authenticity of host 'github.com (IP ADDRESS)' can't be established.> ED25519 key fingerprint is SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU.> Are you sure you want to continue connecting (yes/no)?
-
Next, verify that the fingerprint in the message you see matches GitHub's public key fingerprint.
-
SHA256:uNiVztksCsDhcc0u9e8BujQXVUpKZIDTMczCvj3tD2s
(RSA) -
SHA256:br9IjFspm1vxR3iA35FWE+4VTyz1hYVLIE2t1/CeyWQ
(DSA - deprecated) -
SHA256:p2QAMXNIC1TJYWeIOttrVc98/R1BUFWu3/LiyKgUfQM
(ECDSA) -
SHA256:+DiY3wvvV6TuJJhbpZisF/zLDA0zPMSvHdkr4UvCOqU
(Ed25519)
If it does, then type
yes
:
> Hi USERNAME! You've successfully authenticated, but GitHub does not> provide shell access.
-
Last, verify that the resulting message contains your username.
Don’t let GitHub’s lack of providing shell access trouble you. You’ve successfully added your SSH key.
Top comments (0)