Github和碼雲都提供SSH協議,即用戶可以用公鑰認證方式連接到碼雲的SSH服務器。這就需要生成並部署SSH Key。下面就是我生成SSH Key的步驟,希望有所幫助:
Git生成SSH key
在初始化文件鼠標右鍵,找到Git Bash Here,進入后輸入下面2條指令:
git config --global user.name "名稱或昵稱"
git config --global user.email "你的郵箱"
作用:告訴Git你是誰,郵箱在生成SSH Key需要。
輸入上面2條指令后,再輸入下面指令:
ssh-keygen -t rsa -C "你的郵箱"
生成結果如下
上面完成后,再輸入指令:
cat ~/.ssh/id_rsa.pub
指令下的一大串就是SSH Key(SSH Key是以ssh-rsa AAAA...開頭),SSH Key生成完成。
SSH Key部署
- 部署到Github
登錄Github,點擊頭像 找到settings
點擊右上角New SSH Key
,添加成功后在終端輸入:
ssh -T git@github.com
若返回有
Hi,你的名稱或昵稱 You've successfully authenticated ...
證明添加成功!
- 部署到碼雲
點擊確定即可,添加成功后在終端輸入:
ssh -T git@gitee.com
若返回有
Hi,你的名稱或昵稱 You've successfully authenticated ...
證明添加成功!
簡易的命令行入門教程:
Git 全局設置:
git config --global user.name "侯佳"
git config --global user.email "airmour@foxmail.com"
創建 git 倉庫:
mkdir fast_repair_brother
cd fast_repair_brother
git init
touch README.md
git add README.md
git commit -m "first commit"
git remote add origin https://gitee.com/airmour/fast_repair_brother.git
git push -u origin master
已有倉庫?
cd existing_git_repo
git remote add origin https://gitee.com/airmour/fast_repair_brother.git
git push -u origin master
git報錯:'fatal:remote origin already exists'怎么處理?
只要兩步:
1、先刪除git remote rm origin
2、再次執行添加就可以了。