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 ""
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/
The key fingerprint is:
The key's randomart image is:
+---[RSA 4096]----+
|/.+=%*+o         |
|X#o= B. .        |
|@o*oBo           |
|oo.+oo           |
|    = . S        |
| E + . .         |
|  o .            |
|   .             |
|                 |

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/

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
Hi devk2x! You've successfully authenticated, but GitHub does not provide shell access.