Recently I found that my memory is diminishing, so this is a very detailed practice that will only be used once for a long time. After a long time, it is easy to be forgotten. Almost done.
Usually when we want to clone code from a new github repository. We need to configure our local git public key in the github repository to clone the code normally.
Use the SSH protocol to connect to remote servers and services and authenticate to them. SSH keys can be used to connect to GitHub without the need to provide a username or password every time you visit.
check whether there is a public key:
cat: /Users/********/.ssh/id_rsa.pub: No such file or directory is displayed, it means that the public key has not been created, and you need to create the public key yourself.
2.1 You can enter:
ssh-keygen -t rsa -C "email@example.com"
Or do not specify the mailbox:
Then press Enter all the way and use the default value, because this Key is only used for simple services, so there is no need to set a password.
xx@MacBook-Air ~ % ssh-keygen Generating public/private rsa key pair. Enter file in which to save the key (/Users/xinna/.ssh/id_rsa): /Users/xinna/.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/xinna/.ssh/id_rsa. Your public key has been saved in /Users/xinna/.ssh/id_rsa.pub. The key fingerprint is: SHA256:UmEi7XKNfPMu1ZkNPtJsGGkCyTrfOjTrF+IQAn7sqwE xinna@sionas-MacBook-Air.local The key's randomart image is: +---[RSA 2048]----+ | .o..o | |. .=o . | |... + +. . | | ..o= =.= + . | |E o. *.oS= B = | |. .. =.o = X . | | . .+ = + o . | | .. = o . | | .. ..o . | +----[SHA256]-----+ ————————————————
It first asks you to confirm the location where the public key is saved (.ssh/id_rsa), there is no need to enter it here, just press Enter.
Then it will let you repeat a password twice. If you don't want to enter the password when using the public key, you can leave it blank and press Enter.
If the server needs a public key, you can directly configure
id_rsa.pub in the .ssh directory,
id_rsa is the private key and must be kept secret
cat ~/.ssh/id_rsa.pub to view the public key
xinna@sionas-MacBook-Air ~ % cat ~/.ssh/id_rsa.pub ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAABAQDkL0lFa+JqVPDiFeE2BvaMwWH496wkc7e+IVOZoJ+UzooK7B6/IBZ7HcBoHs8ckF3DdFpdJonwGkNFlCnpVDs+wxamdUgPqARJq7nEe5DeG5UQ4LCyZSwRA1OUOl/3gpAK+oYm/v11EgdGoajYJDUCTTp5fsSxaCl4s/Ym8uqUWR+Ba4Aoz117ka4i6yX1EiFfkv2ztbES+Lq9wNs57vK/ktoQmBLslGq2HqTt//WrJJkK2C0HlVSV9lkLZgH1qd5K7dxP1rY7IOrdwvhtwVUGE5V3fmBWGqnlZWJ2tkYczlnPWb0uX0FqP1qod8GZGBoJfgVhGShQBFMXdgqY+V9h xinna@sionas-MacBook-Air.local
For public code, you can clone without user-related information, but for private projects, you must have user-related information to clone or pull. It is impossible to write the user name and password in some scripts, so there is access_token .
1. On the Github personal Settings page, find Developer Settings at the bottom:
2. Click Personal access tokens in Developer Settings:
3. Enter the description of the Token, and then check the permissions of the Token, generally check all of them, and click Generate:
repooption, otherwise the git clone will fail.
4. The Token code is generated by the system, copy and save it locally, because it will not be seen when you open it again.
access_token clone code
git clone https://<access_token>@github.com/xx.git # for example: git clone https://firstname.lastname@example.org/username/projectName.git