Ubuntu 22.04 system git/repo/github/codeup cannot download code by ssh

On the newly installed Ubuntu 22.04 system, git cannot be used to download code by default, as well as various commands and services based on git, such as repo, codeup, github, etc. Execute the command, the error message:

Permission denied (publickey).
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

or

kex_exchange_identification: Connection closed by remote host
Connection closed by 123.123.123.123 port 22
fatal: Could not read from remote repository.
Please make sure you have the correct access rights
and the repository exists.

First, make sure that there is no problem with the sshkey settings on the local and server sides.

After investigation, openssh (version 8.x) replaced the default encryption algorithm rsa with SHA-1 due to security reasons. You can modify the default encryption algorithm through the configuration file and continue to use the rsa algorithm.

Check the version of openssh-server installed on this machine, it is version 8.9.

$ apt search openssh-server
Sorting... Done
Full Text Search... Done
openssh-server/jammy-updates,now 1:8.9p1-3ubuntu0.1 amd64 [installed]

To modify the default encryption algorithm, the following options can be added to the configuration file:

PubkeyAcceptedKeyTypes +ssh-rsa

Modify the local configuration file (~/.ssh/config):

$ cat .ssh/config 
Host your.git.domain
HostName your.git.domain
# PreferredAuthentications publickey
PubkeyAcceptedKeyTypes +ssh-rsa
IdentityFile ~/.ssh/id_rsa

Test after modification:
The git server can be accessed normally.

$ ssh -p <git_port> [email protected]
  ****    Welcome to Gerrit Code Review    ****
  Hi git_user_name, you have successfully connected over SSH.
Connection to gerrit.qisi.ltd closed.

Guess you like

Origin blog.csdn.net/yinminsumeng/article/details/130481253