一,生成ssh密鑰并配置
分別對(duì)gitlab和github生成對(duì)應(yīng)的密鑰(默認(rèn)情況下本地生成的秘鑰位于C:/Users/用戶名/.ssh/)
1,生成gitlab密鑰并配置
-
電腦開始菜單中找到已安裝的gitbash并打開,輸入命令:
ssh-keygen -t rsa -C "公司郵箱地址"
按回車根吁,再按3次enter鍵,生成對(duì)應(yīng)的gitlab密鑰:id_rsa和id_rsa.pub
jerry@Jerry MINGW64 ~
$ ssh-keygen -t rsa -C "60xxxxx@qq.com" -b 4096
Generating public/private rsa key pair.
Enter file in which to save the key (/c/Users/jerry/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/jerry/.ssh/id_rsa
Your public key has been saved in /c/Users/jerry/.ssh/id_rsa.pub
The key fingerprint is:
SHA256:58T8LFOv9JZrA7Z2ghVVSCKKs+dx1UwuZiG/pq9wEQU 604637883@qq.com
The key's randomart image is:
+---[RSA 4096]----+
| E.+.oo.|
| . . = Bo |
| o . . *.+ |
| o o =.o |
| . S B +. |
| o * B+. |
| o *++o.. |
| o.=+o* |
| .oo=oo |
+----[SHA256]-----+
將gitlab公鑰即id_rsa.pub(Windows下路徑為C:/Users/用戶名/.ssh/)中的內(nèi)容配置到公司的gitlab上。
操作步驟如下圖合呐。用記事本打開id_rsa.pub,復(fù)制有所內(nèi)容笙以,粘貼到4里淌实;5中標(biāo)題可任意輸入。
2猖腕,生成gitlab密鑰并配置
-
在gitbash中輸入命令:
ssh-keygen -t rsa -C "github郵箱地址" -f ~/.ssh/github_rsa
生成對(duì)應(yīng)的github密鑰:github_rsa和github_rsa.pub
jerry@Jerry MINGW64 ~
$ ssh-keygen -t rsa -C "604637883@qq.com" -f ~/.ssh/github_rsa
Generating public/private rsa key pair.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /c/Users/jerry/.ssh/github_rsa
Your public key has been saved in /c/Users/jerry/.ssh/github_rsa.pub
The key fingerprint is:
SHA256:DvG4umzBRa3gCht0hB9YclwE8SCXoDgGx01IuC/zsfE 604637883@qq.com
The key's randomart image is:
+---[RSA 3072]----+
|.BX%Bo . |
|==B== . . |
|=oo..+.. |
|=. .. o+ |
| = o .o S |
|+ = o + |
| + = .. . |
| o.E. |
| .+. |
+----[SHA256]-----+
-
將github公鑰即github_rsa.pub中的內(nèi)容配置到自己的github上拆祈。操作步驟如下:
image.png
打開github_rsa.pub,復(fù)制有所內(nèi)容倘感,填入后點(diǎn)擊“Add SSH key”按鈕放坏。接著可能會(huì)跳轉(zhuǎn)頁面需要輸入你的GitHub密碼,輸入確定即可老玛。
1213182-20200811171229765-156685640.png
3淤年,配置git,訪問不同host時(shí)訪問不同的密鑰
進(jìn)入密鑰生成的位置(C:/Users/用戶名/.ssh/)蜡豹,手動(dòng)創(chuàng)建一個(gè)config文件(注意這個(gè)config文件要無后綴)麸粮。
-
在新建的config文件里面配置如下內(nèi)容:
# 自己的github賬號(hào)配置 Host github.com port 22 User git HostName github.com PreferredAuthentications publickey IdentityFile C:\Users\jerry\.ssh\github_rsa # 公司的gitlab賬號(hào)配置(HostName為公司的gitlab地址) Host gitlab.com port 22 User git HostName gitlab.xxx.com User git PreferredAuthentications publickey IdentityFile C:\Users\jerry\.ssh\id_rsa
字段配置簡(jiǎn)單說明:
Host Host可以看作是一個(gè)你要識(shí)別的模式,對(duì)識(shí)別的模式余素,配置對(duì)應(yīng)的主機(jī)名和ssh文件 Port 自定義的端口豹休。默認(rèn)為22,可不配置 User 自定義的用戶名桨吊,默認(rèn)為git威根,可不配置 HostName 真正連接的服務(wù)器地址, 公司可能為僅數(shù)字IP ,如192.168.41.203 PreferredAuthentications 指定優(yōu)先使用哪種方式驗(yàn)證,支持密碼和秘鑰驗(yàn)證方式 IdentityFile 指定本次連接使用的密鑰文件
設(shè)置HostName時(shí)需要注意视乐,復(fù)制公司gitlab或者自己的github地址時(shí)洛搀,需要把"https://"去掉,只保留github.com部分佑淀。
二留美,驗(yàn)證是否設(shè)置成功
在C:/Users/用戶名/.ssh中,右鍵打開Git Bash Here,分別輸入命令:
# 測(cè)試github
ssh -T git@github.com
# 測(cè)試gitlab(@符后面的為公司gitlab地址)
ssh -T git@192.168.xx.xxx
如下圖所示則說明配置成功
jerry@Jerry MINGW64 ~
$ ssh -T git@github.com
The authenticity of host 'github.com (20.205.xxx.xxx)' can't be established.
RSA key fingerprint is SHA256:nThbg6kXUpJWGl7xxxxxxxxxxxxxxxARLviKw6E5SY8.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added 'github.com' (RSA) to the list of known hosts.
Hi yangjian1218! You've successfully authenticated, but GitHub does not provide shell access.
jerry@Jerry MINGW64 ~
$ ssh -T git@192.168.xx.xxx
The authenticity of host '192.168.xx.xxx (192.168.xx.xxx)' can't be established.
ED25519 key fingerprint is SHA256:Ib8w8v6Cu5xxxxxxxxxxx34zDifjGQo84X5Y.
This key is not known by any other names
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.xx.xxx' (ED25519) to the list of known hosts.
Welcome to GitLab, 楊健!
三谎砾,git倉庫配置
1逢倍,簡(jiǎn)介
在git中,我們使用git config 命令用來配置git的配置文件景图,git配置級(jí)別主要有以下3類:
倉庫級(jí)別 local 【優(yōu)先級(jí)最高】
用戶級(jí)別 global【優(yōu)先級(jí)次之】
系統(tǒng)級(jí)別 system【優(yōu)先級(jí)最低】
-
git 倉庫級(jí)別對(duì)應(yīng)的配置文件是當(dāng)前倉庫下的.git/config 【在當(dāng)前目錄下.git目錄默認(rèn)是隱藏的较雕,所以在文件管理器中我們要打開顯示以藏文件】
1213182-20200811171543448-1343147572.png -
image-20211104104132089.png
git 用戶級(jí)別對(duì)應(yīng)的配置文件是用戶宿主目錄下的~/.gitconfig 【宿主目錄:C:\Users\jerry】
-
git系統(tǒng)級(jí)別對(duì)應(yīng)的配置文件是git安裝目錄下的 /etc/gitconfig
簡(jiǎn)單了解后我們就可以進(jìn)行配置了
2,配置
-
用戶級(jí)別配置
用戶級(jí)別是配置公司gitlba賬號(hào)還是自己github賬號(hào)挚币,可以自由選擇亮蒋。因?yàn)槠匠J褂霉镜拇a頻率較高,所以我選擇將gitlab賬號(hào)配置成用戶級(jí)別妆毕。gitBath下執(zhí)行如下命令:
git config --global user.name '楊健' #公司賬號(hào)名稱
git config --global user.email '604637883@qq.com' #公司賬號(hào)郵箱
-
倉庫級(jí)別配置
local(倉庫級(jí)別)配置成github的賬號(hào)慎玖。選擇一個(gè)文件夾作為github的本地倉庫,在該文件夾里鼠標(biāo)右鍵打開Git Bash Here笛粘,執(zhí)行命令:git init
再執(zhí)行命令:
git config --local user.name 'yangjian1218' #github賬號(hào)名稱
git config --local user.email '604637883@qq.com' #github賬號(hào)郵箱
之后自己的github的代碼都應(yīng)該在這個(gè)倉庫下進(jìn)行pull趁怔、push操作。
3.切換賬號(hào)
如果之前已經(jīng)上傳過代碼到其中一個(gè)賬號(hào),需要上傳到另一個(gè)賬號(hào)中,如之前已經(jīng)上傳到gitLab,現(xiàn)在要切換到github中,先要解除設(shè)置.
$ git remote rm origin
不然會(huì)報(bào)錯(cuò):error: remote origin already exists.
或者直接刪除.git文件夾.
添加賬號(hào)(這一步可省略,)
git config --local user.name 'yangjian1218'
git config --local user.email '604637883@qq.com'
再添加遠(yuǎn)程git倉庫
$ git remote add origin https://github.com/yangjian1218/Face-Updown-classify.git