服务器配置

cd ~/.ssh
#生成key
ssh-keygen -t rsa  #可加参数 -C "lren@xxx.cn"
#复制id_rsa.pub 内容到 gogs-帐户设置-sssh密钥-密钥中

客户端配置

#查看git安装位置
#window
where git
#git中查看
which git

#git安装目录下的 etc/ssh/ssh_config文件添加
Host *
    #IdentityFile ~/.ssh/id_rsa # 秘钥的位置
    IdentityFile F:/gitssh/id_rsa  #windows 
    HostkeyAlgorithms +ssh-rsa # 使 openssh 支持 rsa 算法
    PubkeyAcceptedAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa 

#其它的的host参考
# gitee
Host gitee.com
HostName gitee.com
PreferredAuthentications publickey
IdentityFile /c/Users/MagicBook/.ssh/gitee_id_rsa
# github
Host github.com
HostName github.com
PreferredAuthentications publickey
IdentityFile /c/Users/MagicBook/.ssh/github_id_rsa
# Gitlab
Host gitlab.com
HostName gitlab.com
PreferredAuthentications publickey
IdentityFile /c/Users/MagicBook/.ssh/gitlab_id_rsa
# Gogs
Host gogs.cc
HostName gogs.cc
PreferredAuthentications publickey
IdentityFile /c/Users/MagicBook/.ssh/gitgogs_id_rsa
# GogsTest
Host gogstest.cc
HostName gogstest.cc
PreferredAuthentications publickey
IdentityFile /c/Users/MagicBook/.ssh/gitgogstest_id_rsa

git小乌龟配置ssh

https://blog.csdn.net/zywpurple/article/details/129127267

1. 在开始菜单里,找到并打开 PuTTYgen
菜单:Conversions->Import key
   先择id_rsa私钥
   点击【Generate】按钮生成
   点击【Save private key】 按钮,保存为.ppk文件
2.开始菜单,找到并打开 Pageant (注意打开后在任务栏)
  【Add Key】
  添加上面保存的.ppk文件,关闭即可

测试

#拉代码
git clone ssh://git@x.x.x.x:922/test5.git

#测试连接
ssh -T git@42.192.xxx.xx -p 922

linux单独设置ssh

/etc/ssh/ssh_config

#git安装目录下的文件添加
Host git.xxx.cn
    IdentityFile ~/.ssh/id_rsa_x90
    HostkeyAlgorithms +ssh-rsa
    PubkeyAcceptedAlgorithms +ssh-rsa
    PubkeyAcceptedKeyTypes +ssh-rsa
#其它的的host参考
# gitee
Host gitee.com
    HostName gitee.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/MagicBook/.ssh/gitee_id_rsa
# github
Host github.com
    HostName github.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/MagicBook/.ssh/github_id_rsa
# Gitlab
Host gitlab.com
    HostName gitlab.com
    PreferredAuthentications publickey
    IdentityFile /c/Users/MagicBook/.ssh/gitlab_id_rsa
# Gogs
Host gogs.cc
    HostName gogs.cc
    PreferredAuthentications publickey
    IdentityFile /c/Users/MagicBook/.ssh/gitgogs_id_rsa
# GogsTest
Host gogstest.cc
    HostName gogstest.cc
    PreferredAuthentications publickey
    IdentityFile /c/Users/MagicBook/.ssh/gitgogstest_id_rsa