如何在 Windows 上的 git 配置中修复“ssh 权限被拒绝,请重试错误”
Posted
技术标签:
【中文标题】如何在 Windows 上的 git 配置中修复“ssh 权限被拒绝,请重试错误”【英文标题】:How to fix "ssh permission denied please try again error" in git configuration on Windows 【发布时间】:2019-04-02 00:00:36 【问题描述】:我正在尝试在两台本地 Windows 机器上配置 git 服务器和客户端。我在两台机器上都安装了 git 软件。在服务器上启用了 openssh 服务器可选功能并在服务器上创建了一个裸存储库。然后尝试在客户端克隆服务器的裸存储库,它询问我服务器用户的密码,但是即使我输入了正确的密码,它仍然给出以下错误消息。
权限被拒绝(公钥、密码、键盘交互)。
我试图找出错误的原因。在 google 上浏览此错误后,我知道它是 ssh 配置不正确。我发现的一个建议是使用命令检查 ssh 是否在没有 git 参与的情况下正常工作
ssh -Tv ram-pc1@10.208.27.100,它也失败并给出以下错误消息:
$ ssh -Tv ram-pc1@10.208.27.100
OpenSSH_7.7p1, OpenSSL 1.0.2p 14 Aug 2018
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Connecting to 10.208.27.100 [10.208.27.100] port 22.
debug1: Connection established.
debug1: identity file /c/Users/Admin/.ssh/id_rsa type 0
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_ed25519-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_xmss type -1
debug1: key_load_public: No such file or directory
debug1: identity file /c/Users/Admin/.ssh/id_xmss-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_7.7
debug1: Remote protocol version 2.0, remote software version OpenSSH_for_Windows_7.6
debug1: match: OpenSSH_for_Windows_7.6 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 10.208.27.100:22 as 'ram-pc1'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:27NSp0TODhiZ68zbYLvsaqPNMp8tE0ZanMeoeQp+u14
debug1: Host '10.208.27.100' is known and matches the ECDSA host key.
debug1: Found key in /c/Users/Admin/.ssh/known_hosts:1
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=<ssh-ed25519,ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering public key: RSA SHA256:2KyRU6bbWWkN+IBYN6xiuWQuHl0pKL6Cim6K4/6RBek /c/Users/Admin/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /c/Users/Admin/.ssh/id_dsa
debug1: Trying private key: /c/Users/Admin/.ssh/id_ecdsa
debug1: Trying private key: /c/Users/Admin/.ssh/id_ed25519
debug1: Trying private key: /c/Users/Admin/.ssh/id_xmss
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
ram-pc1@10.208.27.100's password:
debug1: Authentications that can continue: publickey,password,keyboard-interactive
Permission denied, please try again.
ram-pc1@10.208.27.100's password:
debug1: Authentications that can continue: publickey,password,keyboard-interactive
Permission denied, please try again.
ram-pc1@10.208.27.100's password:
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: No more authentication methods to try.
ram-pc1@10.208.27.100: Permission denied (publickey,password,keyboard-interactive).
以下是我的 ssh_config 文件设置:
#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::
#HostKey __PROGRAMDATA__/ssh/ssh_host_rsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_dsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ecdsa_key
#HostKey __PROGRAMDATA__/ssh/ssh_host_ed25519_key
# Ciphers and keying
#RekeyLimit default none
# Logging
#SyslogFacility AUTH
#LogLevel INFO
# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10
#PubkeyAuthentication yes
# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile .ssh/authorized_keys
#AuthorizedPrincipalsFile none
# For this to work you will also need host keys in %programData%/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no
#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
#PermitTTY yes
#PrintMotd yes
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#PermitUserEnvironment no
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none
# no default banner path
#Banner none
# override default of no subsystems
Subsystem sftp sftp-server.exe
# Example of overriding settings on a per-user basis
#Match User anoncvs
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
我花了很多时间来解决这个错误。但没有成功。请帮助解决这个问题。提前致谢。
【问题讨论】:
您好,请同时输入您的 sshd_config 文件。检查 PasswordAuthentication 属性,如果它设置为“no”,请将其更改为“yes”并通过“sudo service ssh restart”命令重新启动您的 ssh 服务。 我已经用我的配置文件详细信息更新了我的问题,请检查一次 我的 PasswordAuthentication 已经设置为 yes :( 您也可以尝试以全新的方式进行设置,而不是调试此实例。如果你喜欢我建议你关注:github.com/PowerShell/Win32-OpenSSH/wiki/…,你也可以关注这个来生成 ssh 密钥对:ssh.com/ssh/keygen 有时最好重做而不是修复由于我们错过/跳过某些东西而发生的工具错误。跨度> 可能相关:superuser.com/questions/1362298/… 还有serverfault.com/questions/598058/… 【参考方案1】:在 10.208.27.100 服务器端检查 ~ram-pc1/.ssh/authorized_keys 的内容:它应该包括你的公钥。
所说的公钥应该是一个名为C:\Users\Admin\.ssh\id_rsa.pub
(和私钥的id_rsa)的rsa(暂时没有密码),由ssh-keygen -t rsa -P ""
生成
【讨论】:
以上是关于如何在 Windows 上的 git 配置中修复“ssh 权限被拒绝,请重试错误”的主要内容,如果未能解决你的问题,请参考以下文章
如何在Ubuntu和Windows上为德语Umlaute配置git编码?