Generating a new SSH key and adding it to the ssh-agent in Mac
Published: 2024-05-08 10:03:57

1. Go to github profile
2. Go to Profile settings

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/fp3v2rfwqv35wvp1sbnj.png)
3. Then click on SSH and GPG keys

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r4gfbotfpz65ia5v2xor.png)

4. Open you mac terminal and Paste the text below, replacing the email used in the example with your GitHub email address 

```
ssh-keygen -t ed25519 -C "your_email@example.com"

```
5. After Run the command it show 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z5pjygyh0eczqfeehp6n.png)
Put your laptop password
6. After that it generate SHA256

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/z2z4lmwvxu3ix6z3f1ty.png)
7.Start the ssh-agent in the background.

```
$ eval "$(ssh-agent -s)"
> Agent pid 59566
```

8. Run 

```
open ~/.ssh/config  
```
If the file doesn't exist, create the file.

```
touch ~/.ssh/config
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/h97iy2rwpt9tunq1v3u6.png)

9. Open ~/.ssh/config file, then modify the file to contain the following lines. If your SSH key file has a different name or path than the example code, modify the filename or path to match your current setup.

Text

```
Host github.com
AddKeysToAgent yes
UseKeychain yes
IdentityFile ~/.ssh/id_ed25519 
```



![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/rzta41kf1v5mxjsldot1.png)
10. Run

```
ssh-add --apple-use-keychain ~/.ssh/id_ed25519   
```

If it show error like 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/mdo0g557omfs0bgy1ktg.png)

Then run 

```
ssh-keygen -t ed25519 -C Your_github_emailr@gmail.com
```

Then run 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/oq24hkkq63b29to736gn.png)

11. Go to your git hub account and click on "New SSH key"


![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/qqvu8v24asurpv1sgud2.png)

12. Provide title and key. 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/o60dsm5z1oytsq5s6hy4.png)

13. For "key" open .ssh > id_ed25519.pub 

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/r9ir3viptc1owivl1wam.png)

Now clone a project from your github repository 

```
git clone git@github.com:KhairunNaharNowrin/End-to-End-Testing-With-Cypress.git  
```

14. Setup the project environment
15. Run

```
git add .  
```
 

```
git commit -m "set up environment"
```

It will show error like "Author identity unknown"


Run

  

```
git config --global user.email "you@example.com"
```

```
  git config --global user.name "Your Name"
```

to set your account's default identity.
Omit --global to set the identity only in this repository.

```
git push   
```

![Image description](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/e7ncj0sqejaml83680fv.png)

reference - 

- https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
- https://www.youtube.com/watch?v=45YCxPnBj-w