Published on

Generate SSH Key

Authors

Generate SSH Key

Checking for existing SSH keys

Open terminal, navigate to home folder (default when open terminal).

Enter below command to see if any SSH keys exist:

ls -al .ssh

The result will show a list contain id_rsa, id_rsa.pub, known_hosts if exist any SSH keys.

Generating a new SSH keys

Create a new SSH keys:

ssh-keygen -t rsa -b 4096 -C "your_email@example.com

Full options: ssh-keygen -t rsa -b 4096 -C "your_email@example.com"

Enter for default options.

Show SSH agent pid:

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

Add SSH key to the ssh-agent:

ssh-add ~/.ssh/id_rsa

Security

Should keep the private key not too open:

chmod 400 ~/.ssh/id_rsa

Copy SSH

If you using xclip, you could used copy SSH key quick as below:

xclip -sel clip < ~/.ssh/id_rsa.pub

Add SSH key to remote

Usually, you can add your SSH key in the Account > Setting section > SSH or Development keys.

ssh-copy-id -i ~/.ssh/id_rsa.pub remote-host

To remove the remote-host from known-host:

ssh-keygen -f "~/.ssh/known_hosts" -R remote-host

Verify SSH connection

Assume your remote git repo store on Github, this below will help you to check SSH connect to the remote.

ssh-add -L
ssh -T git@github.com

A message will show the result of connect process.

See more and details: https://help.github.com/articles/generating-an-ssh-key/