Git and GitHub should be used by every developer. They are widely used in nearly every type of software development project.
Hosting services like Kinsta have received hundreds of 5-star ratings. Every day.
src=”https://kinsta.com/wp-content/themes/kinsta/images/components/quotes/trustpilot-logo.png” alt=”Trustpilot logo” width=”82″ height=”20″>
I love the support and experience Kinsta’s live chat agents provide. For large websites, especially ecommerce sites, the 24/7 support is a huge advantage.
width=”80″ height=”80″ src=”https://kinsta.com/wp-content/uploads/2019/07/leland-zaremba.png” class=”avatar–round” alt=”leland zaremba” loading=”lazy”>
Leland Zaremba Learn why
Gitlab and Bitbucket also offer Git hosting, but GitHub is the most preferred choice for developers. To make your profile more appealing to recruiters, you can edit it.
Git and GitHub can be used to organize and collaborate with other developers and, of course, at Kinsta.
Git and Git are both related tools. You need to keep your workflow updated with each one.
SSH keys are recommended for all of your computers. This tutorial will explain what SSH keys are and their benefits, as well as how to create and configure GitHub SSH key.
Let’s get started!
What are SSH Keys?
SSH keys can be described as credentials that allow secure access to remote computers via the internet using the SSH protocol. This authentication is usually done in a command-line environment.
This protocol uses client-server architecture. You, the client, will need special software called an SSH client to log in to a remote server to execute commands. This is what you do when you authenticate via a terminal to GitHub.
loading=”lazy” class=”wp-image-114305 size-large” src=”https://kinsta.com/wp-content/uploads/2022/01/Git-push-1024×396.png” alt=’Terminal showing two commands: “git commit -am “Added comment in the structured-programming example file” and “git push” with the success response from the GitHub server’ width=”1024″ height=”396″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/Git-push-1024×396.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/Git-push-300×116.png 300w, https://kinsta.com/wp-content/uploads/2022/01/Git-push-768×297.png 768w, https://kinsta.com/wp-content/uploads/2022/01/Git-push.png 1310w” sizes=”(max-width: 1024px) 100vw, 1024px”>
SSH isn’t just for GitHub. Other platforms such as Kinsta, Google Cloud and Amazon Web Services use SSH to provide secure access to their services.
Before we get into the details of how SSH keys work, it is important to distinguish between private and public keys.
Public Keys vs. Private Keys
Let’s begin with the basics.
Asymmetric encryption is a type of cryptography used in the SSH protocol. Although it may sound strange and complicated, this term is actually quite simple.
Asymmetric encryption, in essence, is a system that uses two keys: public and private keys.
The public key, as you might guess, can be shared with anyone. It is used to encrypt data and convert the message into secret code, or ciphertext. The key is sent to servers, or other systems to encrypt data before it can be sent over the internet.
The private key, on the other hand is what you need to keep secret. It is used to decrypt encrypted data using your public key. It is essential to decrypt encrypted data.
This allows the server and you to maintain a secure communication channel for the transmission of the information.
Here’s what happens behind the scenes when you connect via SSH to a server:
The client sends the server the public key.
It is important that you keep your private keys secure and not share them with anyone. They are the key to all information you receive.
GitHub: Using SSH keys
Github has stopped accepting password authentication for command line access since August 13, 2021. You will need to either use an SSH key or a personal access token to authenticate.
This is what happens when you attempt to authenticate using your GitHub password instead of HTTP in a terminal.
Username for ‘https://github.com’: yourusername Password for ‘https://firstname.lastname@example.org’: remote: Support for password authentication was removed on August 13, 2021. Instead, please use a personal access token. remote: Please see https://github.blog/2020-12-15-token-authentication-requirements-for-git-operations/ for more information. fatal: Authentication failed for ‘https://github.com/yourusername/repository.git/’
GitHub requires your public key in order to allow you to modify any repos via SSH.
Let’s look at how to generate SSH keys locally.
How to Create SSH Keys Locally
You now have a basic understanding of the SSH protocol, as well as the differences between private and public keys. It’s time for you to establish the secure SSH channel between the machine and your GitHub repos.
You should have a GitHub account and a terminal/command prompt for Git before we can move on. Git bash is required if you are running Windows. This includes all the tools that you will need to follow this tutorial.
OpenSSH Client is the most widely used open-source software to connect via SSH. It’s automatically installed on Windows 10, macOS and Linux so you don’t have to worry about it.
To generate local SSH keys, you will need to open a command prompt for Windows or a Unix-based system terminal. You can usually do this by looking for “terminal”, cmd, or “powershell”, in your application panel and clicking on the icon.
loading=”lazy” class=”wp-image-114306 size-large” src=”https://kinsta.com/wp-content/uploads/2022/01/open-terminal-1024×526.png” alt=’Application finder showing different terminal applications, including “Terminal Emulator”, “Alacritty”, and “Kitty”.’ width=”1024″ height=”526″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/open-terminal-1024×526.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/open-terminal-300×154.png 300w, https://kinsta.com/wp-content/uploads/2022/01/open-terminal-768×394.png 768w, https://kinsta.com/wp-content/uploads/2022/01/open-terminal-1536×788.png 1536w, https://kinsta.com/wp-content/uploads/2022/01/open-terminal.png 1584w” sizes=”(max-width: 1024px) 100vw, 1024px”>
Search for terminal applications
Linux users will find the shortcut Ctrl+ Alt + T to open a terminal.
You should now have a window that looks like the image below.
loading=”lazy” class=”wp-image-114307 size-large” src=”https://kinsta.com/wp-content/uploads/2022/01/terminal-1024×511.png” alt=”Semi-transparent terminal application running the fish shell.” width=”1024″ height=”511″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/terminal-1024×511.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/terminal-300×150.png 300w, https://kinsta.com/wp-content/uploads/2022/01/terminal-768×383.png 768w, https://kinsta.com/wp-content/uploads/2022/01/terminal-1536×766.png 1536w, https://kinsta.com/wp-content/uploads/2022/01/terminal-360×180.png 360w, https://kinsta.com/wp-content/uploads/2022/01/terminal.png 1783w” sizes=”(max-width: 1024px) 100vw, 1024px”>
To generate a local SSH pair, run the following command:
ssh-keygen -t ed25519 -C “email@example.com”
Let me tell you something: This command is impossible to remember! It’s a command that developers must Google every time.
It is a long command with random numbers and forgettable details.
It is important to be able to understand every command we enter into our terminals. Let’s take a look at each one.
How did we increase our traffic by more than 1000%?
Join over 20,000 others who receive our weekly newsletter, which includes insider WordPress tips.
Subscribe Now ssh keygen: This command-line tool is used to create a new pair SSH keys. Its flags can be viewed with ssh keygen help-t. The -t flag indicates the algorithm used for creating the digital signature of the key pairs. If your system supports it ed25519 will be the best algorithm to create SSH keys pairs.
Once you have typed the command in your terminal, you will need to input the file where you want to save the keys. It is located in your home directory in a hidden folder called “.ssh”, by default. However, you can change this to suit your needs.
Next, you will be asked to enter a passphrase that you want to add to your key pairing. If your device is ever compromised, this adds an additional layer of security. Although it is not mandatory to include a passphrase in your device, it is highly recommended.
This is how the entire process looks like.
loading=”lazy” class=”size-large wp-image-114308″ src=”https://kinsta.com/wp-content/uploads/2022/01/ssh-keygen-1024×540.png” alt=’ssh-keygen command with various messages including the file the keys will be saved “/home/daniel/.ssh/kinsta_keys”, passphrase input, and the resulting key fingerprint.’ width=”1024″ height=”540″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/ssh-keygen-1024×540.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/ssh-keygen-300×158.png 300w, https://kinsta.com/wp-content/uploads/2022/01/ssh-keygen-768×405.png 768w, https://kinsta.com/wp-content/uploads/2022/01/ssh-keygen.png 1133w” sizes=”(max-width: 1024px) 100vw, 1024px”>
You can see that this command creates two files in your directory (commonly /.ssh: the public key with a.pub extension and the private without an extension).
Later, we’ll show how to add your public key to your GitHub Account.
dd SSH Key to the ssh agent
The ssh–agent program runs in background. It stores your passphrases and private keys safely and makes them available for you to use with ssh. It is a wonderful utility that allows you to save time by not having to type your passphrase each time you connect to a server.
This is how you will add your private key to the agent. Here’s how:
Check that ssh agent is running in background
If you receive a message like this, it means that everything is okay. This message means that the ssh agent is running under a specific process id (PID).
Your SSH private key (the one that does not have an extension) should be added to the ssh agent.>ssh_add /.ssh/kinsta_keys
You should replace kinsta_keys by the name of your SSH keys. This key should be called “id_algorithm_used” if it is your first key.
dd SSH key to GitHub Account
Last, add your public key into your GitHub account. Follow these steps:
Copy the SSH public key to your clipboard You can open the file where it is located with a text editor and copy it, or use the terminal to show its contents.>cat ~/.ssh/kinsta_keys.pub # ssh-ed25519 AAAAC3NzaC1lZDI1NTE5AAAAIJl3dIeudNqd0DPMRD6OIh65tjkxFNOtwGcWB2gCgPhk firstname.lastname@example.orgLog into GitHub ] and go to the upper-right section of the page, click in your profile photo, and select Settings.
loading=”lazy” class=”size-full wp-image-114309″ src=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-settings.png” alt=”GitHub upper-right panel showing different sections with an arrow pointing to the Settings section.” width=”298″ height=”841″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-settings.png 298w, https://kinsta.com/wp-content/uploads/2022/01/GitHub-settings-106×300.png 106w” sizes=”(max-width: 298px) 100vw, 298px”>
Next, select Profile and click on GPG keys.
loading=”lazy” class=”size-full wp-image-114310″ src=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-ssh-gpg-keys.png” alt=”Profile settings panel showing the SSH and GPG keys option.” width=”374″ height=”709″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-ssh-gpg-keys.png 374w, https://kinsta.com/wp-content/uploads/2022/01/GitHub-ssh-gpg-keys-158×300.png 158w” sizes=”(max-width: 374px) 100vw, 374px”>
GPG and SSH keys.
Click on the New SSH Key button.
loading=”lazy” class=”size-large wp-image-114311″ src=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-new-ssh-key-1024×340.png” alt=”SSH keys section with an arrow pointing to the New SSH key button.” width=”1024″ height=”340″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/GitHub-new-ssh-key-1024×340.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/GitHub-new-ssh-key-300×99.png 300w, https://kinsta.com/wp-content/uploads/2022/01/GitHub-new-ssh-key-768×255.png 768w, https://kinsta.com/wp-content/uploads/2022/01/GitHub-new-ssh-key.png 1330w” sizes=”(max-width: 1024px) 100vw, 1024px”>
New SSH key button
Your new SSH key on GitHub should be given a title — this is usually the device that you will use the key from. Then, paste the key in the Key area.
loading=”lazy” class=”size-large wp-image-114312″ src=”https://kinsta.com/wp-content/uploads/2022/01/title-key-field-1024×587.png” alt=’Add a new SSH key form with the fields “Title” and “Key”.’ width=”1024″ height=”587″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/title-key-field-1024×587.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/title-key-field-300×172.png 300w, https://kinsta.com/wp-content/uploads/2022/01/title-key-field-768×440.png 768w, https://kinsta.com/wp-content/uploads/2022/01/title-key-field.png 1309w” sizes=”(max-width: 1024px) 100vw, 1024px”>
Create a new SSH key.
Add your SSH key.
loading=”lazy” class=”wp-image-114313 size-full” src=”https://kinsta.com/wp-content/uploads/2022/01/add-ssh-key-button.png” alt=”Add SSH key button.” width=”451″ height=”155″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/add-ssh-key-button.png 451w, https://kinsta.com/wp-content/uploads/2022/01/add-ssh-key-button-300×103.png 300w” sizes=”(max-width: 451px) 100vw, 451px”>
Add the SSH key button
A Repo Push is a way to test SSH connection
Now it’s time for you to verify everything that you have done. To ensure that your connection is working correctly, you will change, commit, then push to an existing repository using SSH.
All Kinsta hosting plans come with 24/7 support from our WordPress engineers and developers. Chat with the same team who supports Fortune 500 clients. Take a look at our plans!
We will use this example to modify the HTML site that we created in our Git for Web Development tutorial.
We’ll first need to clone this repository onto our local machine. You can copy the SSH address from the repo page at GitHub.
loading=”lazy” class=”size-large wp-image-114315″ src=”https://kinsta.com/wp-content/uploads/2022/01/clone-ssh-1024×498.png” alt=”GitHub page showing SSH clone command.” width=”1024″ height=”498″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/clone-ssh-1024×498.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/clone-ssh-300×146.png 300w, https://kinsta.com/wp-content/uploads/2022/01/clone-ssh-768×373.png 768w, https://kinsta.com/wp-content/uploads/2022/01/clone-ssh.png 1343w” sizes=”(max-width: 1024px) 100vw, 1024px”>
SSH clone command
Next, use a terminal to clone your repo
git clone email@example.com:DaniDiazTech/HTML-site.git
Let’s now add a simple tag to the index.html file.
loading=”lazy” class=”wp-image-114316 size-large” src=”https://kinsta.com/wp-content/uploads/2022/01/new-title-1024×351.png” alt=’Simple HTML site with the title “A new title”, and four pictures of tech items.’ width=”1024″ height=”351″ srcset=”https://kinsta.com/wp-content/uploads/2022/01/new-title-1024×351.png 1024w, https://kinsta.com/wp-content/uploads/2022/01/new-title-300×103.png 300w, https://kinsta.com/wp-content/uploads/2022/01/new-title-768×263.png 768w, https://kinsta.com/wp-content/uploads/2022/01/new-title.png 1522w” sizes=”(max-width: 1024px) 100vw, 1024px”>
Simple HTML site.
Once you have done this, commit your changes.
Git commit -am “Added simple title”
Push them to GitHub exactly as you would normally.
Congratulations if everything went well! Congratulations! You have just created an SSH connection between your computer and GitHub.
Multi-SSH keys for different GitHub accounts can be managed
It is difficult to use SSH between multiple GitHub accounts, such as one for personal projects and another for work. To authenticate to different GitHub accounts, you would normally need two separate machines.
This can be easily solved by configuring SSH config.
Let’s get to it.
Add another SSH key pair to your other GitHub account. Keep in mind the name of the file you’re assigning the new key to.>ssh-keygen -t ed25519 -C “firstname.lastname@example.org”Create the SSH config file. The config file instructs the ssh programme how it should behave. The default config file is not present. To make it appear, go to the.ssh/ directory:>touch /.ssh/configModify SSH config. Copy the following code into the config file:>#Your daily GitHub account Host github.com Name github.com IDFile /.ssh/id_ed25519 IdentitiesOnly Yes # Work account Host github.com identityFile /.ssh/work_key_file IdentitiesOnly Yes
You can now authenticate via SSH with your secondary or work account.
Congratulations! You’ve now learned all the necessary knowledge to connect to GitHub via SSH.
This tutorial covered the SSH protocol and the differences between private and public keys. It also showed how to create keys, add them into GitHub and manage multiple SSH keys to different GitHub accounts. Your private key must remain private unless you wish to have access to all of your data.
Now you are ready to create a seamless workflow using Git and GitHub. Keep programming!
How to Generate SSH Keys For GitHub