macOS uses git clone error: Permission denied (public key) solution

On the first day of the internship, I used the macOS system to pull the project code from gitlab through git and reported an error: Permission denied (public key). I searched many blogs on the Internet but failed to solve the problem. After a morning of hard work, I found the root of the problem.

First make sure that the installation of git is ok, and configure the global user name and mailbox

When the error was reported at the beginning, an SSH Key was generated according to the guidelines of some blogs and added to gitlab. The operation of this part is as follows: link

After the configuration is complete, try again and still fail, and the error has not changed.

Check to see if the correct key is being used with the following command:

ssh-add l

If there is no content, enter the following code to add the key to the ssh-agent's cache:

ssh-add ~/.ssh/id_rsa

Try to execute the following code to connect to gitlab, but still report an error

ssh -T [email protected]

Find the key problem from the error: no mutual signature algorithm

According to the keyword search, it is known that ssh-rsa is not enabled in the higher version of OpenSSH

Searching yielded the following solutions:

  1. Add PublickeyAcceptedKeyTypes +ssh-rsa configuration
  2. Replace the key generation algorithm and use the ed25519 algorithm to generate
  3. Lower the OpenSSH version

I used the first method, first go to the folder: ~/.ssh

Create a new config file and enter the following

Host *
		HostkeyAlgorithms +ssh-rsa
		PublickeyAcceptedKeyTypes +ssh-rsa

Remember when you are done: wq to save, and it will succeed after trying again

Guess you like

Origin blog.csdn.net/wzc3614/article/details/131545415