SSH连接
Win10 x64, Maven 3.x, Git 2.22
- 打开Git Bash, 生成公私钥
ssh-keygen -t rsa -C "[Git账号], 譬如xxx@xxx.com"
# 密码默认为空
- 将生成的公钥(默认为id_rsa.pub)内容, Copy到GitLab SSH Key中
- 添加私钥到本地ssh, 同时将公钥放入已知hosts(known_hosts)
eval $(ssh-agent -s)
ssh-add ~/.ssh/id_rsa
ssh-keyscan gitlab.xxx.cn >> ~/.ssh/known_hosts
第一个问题
使用命令 mvn jgitflow:feature/hotfix/release-start|finish时, 报‘Auth Fail'异常, 解决方法:
# 如果~/.ssh下没有config文件, 手动创建, 且填充内容如下:
Host gitlab.xxx.cn
UserKnownHostsFile ~/.ssh/known_hosts
HashKnownHosts no
IdentityFile ~/.ssh/id_rsa
诞生第二个问题
使用命令 mvn jgitflow:feature/hotfix/release-start|finish时, 报‘Invalid privatekey’异常, 解决方法:
# 修改ssh-keygen, 添加 -m PEM (使用PEM格式)
ssh-keygen -t rsa -m PEM -C "[Git账号], 譬如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