The following steps are mainly for Windows machine, but these steps are very similar when you are on Mac or Linux.
Open terminal or something like terminal such as Git Bash
Go to .ssh directory, we don’t have to go there to generate ssh key.
$ cd ~/.ssh
$ ssh-keygen -t ed25519 -C “your_email@example.com”
Note: If you are using a legacy system that doesn’t support the Ed25519 algorithm, use:
$ ssh-keygen -t rsa -b 4096 -C “your_email@example.com”
Note: email address is the one that you use to register github account
I am using a legacy system, so I use rsa
$ ssh-keygen.exe -t rsa -b 4096 -C “john_cheng@byu.edu”
Generating public/private rsa key pair.
(this shows where the key will be stored)
Enter file in which to save the key (/c/Users/jc2349/.ssh/id_rsa):
(I usually just leave them empty)
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
(indicate where the key is stored)
Your identification has been saved in /c/Users/jc2349/.ssh/id_rsa
Your public key has been saved in /c/Users/jc2349/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:wkwDLIFcXCl2nDMq7MeTSP6Xj6/y2REsRtlp/lkfVa4 john_cheng@byu.edu
The key’s randomart image is:
+—[RSA 4096]—-+
|..+++.o .|
|…+.Oo . ..|
|. ..+o=+ ..|
| + ..++. .. |
|+ + .o++S . .E |
| + =. ..o o . . |
| o . .. o . |
| o o+ . |
| +=++ |
+—-[SHA256]—–+
copy the public key
Go to the key directory where keys were generated to copy the key
cd ~/.ssh
$ cat id_rsa.pub
It should look like something below.
ssh-rsa xxxxxx youremailaddress@gmail.com
After copy the ssh public key, past it in your Github account.
Go to Settings
Then, go to SSH and GPG Key
Click on new SSH Key and then past your public key content in there.
Then, click Add SSH Key to save your key.
After you create your new SSH key on Github you can also verify it on your local machine.
However, you will need to use Git Bash. (At least this was what happen to me when I ran the test.)
How to install Git Bask on your windows machine.
jc2349@CHENJOHN1 MINGW64 ~/.ssh
$ ssh -T git@github.com
Hi nuevenueve! You’ve successfully authenticated, but GitHub does not provide shell access.
Use in the end when you want to refer to the outcome of events or disclose a result
Source:
How to create SSH key
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent
How to copy SSH key to Github
https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account