There are generally two ways to pull code from Github

  • https
  • ssh

HTTPS

Limitations: You need to enter your account password for verification every time you submit your code, which is very troublesome

git clone https://github.com/sialvsic/<repo name>.git
Copy the code

SSH

To avoid repeatedly entering the account password for authentication during each submission, you can configure SSH once to save time

git clone [email protected]:sialvsic/<repo name>.git
Copy the code

How to configure

Ideas:

  • Generate the SSH key
  • Add an SSH key on Github
  • Test the SSH key

Generate the SSH key

Connecting to GitHub with SSH

A. Check whether the SSH key exists. – Checking for existing SSH keys

Run the ls -al ~/. SSH command to check whether the following file names exist: id_rsa.pub id_ecdsa.pub id_ed25519.pubCopy the code

B. If the SSH key exists, you do not need to generate it again. If the SSH key does not exist, you need to generate different commands in different environments, such as Mac, Linux, and Windows

The following uses Linux as an example

Open the command line and type the following command

$ssh-keygen -t ed25519 -c "[email protected]" If the ed25519 algorithm is not supported $ssh-keygen -t rsa -b 4096-c "[email protected]"Copy the code

When you see the prompt, Enter a file in which to save the key, Enter Enter (this will be saved to the default location)

Enter a file in which to save the key (/home/you/.ssh/id_ed25519): [Press enter]

When you see the prompt, Enter passphrase, you can skip this by typing Enter

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

Two SSH files are then generated, one public key and one private key

Id_xxx <= Private key ID_xxx.pub <= public keyCopy the code

Add an SSH key on Github

A. Copy the content of the generated public key

$ pbcopy < ~/.ssh/id_ed25519.pub

# Copies the contents of the id_ed25519.pub file to your clipboard
Copy the code

B. Open Github, choose Profile picture > Setting > SSH and GPG key > New SSH key, and paste the copied value into the key text area. You can fill in the title part as you like

Example Test SSH key configuration

A. Open the CLI

B. the input

$ ssh -T [email protected]

# Attempts to ssh to GitHub
Copy the code

You may see a warning ⚠️

> The authenticity of host 'github.com (IP ADDRESS)' can't be established.
> RSA key fingerprint is SHA256:nThbg6kXUpJWGl7E1IGOCspRomTxdCARLviKw6E5SY8.
> Are you sure you want to continue connecting (yes/no)?
Copy the code

C. Type yes. You will see the following information: username is your Github account name

> Hi username! You've successfully authenticated, but GitHub does not
> provide shell access.
Copy the code

The SSH key configuration is complete