Setting up the SSH private and public keys is one of the most frequent problems encountered when starting started with Git and GitHub. On top of that, GitHub no longer supports Git password authentication.
You can no longer access Git on GitHub using your GitHub account password as of August 13, 2021. Making an SSH key and closing your Git repositories with SSH is a quick and significantly more secure way to connect with your GitHub repositories.
Table of Content
Things You Should Know About SSH
- SSH allows you to log in to a server, such as GitHub, without disclosing your username or password.
- The cryptographic protocol known as SSH, or Secure Shell, is founded on the idea of public-private keys.
- Git uses SSH because it is both quicker and more secure than constantly putting in your login and password.
- You’ve probably noticed that GitHub is complaining about the lack of an SSH key on your computer.
How to Add SSH on Git
Follow the steps below to add your SSH on Git!
Step 1: Git installation
- By using the following command in any open terminal, you can determine whether Git is already installed:
- You must install Git if you receive an error message. In any case, I advise setting up or updating Git.
- Open https://git-scm.com right away. I can currently see version 2.30.0.
- Open the installer that you downloaded and proceed with the installation. Leave all settings at their defaults unless you are an expert.
- A new program called Git Bash, a terminal substitute for Cmd or Powershell, has also been installed by this wizard.
- Run the following command from Git Bash or any terminal of your choosing.
Step 2: Setting up Git
- Please modify the commands below with your name and email before continuing. Any modifications you make to any Git repository will include them. Do it right away to avoid losing points with your coworkers.
git config --global user.name “Your Name” git config --global user.email “firstname.lastname@example.org”
Step 3: Clone a GitHub repository
- Go to the repository you wish to clone after logging into your GitHub account. I’m assuming you’re cloning your own repositories, whether they be public or private, in order to make changes.
- If SSH is not already selected, click the green Code button, pick it, and then copy the address that appears.
- Execute the command below.
git clone (PASTE HERE YOUR ADDRESS)
- You shouldn’t be concerned if you see a warning that reads, “The legitimacy of host ‘github.com’ can’t be determined.” You will get this warning if this is your first time connecting to this server. If you choose “yes,” it won’t annoy you ever again.
Step 4: Making an SSH key
- Ssh-keygen will be the tool we employ. So launch a terminal and enter the following command:
- You will first be questioned about where the keys should be kept. Your user folder will by default include a folder named .ssh. Simply leave it alone and press Enter.
- You will then be prompted to choose a password to secure your private key. Anyone who obtains your private key without a password can pretend to be you.
- Setting a password is a good idea, but it can be difficult to do it in Windows such that you don’t have to enter it each time you execute a Git command. Therefore, keep it blank for the time being, and simply press Enter twice.
- A pair of your public and private keys have been created.
- To review what you currently have:
id_rsa. This is your PRIVATE key. Never share this with anyone else. It’s your little secret.
id_rsa.pub. This is your PUBLIC key. There are no surprises in this. It can be distributed to others.
Step 5: Adding your SSH key to GitHub
- Open your public key in your preferred text editor. To inspect the file’s contents, I’ll use the terminal and the cat command.
- Copy the file’s content in its entirety.
- Go to your profile settings in GitHub to get your SSH and GPG keys.
- Click Add SSH key after pasting your public key into the substantial text box that appears on the screen. You should definitely give your key a name so you can remember it later.
Step 6: Clone a GitHub repository (again)
- It is now time to issue the clone command once more, and it ought to succeed.
- Any tools or code editors you may be using now integrate with Git. Changes from GitHub can be pushed and pulled without any problems.
- The SSH key feature on GitHub makes it easy to access your repositories from the command line.
- You can use your key instead of your username and password every time you push to or pull from your repository.
- Using an SSH key to log into your account is a quick and safe way to do so. It’s convenient because you don’t have to remember a long password.
- You can make your real password so long and hard to guess that neither people nor computers could figure it out. The SSH key works just like a real key that you alone have.