SSH連接
Win10 x64, Maven 3.x, Git 2.22
- 打開Git Bash, 生成公私鑰
ssh-keygen -t rsa -C "[Git賬號(hào)], 譬如xxx@xxx.com"
# 密碼默認(rèn)為空
- 將生成的公鑰(默認(rèn)為id_rsa.pub)內(nèi)容, Copy到GitLab SSH Key中
- 添加私鑰到本地ssh, 同時(shí)將公鑰放入已知hosts(known_hosts)
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
ssh-keyscan gitlab.xxx.cn >> ~/.ssh/known_hosts
第一個(gè)問題
使用命令 mvn jgitflow:feature/hotfix/release-start|finish時(shí), 報(bào)‘Auth Fail'異常, 解決方法:
# 如果~/.ssh下沒有config文件, 手動(dòng)創(chuàng)建, 且填充內(nèi)容如下:
Host gitlab.xxx.cn
UserKnownHostsFile ~/.ssh/known_hosts
HashKnownHosts no
IdentityFile ~/.ssh/id_rsa
誕生第二個(gè)問題
使用命令 mvn jgitflow:feature/hotfix/release-start|finish時(shí), 報(bào)‘Invalid privatekey’異常, 解決方法:
# 修改ssh-keygen, 添加 -m PEM (使用PEM格式)
ssh-keygen -t rsa -m PEM -C "[Git賬號(hào)], 譬如xxx@xxx.com"
參考文檔:
https://gitlab.xxx.cn/help/ssh/README#generating-a-new-ssh-key-pair
https://stackoverflow.com/questions/21904017/teamcity-ssh-private-key-login-failed-invalid-privatekey
If you are on Windows, you can use PuTTYgen (from PuTTY package). Load the key and then go to Conversions > Export OpenSSH key. For RSA keys, it will use the classic format.
If you are creating a new key with ssh-keygen, just add -m PEM to generate the new key in the classic format:
ssh-keygen -m pem