git clone git@tides.cn:server/code.git Cloning into 'code'...git@tides.cn: Permission denied (publickey).fatal: Could not read from remote repository. Please make sure you have the correct access rightsand the repository exists

栏目: git 发布时间:2024-12-05

今天遇到一个git clone 的问题,提示没有权限,git clone失败。详细报错信息如下:

$ git clone git@tides.cn:server/code.git
Cloning into 'code'...
git@tides.cn: Permission denied (publickey).
fatal: Could not read from remote repository.

Please make sure you have the correct access rights
and the repository exists

登录到 gitlab 后台排查了一下,我的账号是管理员角色,已是最高权限,ssh key配置也没有任何问题。

查了一下我的 git 版本

git -v # git version 2.39.3 (Apple Git-146)

git 自 2.33 版本开始,默认禁用了 ssh-rsa 算法,所以导致 git clone 失败。

解决方法:

# 配置 ~/.ssh/config 文件
Host gitlab.tides.cn
    HostKeyAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa%

搞定!

本文地址:https://www.tides.cn/p_git-permission-denied-publickey-fatal-could-not-read-from-remote-repository