Mac gitlab配置SSH链接的一个问题

问题:
[email protected]'s password:

No more authentication methods to try.
Permission denied (publickey,password).

起因

项目超过100M,通过之前http提交代码失败,设置 http.postBuffer依然不行,转而使用SSH。SSH还有一个好处就是免密提交,不需要重复验证用户名密码,确实方便。

环境

服务器:公司搭建的内部服务器
设备:mac

过程

参照文档进行操作

1、创建公钥和私钥:
ssh-keygen -t rsa -C "[email protected]" -b 4096

2、重新指定名称和存放地址:(直接回车,默认存放地址/名称:/Users/xx/.ssh/id_rsa)

Enter file in which to save the key (/Users/fei/.ssh/id_rsa): /Users/fei/.ssh/id_yundou_rsa

直接回车,不设置密码。

3、创建成功。

Your public key has been saved in /Users/fei/.ssh/id_yundou_rsa.pub.
The key fingerprint is:
SHA256:E5WdNCjEduotJLFcAJd/+pnnRGC8kR5HHCM0Qb0IY58 [email protected]
The key's randomart image is:
+---[RSA 4096]----+
|    ..o=.oBO*o   |
|     .o Oo+==o   |
|     . B.BBo..   |
|      + ++E*.    |
|       +S+o .    |
|        +...     |
|         o o.    |
|          +..    |
|           o.    |
+----[SHA256]-----+

依照这个流程创建几次没有遇到问题~~

4、复制公钥到服务器添加:
pbcopy < ~/.ssh/id_yundou_rsa.pub
image.png

保存之后既可以。

5、验证链接
ssh -T [email protected](@后是gitlab域名)

返回:Welcome to GitLab, xxxx!表示已经配置成功。否则~~ 重新验证流程是否有误。

问题

最后验证链接的时候报错,没错,就是个倒霉孩子。竟然要密码,关键是不知道要的是什么密码,账号密码,直接回车,电脑密码都试过了,结果都不行。

git@gitlab.yundoukuaiji.com's password:
Permission denied, please try again.
git@gitlab.yundoukuaiji.com's password:
Permission denied, please try again.
git@gitlab.yundoukuaiji.com's password:
Permission denied (publickey,password).

然后告诉我没有权限~~~,不理解,打印链接调试信息
ssh -Tv [email protected]

feideMacBook-Pro:.ssh fei$ ssh -vT [email protected]
OpenSSH_7.4p1, LibreSSL 2.5.0
debug1: Reading configuration data /Users/fei/.ssh/config
debug1: /Users/fei/.ssh/config line 2: Applying options for gitlab.yundoukuaiji.com
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to gitlab.yundoukuaiji.com [192.168.1.10] port 22.
debug1: Connection established.
debug1: identity file /Users/fei/.ssh/id_yundou_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /Users/fei/.ssh/id_yundou_rsa-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.2p2 Ubuntu-4ubuntu2.1
debug1: match: OpenSSH_7.2p2 Ubuntu-4ubuntu2.1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to gitlab.yundoukuaiji.com:22 as 'git'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: [email protected]
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: [email protected] MAC: <implicit> compression: none
debug1: kex: client->server cipher: [email protected] MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:sj/BvZlBEyDB8qtIQa/XG9jhms49dnflUXDZI+SkbAY
debug1: Host 'gitlab.yundoukuaiji.com' is known and matches the ECDSA host key.
debug1: Found key in /Users/fei/.ssh/known_hosts:3
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /Users/fei/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password
debug1: Offering RSA public key: /Users/fei/.ssh/id_yundou_rsa
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: password
[email protected]'s password:

依然跟我要密码~ 然后在网上搜,看到有相同问题的,照着改依然不行。之所以会重复几次过程,就是重新走上面的流程。

网上试了几个方法:
1、本地ssh-add
ssh-add ~/.ssh/youraccount_rsa
没有解决~

2、重新添加origin
git remote add origin [email protected]:username/project.git
应该是还没有到这一步,所以看不出来有什么效果,本地还没有连接到远程代码仓库。

3、配置config

Host gitlab.xxx.com
HostName gitlab.xxx.com
User git
IdentityFile ~/.ssh/id_yundou_rsa

还是没有效果,有些坑。

解决

配置config,多加一个参数:Port

Host gitlab.xxx.com
HostName gitlab.xxx.com
Port 10122
User git
IdentityFile ~/.ssh/id_yundou_rsa

服务端配置的端口是10122,之前却一直使用默认的端口22。

因为是公司内网搭建的代码服务,跟GitHub、gitOSChina有些不同,在oschina上直接配置就可以了。

#git.oschina
Host gitee.com
HostName gitee.com
User git
IdentityFile ~/.ssh/id_rsa

猜你喜欢

转载自blog.csdn.net/fengzhixinfei/article/details/78904866