git 多賬戶配置完整實(shí)現(xiàn)過程詳解
環(huán)境 MacOS
檢查是否已有全局賬戶設(shè)置
$ git config --global user.name $ git config --global user.email
如果都沒有返回值,就說明沒有已配置的 git 賬戶,否則請(qǐng)刪除賬戶信息:
$ git config --global --unset user.name "yourname" $ git config --global --unset user.email "youremail"
生成公鑰和秘鑰
$ ssh-keygen -t rsa -C "your_email1" $ ssh-keygen -t rsa -C "your_email2"
注意
生成過程中的 Enter file in which to save the key (/Users/faremax/.ssh/id_rsa):
一步驟請(qǐng)分別起不同的名。
查看生成的文件
ls -l ~/.ssh
-rw------- 1 faremax staff 1679 7 6 11:05 id_rsa_github -rw-r--r-- 1 faremax staff 400 7 6 11:05 id_rsa_github.pub -rw------- 1 faremax staff 1679 7 6 11:06 id_rsa_gitlab -rw-r--r-- 1 faremax staff 405 7 6 11:06 id_rsa_gitlab.pub -rw-r--r-- 1 faremax staff 602 12 6 2017 known_hosts
忽略2017年創(chuàng)建的幾個(gè)文件,可以看到兩個(gè)不同的公鑰和私鑰對(duì)已經(jīng)生成成功了。
分別在 GitHub 和 Gitlab 中錄入對(duì)應(yīng)的公鑰
$ pbcopy < id_rsa_github.pub # 復(fù)制文件內(nèi)容
$ pbcopy < id_rsa_gitlab.pub
添加并識(shí)別私鑰
$ ssh-agent bash $ ssh-add ~/.ssh/id_rsa $ ssh-add ~/.ssh/id_rsa_github $ ssh-add ~/.ssh/id_rsa_gitlab
- 創(chuàng)建配置文件
$ touch ~/.ssh/config
在該文件中添加以下配置
#該文件用于配置私鑰對(duì)應(yīng)的服務(wù)器 #Default gitlab user(email1@hostname.com) Host git@hostname.com HostName https://hostname.com User git IdentityFile ~/.ssh/id_rsa_gitlab ###################################### #Add github user(email1@hostname.com) Host git@github.com HostName https://github.com User git IdentityFile ~/.ssh/id_rsa_github
驗(yàn)證連接Git
以下輸入輸出表示鏈接成功,如果提示權(quán)限問題,說明秘鑰和公鑰匹配除了問題,請(qǐng)檢查并重復(fù)上述步驟(使用 -vT
參數(shù)執(zhí)行下面命令查看錯(cuò)誤信息)
$ ssh -T git@github.com Hi faremax! You've successfully authenticated, but GitHub does not provide shell access. $ ssh -T git@hostname.com Welcome to GIT, faremax!
以上就是git 多賬戶配置完整實(shí)現(xiàn)過程詳解的詳細(xì)內(nèi)容,更多關(guān)于git 多賬戶配置的資料請(qǐng)關(guān)注腳本之家其它相關(guān)文章!
相關(guān)文章
在VSCode中如何配置Python開發(fā)環(huán)境
VScode是一個(gè)相當(dāng)優(yōu)秀的IDE,具備開源、跨平臺(tái)、模塊化、插件豐富、啟動(dòng)時(shí)間快、顏值高、可高度定制等等優(yōu)秀的特質(zhì),所以用VScode來編寫Python,也是相當(dāng)?shù)暮糜玫?。所以,今天我們就來講講,怎么在VScode上配置Python開發(fā)環(huán)境。2020-01-01vscode?ssh遠(yuǎn)程連接服務(wù)器的思考淺析
這篇文章主要為大家介紹了vscode?ssh遠(yuǎn)程連接服務(wù)器的思考淺析,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2023-02-02git版本回退方式(git?reset、git?revert、git?stash)
這篇文章主要介紹了git版本回退方式(git?reset、git?revert、git?stash),具有很好的參考價(jià)值,希望對(duì)大家有所幫助,如有錯(cuò)誤或未考慮完全的地方,望不吝賜教2025-04-04