Generating a new SSH key and adding it to the ssh-agent

Generating a new SSH key and adding it to the ssh-agent

06/10/2021 Off By devk2x

Generating a new SSH key

Chạy lệnh bên dưới (có thể không cần nhập pass phase – nhập enter để tiếp tục)

bd@devk2x % ssh-keygen -t rsa -b 4096 -C "devk2x@gmail.com"
Generating public/private rsa key pair.
Enter file in which to save the key (/Users/bd/.ssh/id_rsa): 
/Users/bd/.ssh/id_rsa already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /Users/bd/.ssh/id_rsa.
Your public key has been saved in /Users/bd/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:Imkg4JVUlE4ErSHIg15TNWrCIoEsQCqx2KTB1RysOw4 devk2x@gmail.com
The key's randomart image is:
+---[RSA 4096]----+
|/.+=%*+o         |
|X#o= B. .        |
|@o*oBo           |
|oo.+oo           |
|    = . S        |
| E + . .         |
|  o .            |
|   .             |
|                 |
+----[SHA256]-----+

Adding your SSH key to the ssh-agent

Start the ssh-agent in the background.

bd@devk2x % eval "$(ssh-agent -s)"
Agent pid 4684

Add the SSH key to your account on GitHub

Copy the SSH public key to your clipboard.

bd@devk2x % pbcopy < ~/.ssh/id_rsa.pub

In the upper-right corner of any page, click your profile photo, then click Settings.

In the user settings sidebar, click SSH and GPG keys.

Authentication keys

Click New SSH key or Add SSH key.

SSH Key button

Paste your key into the “Key” field.

The key field

Click Add SSH key.

The Add key button

Test connection to github

bd@devk2x % ssh -T git@github.com
Hi devk2x! You've successfully authenticated, but GitHub does not provide shell access.

Documents

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/generating-a-new-ssh-key-and-adding-it-to-the-ssh-agent

https://docs.github.com/en/authentication/connecting-to-github-with-ssh/adding-a-new-ssh-key-to-your-github-account