git - 本地Git无法解析配置中带有 ssh:/的主机名,要求输入密码时也不需要
我在使用新的Gitlab服务器(版本号 12.10.3
)和我的本地git项目。我试图导入它,但是我被远程的URL设置卡住了。
使用下面的URL,git要求我输入密码。
git remote set-url origin [email protected]:mygroup/data/myproject.git
git push --all
[email protected]'s password:
为了避免这种情况,我在另一个主题中加入了一个红色的字样。ssh://
在URL的开头,让这个工作,然后。
git remote set-url origin ssh://[email protected]:mygroup/data/myproject.git
git push --all
ssh: Could not resolve hostname 192.168.1.20:mygroup: Name or service not known
fatal: Could not read from remote repository.
Please make sure you have the correct access rights and the repository exists.
当然,当我做完这个IP地址后 ping
从我的工作站。我还设置了我的 SSH 密钥,将其添加到我的 Gitlab 帐户中,并在 known_hosts
文件夹。
ssh-keyscan 192.168.1.20 >> /c/Users/MyName/.ssh/known_hosts
我错过了什么吗?
编辑
看来我的SSH密钥可能有问题。我试着用 ssh -Tvvv [email protected]
我得到了以下输出。
[...]
debug1: Will attempt key: /c/Users/MyName.ssh/id_rsa RSA SHA256:+W7oskD00BfECMDiA0jTGA4pQbxeNT3v2OFrULoJ7ts
debug1: Will attempt key: /c/Users/MyName/.ssh/id_dsa
debug1: Will attempt key: /c/Users/MyName/.ssh/id_ecdsa
debug1: Will attempt key: /c/Users/MyName/.ssh/id_ed25519
debug1: Will attempt key: /c/Users/MyName/.ssh/id_xmss
debug2: pubkey_prepare: done
debug3: send packet: type 5
debug3: receive packet: type 7
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug3: receive packet: type 6
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug3: send packet: type 50
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug3: start over, passed a different list publickey,gssapi-keyex,gssapi-with-mic,password
debug3: preferred publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Offering public key: /c/Users/MyName/.ssh/id_rsa RSA SHA256:+W7oskD00BfECMDiA0jTGA4pQbxeNT3v2OFrULoJ7ts
debug3: send packet: type 50
debug2: we sent a publickey packet, wait for reply
debug3: receive packet: type 51
debug1: Authentications that can continue: publickey,gssapi-keyex,gssapi-with-mic,password
debug1: Trying private key: /c/Users/MyName/.ssh/id_dsa
debug3: no such identity: /c/Users/MyName/.ssh/id_dsa: No such file or directory
debug1: Trying private key: /c/Users/MyName/.ssh/id_ecdsa
debug3: no such identity: /c/Users/MyName/.ssh/id_ecdsa: No such file or directory
debug1: Trying private key: /c/Users/MyName/.ssh/id_ed25519
debug3: no such identity: /c/Users/MyName/.ssh/id_ed25519: No such file or directory
debug1: Trying private key: /c/Users/MyName/.ssh/id_xmss
debug3: no such identity: /c/Users/MyName/.ssh/id_xmss: No such file or directory
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
[email protected]'s password:
它似乎使用了证书认证程序 我的密钥在 /c/Users/MyName/.ssh/id_rsa
已经被用来验证,但由于一些隐秘的原因,它没有工作。
我又在Gitlab上检查了一下 SSH keys
部分,而密钥与预期的完全一样。
【回答】:
git remote set-url origin [email protected]:mygroup/data/myproject.git
git push --all
[email protected]'s password:
我也设置了我的SSH密钥
嗯,看来你没有。为了验证它,开始用 ssh -Tv [email protected]
.
git remote set-url origin ssh://[email protected]:mygroup/data/myproject.git
正确的SSH URL语法是 ssh://[[email protected]]host.xz[:port]/path/to/repo.git/
. 查看不同的语法 文献.
在你的情况下,URL应该是 ssh://[email protected]/mygroup/data/myproject.git
. 路径没有用 :
,它的开始是 /
. 冒号用于分隔 host
只用类似scp的语法从路径中提取。[[email protected]]host.xz:path/to/repo.git/
.