How I linked my Kali Linux to my github account through SSH
Tags: webdev, linux
Published: 2024-04-02 21:26:43

Linking your Kali Linux to your GitHub account through SSH can greatly streamline your workflow, allowing you to seamlessly push and pull code without the need to repeatedly enter your credentials. 
By establishing this secure connection, you enhance both efficiency and security in managing your projects. 

Me: In this article, I'll walk you through the simple steps I took in setting up SSH authentication between my Kali Linux system and my GitHub account.
Nobody: What of windows' users?.
Me: Windows' users can also follow my lead, but I will like them to use git bash as the command line.

Without further ado, let's jump into the game!.

Firstly, you need to generate an ssh key, and you can do that using the following command in your terminal:
```bash
ssh-keygen -t rsa -b 4096 -C your_email@example.com
```
replace `your_email@example.com` with your email address (must be the one associated with your Github account).


Secondly, save the ssh key. By default, the ssh key files are saved in the `~.ssh` directory. So, you can press enter to accept it or you can decide to change the location.
You will be prompted to enter and re-enter a passphrase which you can ignore by press enter immediately. Your key has been generated. 

![keygen](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/79f27tdncim98wchcyxf.png)

Thirdly, you need to add the new generated key to the `ssh-agent` (manages your ssh keys). So start the `ssh-agent` by running the command:
```bash
eval "$(ssh-agent -s)"
```

Now, add your ssh private key to the ssh-agent by running the following command:
```bash
ssh-add .ssh/id_rsa 
```
`.ssh/id_rsa` is the location of the private key from my current position in my terminal. Make sure you locate yours correctly.

Fourthly, Add the key to your github account.
Go to the `.ssh` folder, then locate and open `id_rsa.pub` in a text editor. Copy whatever is in there.
Now, let's paste it in our github.
Go to settings,
![github settings](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/xuyurltpiafyse7m69x4.png)

Go to SSH and GPG keys,
![SSH and GPG keys](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/jpr02wtcl5na8nciy6g4.png)

Click on **New SSH Key** button,
![New SSH Key](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/al0r8fwpbyk5xkw15s6a.png)

Give it a title (example - Linux SSH key), The Key type is Authentication Key, paste what you copied in `id_rsa.pub` in the Key field.
Your result will be similar to this.
![result](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mw9xrgcehjiuqzj8i4tv.png)

Now, let’s test the connection.
Run the following command in your terminal:
```bash
ssh -T git@github.com
```
If everything is done correctly, you see a similar message:
```bash
Hi username! You've successfully authenticated, but GitHub does not provide shell access.
```

But, some error like this might occur:
![github error](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/cz53zbb3xbm3jvo10hk4.png)

You will need to get the private key and input it instead of typing yes when asked if you want to continue connecting. 
To get the private key, you can run the command:
```bash
ssh-keygen -lf .ssh/id_rsa
```
You will get something like 
```bash
4096 SHA256:zjb3ddSf4AhvjyJdYDS4UqX+G0seY your_email.com (RSA)
```
Copy everything except 4096 and (RSA). And that’s the private key.
And you're good to go.
![success!](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/8gj0f3s5lrdofn6r2yzc.png)

Now I am able to perform Git operations on repositories for which I am authorized.
![git clone](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/tu117kud9h6j52093fa9.png)

Thanks.I hope it's helpful.