登录
注册
写文章
发现
工具
GIT上配置多个不同的账号
_3t3lfz KEKfID
编辑文章
GIT上配置多个不同的账号
asfx站长
2023.09.05 10:13:00
阅读
937
###在使用GIT管理代码时,很可能存在多个账号,例如gitee.com和github.com上都有托管代码。下面以gitee为例,添加账号到git。 ##### 1.在git的终端生成公私钥 ssh-keygen -t rsa -C "gitee_email_address" ###### 提示: Generating public/private rsa key pair. Enter file in which to save the key (/c/Users/ASUS/.ssh/id_rsa): ##### 2.复制括号里的路径,默认文件名为id_rsa,可以改成自己想要的,粘贴修改文件名后,再一路回车生成公私钥到上面这个路径下 例如输入:/c/Users/ASUS/.ssh/id_rsa_gitee 回车后会生成2个文件,id_rsa_gitee(私钥),id_rsa_gitee.pub(公钥) ##### 3.复制生成的.pub文件里的内容,粘贴到gitlab/github/gitee网站安全设置的SSH公钥,点击确定 ##### 4.在.ssh文件夹下新建config名,无后缀的文件,输入内容: ``` # github user Host github HostName github.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_github User xxx@163.com # gitee user Host gitee HostName gitee.com PreferredAuthentications publickey IdentityFile ~/.ssh/id_rsa_gitee User xxx@163.com ``` ##### 5.在git终端添加私钥 ssh-add ~/.ssh/id_rsa_gitee ###### 提示已添加:Identity added: /c/Users/ASUS/.ssh/id_rsa_gitee (xxx@163.com) ##### 6.测试与远程代码托管网站通信是否正常 ssh -T git@gitee.com ###### 若提示以下内容,则输入yes并回车: The authenticity of host 'gitee.com (180.76.198.77)' can't be established. ED25519 key fingerprint is SHA256:+xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx. This key is not known by any other names Are you sure you want to continue connecting (yes/no/[fingerprint])? ##### 7.正常响应: Hi 小明(@whyai)! You've successfully authenticated, but GITEE.COM does not provide shell access.
我的主页
退出