git是分布式代碼管理工具,遠程代碼管理是基於ssh的,代碼上傳大搜gitlab或者github代碼倉儲時,需要進行ssh配置。
把本地代碼上傳到服務器時需要加密處理,git中公鑰(id_rsa.pub)是用來加密的數字,用私鑰(id_rsa)來還原,gitlab/github發回來的使用公鑰加密過的數據,用本地的私鑰來還原。
如果公鑰或者私鑰丟了一個,就不能用了,重新生成一次把之前的覆蓋掉,然后再gitlab/github中再設置一次即可。
電腦終端運行:
1. 查詢ssh key是否存在
ls -al !/.ssh
2.復制id_rsa.pub,將復制的key粘貼到gitlab/github ssh設置中
pbcopy < ~/.ssh/id_rsa.pub
3.生成ssh key
# -t 為指定加密方式為RSA, -C 為指定郵箱。命令完成后目錄下會生成id_rsa(私鑰)和id_rsa.pub(公鑰)
ssh-keygen -t rsa -C "your_email@example.com"
默認會在相應路徑下(/your_home_path)生成id_rsa和id_rsa.pub兩個文件,此時終端會顯示:
Generating public/private rsa key pair.
Enter file in which to save the key (/your_home_path/.ssh/id_rsa):
可能會讓輸入開機密碼,可能不會直接回車即可。
4.打印公鑰:
cat id_rsa.pub
ssh key 配置到github/gitlab之后,根據此倉儲的配置提示,進行本機的配置:全局配置、上傳本地代碼庫、新建項目等等。
如:
git config --global user.name "xxxx" git config --global user.email "xxxx@163.com" git init git remote add origin xxxx(git通道) git add . git commit -m "11.11 11:11 update" git push -u origin master