git SSH 拉取代碼
1. 生成 SSH Key
ssh-keygen -t rsa -C "youremail@example.com" -f "file_name"
# -t 指定密鑰類型,默認SSH-2
# -C 指定郵件地址
# -f 指定產(chǎn)出文件路徑地址,默認 ~/.ssh/(id_rsa|id_rsa.pub) --> 公鑰、私鑰文件
2. 添加公鑰(gitee/github)
3. 配置私鑰 -(配置多個平臺 git 私鑰)
# 配置文件 ~/.ssh/config
# github.com
Host github.com-1 (別名)
HostName github.com (git 平臺地址) - 注意:如果HostName 是ip地址,不能攜帶端口號
IdentityFile C:\\Users\\Administrator\\.ssh\\id_github_ras (私鑰文件地址)
StrictHostKeyChecking no (不去應(yīng)答交互)
# git
Host zhangsan
HostName 192.168.0.1
IdentityFile C:\\Users\\Administrator\\.ssh\\id_gitee_ras
StrictHostKeyChecking no
# gitee
Host gitee.com
HostName gitee.com
IdentityFile C:\\Users\\Administrator\\.ssh\\id_gitee_ras
StrictHostKeyChecking no
Host gitee.com-1
HostName gitee.com
IdentityFile C:\\Users\\Administrator\\.ssh\\id_gitee_1_ras
StrictHostKeyChecking no
# aliyun
Host codeup.aliyun.com
HostName codeup.aliyun.com
IdentityFile C:\\Users\\Administrator\\.ssh\\id_aliyun_ras
StrictHostKeyChecking no
4. 使用
4.1 ssh 協(xié)議
git clone ssh://{user_name}@{Host}[:{port}]/{倉庫路徑[.git]}
- 例:
git clone ssh://admin@github.com-1/a/b.git
git clone ssh://admin@zhangsan:8888/a/b.git
4.2 git 協(xié)議
git clone git@{Host}[:{port}]/{倉庫路徑[.git]}
文章來源:http://www.zghlxwxcb.cn/news/detail-626833.html
- 例:
git clone git@github.com-1/a/b.git
git clone git@zhangsan:8888/a/b.git文章來源地址http://www.zghlxwxcb.cn/news/detail-626833.html
5. 擴展 StrictHostKeyChecking
StrictHostKeyChecking=no 最不安全的級別,當然也沒有那么多煩人的提示了,相對安全的內(nèi)網(wǎng)測試時建議使用。如果連接server的key在本地不存在,那么就自動添加到文件中(默認是known_hosts),并且給出一個警告。
StrictHostKeyChecking=ask 默認的級別,就是出現(xiàn)剛才的提示了。如果連接和key不匹配,給出提示,并拒絕登錄。
StrictHostKeyChecking=yes 最安全的級別,如果連接與key不匹配,就拒絕連接,不會提示詳細信息。
到了這里,關(guān)于git SSH 拉取代碼的文章就介紹完了。如果您還想了解更多內(nèi)容,請在右上角搜索TOY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!