git密钥添加及验证

概述

由于特殊原因删除了window .ssh/known_hosts,在通过vscode push代码是提示异常,因为第一次需要人工yes确认的主机秘钥,蛋疼的操作

开干

env

  • window11
  • git

x01、生成ssh密钥对

#ssh-keygen --help
    [-t dsa | ecdsa | ecdsa-sk | ed25519 | ed25519-sk | rsa]

ssh-keygen -t rsa    // -t 加密类型

id_rsa   //私钥
id_rsa.pub //公钥
copy到window中,或者直接window11的powershell执行生成秘钥对
C:\Users\xxx\.ssh\

x02、公钥添加到git仓库中

#github
https://github.com/settings/profile

access->SSH and GPG keys -> New SSH key  
id_rsa.pub 内容复制进去

#gitee
https://gitee.com/profile/account_information

安全设置 -> SSH公钥
id_rsa.pub 内容复制进去

添加profile是整个账户都是有效的(账户下创建的仓库)

x03、验证ssh通信

#ssh
    -T  //Disable pseudo-terminal allocation 禁止伪终端的分配

ssh -T git@gitee.com
ssh -T git@github.com
ssh -T git@code.aliyun.com

C:\Users\xxx\.ssh\known_hosts   //主机通信的钥匙

#git ssh clone
git clone git@code.aliyun.com:mvpbang/xxx.git
git clone git@gitee.com:m0p/xxx.git
posted @ 2023-03-17 18:02  mvpbang  阅读(103)  评论(0编辑  收藏  举报