In this short tutorial we are going to see how you can generate a new SSH key and add it to GitHub, so you can access your private repositories and manage them locally or from your server, running the commands git pull, git push and any other that has restrictions.
This tutorial will work on any operating system, be it Windows, MacOS or any Linux distribution, be it Debian, CentOS or Ubuntu. If you use Windows, it will work as long as you use the Linux terminal or a terminal emulator like Git Bash.
To follow this tutorial you will need basic knowledge of the command line:
- If you use MacOS, you can refer to the MacOS command line introduction tutorial.
- If you use Linux, you could refer to the Linux command line introduction tutorial.
- If you use Windows, you could also consult the Linux command line introduction tutorial.
First we will see how to generate an SSH key and then how to add it to GitHub.
- 1 How to generate a new SSH key
- 2 How to add an SSH key to SSH agent
- 3 How to add an SSH key to your GitHub account
How to generate a new SSH key
To generate a new SSH key on your system, follow the steps below:
1. Open command terminal window or access your server via SSH.
2. Run the following command, replacing [email protected] with your email address:
$ ssh-keygen -t ed25519 -C "[email protected]"
This will create the public and private key pair we need. It is important that you keep the key name ed25519, as it is the one that GitHub will look for by default. In case your system does not support the ed25519 algorithm you will have to run the following command instead of the previous one:
$ ssh-keygen -t rsa -b 4096 -C "[email protected]"
3. You will be prompted to enter a file name to save the key to. Press Enter to use the default path and filename:
> Enter a file in which to save the key (/c/Users/you/.ssh/id_algorithm):[Press enter]
4. You will then be prompted to enter a password for the key. You can enter a password or leave it blank by pressing Enter to use none:
> Enter passphrase (empty for no passphrase): [Type a passphrase] > Enter same passphrase again: [Type passphrase again]
If you are going to use a password, be sure to consult the official documentation, which explains how to work with SSH key passwords.
5. And with this we will have generated the key. For more information, you can consult the official guide on how to generate a GitHub SSH key.
How to add an SSH key to SSH agent
Once the key is generated, you should add it to your system's SSH agent to manage it, so that you do not have to specify it continuously. To add the key to your system's SSH agent follow these steps:
1. Check that the SSH agent is running or start it using the following command:
$ eval "$(ssh-agent -s)"
You should get the PID of the process as output of the command:
> Agent pid 68224
2. Then add the SSH key to the SSH agent using the following command:
$ ssh-add ~/.ssh/id_ed25519
If you have used a name other than ed25519, you must replace the key name in the above command.
That's it. Now all you have to do is add the key to your GitHub account to use it.
How to add an SSH key to your GitHub account
To add the SSH key you have created to your GitHub account you must follow the steps below:
1, The first thing to do is to copy the SSH key, which you will find in the
~/.ssh/id_ed25519.pub directory if you have used the name ed25519 for the key. If you have installed the clip utility use the following command to copy the key:
$ clip < ~/.ssh/id_ed25519.pub
If you do not have the clip utility installed, open the file containing the key with any editor and copy it. In the following example we use the nano editor:
2. Next, log in to your GitHub account using your browser and access your account settings by clicking on the profile picture in the top right of the menu and then Settings.
3. Click on the SSH and GPC keys option in the Access section of the left menu.
4. Click New SSH Key and enter a name for the key in the Title field. Then paste the SSH key you copied earlier into the Key field, leaving the Key type option selected.
5. Finally click the Add SSH key button. If you are prompted for your account password, enter it.
With this you have now added the password you have generated to your GitHub account.
Licenciada en Bellas Artes y programadora por pasión. Cuando tengo un rato retoco fotos, edito vídeos y diseño cosas. El resto del tiempo escribo en MA-NO WEB DESIGN AND DEVELOPMENT.
Tools to build PWA quickly
For quite some time now, UX has been the focus of modern web development. Several factors affect this, including page load speed, usability, scalability, and design. But now more customers…