[Switch] how to generate SSH key

mark it for future reference

This article is contained in Gevin's blog
Original Address: http://blog.igevin.info/posts/generate-ssh-key-for-git/

SSH key GitHub provides a way to communicate with, in this way, it is possible without entering a password, the remote end as their GitHub server, version control

step

  • SSH keys to check whether there is
  • Generate a new ssh key
  • Add the ssh key to the GitHub
How to generate SSH KEY
How to generate SSH KEY

1. Check whether there is SSH keys

Enter the following command, if there is a file id_rsa.pubor id_dsa.pubis added directly to Step 3 to GitHub SSH key, otherwise generated SSH key into the second step

ls -al ~/.ssh
# Lists the files in your .ssh directory, if they exist

2. Create a new ssh key

The first step: generating a public / private rsa key pair
in the command linessh-keygen -t rsa -C "[email protected]"

Default (/ your_home_path) generated at the respective paths id_rsaand id_rsa.pubtwo files, as shown in the code below

ssh-keygen -t rsa -C "[email protected]"
# Creates a new ssh key using the provided email
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):

Step two: Enter a passphrase (this step can be skipped)

After setting a passphrase, when version control, and each will be asked to enter a passphrase GitHub communication, to avoid certain "mistakes"

Enter passphrase (empty for no passphrase): [Type a passphrase]
Enter same passphrase again: [Type passphrase again]

sample result:

Your identification has been saved in /your_home_path/.ssh/id_rsa.
Your public key has been saved in /your_home_path/.ssh/id_rsa.pub.
The key fingerprint is:
#01:0f:f4:3b:ca:85:d6:17:a1:7d:f0:68:9d:f0:a2:db [email protected]

The third step: adding the newly generated key to the ssh-agent:

# start the ssh-agent in the background
eval "$(ssh-agent -s)"
Agent pid 59566
ssh-add ~/.ssh/id_rsa

3. Add the ssh key to the GitHub

Use your favorite text editor to open id_rsa.pubthe file, the information inside is the SSH key, copy this information to the GitHub Add SSH keypage to

Different operating systems have some commands directly from SSH key files are copied to the clipboard, as follows:

mac

pbcopy < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

windows

clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

linux

sudo apt-get install xclip
# Downloads and installs xclip. If you don't have `apt-get`, you might need to use another installer (like `yum`)

xclip -sel clip < ~/.ssh/id_rsa.pub
# Copies the contents of the id_rsa.pub file to your clipboard

This article first contained in Gevin's blog



Author: Gevin
link: https: //www.jianshu.com/p/31cbbbc5f9fa
Source: Jane book
Jane book copyright reserved by the authors, are reproduced in any form, please contact the author to obtain authorization and indicate the source.

 

Guess you like

Origin www.cnblogs.com/Arborday/p/11263517.html
Recommended