Git 添加SSH验证

2024-10-09 17:52:57  阅读 58 次 评论 0 条

用gitblit添加新仓库

    touch README.md
    git init
    git add README.md
    git commit -m "first commit"
    git remote add origin ssh://username@172.16.1.203:29418/xxxxxxx.git
    git push -u origin master

报错

Unable to negotiate with 172.16.1.203 port 29418: no matching host key type found. Their offer: ssh-rsa,ssh-dssfatal: Could not read from remote repository.Please make sure you have the correct access rightsand the repository exists.

解决方法:

  1. 生成ssh密钥

命令行

git config --global user.name "username"

git config --global user.email "mail@gmail.com"


ssh-keygen -t rsa -C "配置的邮箱"

提示输入全留空,直接一路回车

生成的key在   ~/.ssh/id_rsa 和id_rsa.pub

~ 表示当前用户,windows在C:\用户\yourname,linux/Mac 即当前用户home目录


   2. 将 id_rsa.pub公钥添加到gitblit上去,gitlab同理


    3. 上面的报错信息是说你的 SSH 客户端和服务器之间的密钥类型不匹配,并且提示了 Their offer 的类型,由于上面我们创建了rsa密钥,所以在~/.ssh/config 文件中添加以下内容,没有文件自己创建

Host 172.16.1.203
    HostKeyAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa


再运行git fetch命令会提示将主机添加到known_hosts,直接回车即可,git通了

本文地址:http://bloguan.com/?id=621
版权声明:本文为原创文章,版权归 博观网 所有,欢迎分享本文,转载请保留出处!
NEXT:已经是最新一篇了

发表评论


表情

还没有留言,还不快点抢沙发?