Git 配置多个SSH-Key

发布时间 2023-05-09 18:56:28作者: dreamstar
Git 全局配置

查看全局配置

git config --global --list
git config --global user.name

删除全局配置

git config --global --unset user.name

1.生成ssh public key and private key

open git base, 执行以下command,其中是keyname自己填;codeup_id_rsa 也自己填,是key文件名字

ssh-keygen -t rsa -C "keyname" -f ~/.ssh/codeup_id_rsa

编辑

 执行成功之后,可以在 C:\Users\username\.ssh (~/.ssh/)看到文件

 编辑

 2.public key 上传到aliyun codeup

编辑

 3.测试连接

 其中codeup.aliyun.com是代码管理平台网址,~/.ssh/codeup_id_rsa是刚才生成的privatekey

ssh -T git@codeup.aliyun.com -i ~/.ssh/codeup_id_rsa

编辑

4.在配置git

4.1 把私钥codeup_id_rsa,添加到ssh_agent

ssh-agent bash
ssh-add ~/.ssh/codeup_id_rsa
ssh-add -L

编辑

 查看ssh_agent


 

4.2 创建~/.ssh/.gitconfig

# ~/.ssh/config 配置多个git的ssh-key
# 第一个默认的SSH Key
Host codeup.aliyun.com
    HostName codeup.aliyun.com
    IdentityFile ~/.ssh/codeup_id_rsa
    PreferredAuthentications publickey

 4.3 测试连接

ssh -T git@codeup.aliyun.com

编辑

 5.配置结束,~/.ssh/下面有这么几个文件 

编辑

 

6. Clone code from codeup.

编辑

 

如果连接不成功,查看命令

ssh -vT git@gihub.com

参考:

Windows下配置多个git账号的SSH Key - 简书

五、Git 配置 – git config_gitconfig文件在哪里?_bb_632504322的博客-CSDN博客

Linux 命令(212)—— ssh-add 命令_ssh-add ~/.ssh/id_rsa_恋喵大鲤鱼的博客-CSDN博客