我面临的问题是,正在运行的 ssh-agent 不记得我的私钥密码。每次我打开 SSH 会话时,它都会不断提示输入密码。我不明白为什么,希望其他人能提供支持。
- 操作系统名称:Microsoft Windows 11 Pro
- 操作系统版本:10.0.22621 N/A 内部版本 22621
- SSH:OpenSSH_for_Windows_8.6p1,LibreSSL 3.4.3
我的 .ssh 目录包含密钥和配置文件。所有文件都有正确的所有者/权限: 注意:C:\Users\lmole.ssh> ls ~/.ssh
Directory: C:\Users\lmole\.ssh
Mode LastWriteTime Length Name
---- ------------- ------ ----
-a---- 28-3-2023 08:36 1631 config
-a---- 24-2-2022 13:01 1743 id_rsa
-a---- 27-3-2023 08:22 3457 known_hosts
-a---- 24-2-2022 13:20 1743 openssh1.key
-a---- 24-2-2022 13:01 1743 openssh2.key
配置文件明确指出要记住密码 〜/.ssh /配置
# Personal key for NAS
Host nas
HostName 192.168.0.150
Port 22
User lucas
PreferredAuthentications publickey
IdentityFile C:\Users\lmole\.ssh\openssh2.key
AddKeysToAgent yes
IdentitiesOnly yes
我的经纪人正在列出钥匙注:G:> ssh-add -l
2048 SHA256:xxxxxjwUDVgN6hWv6G0D00MmMOjww C:\Users\lmole\.ssh\openssh1.key (RSA)
2048 SHA256:xxxxxBSIujD4VAVGICODc1yfMv5cFtdQ/w C:\Users\lmole\.ssh\openssh2.key (RSA)
但它仍然继续要求输入密码: PS C:\Users\lmole.ssh> ssh -v nas
OpenSSH_for_Windows_8.6p1, LibreSSL 3.4.3
debug1: Reading configuration data C:\\Users\\lmole/.ssh/config
debug1: C:\\Users\\lmole/.ssh/config line 1: Applying options for *
debug1: C:\\Users\\lmole/.ssh/config line 35: Applying options for nas
debug1: Authenticator provider $SSH_SK_PROVIDER did not resolve; disabling
debug1: Connecting to 192.168.0.150 [192.168.0.150] port 22.
debug1: Connection established.
debug1: identity file C:\\Users\\lmole\\.ssh\\openssh2.key type -1
debug1: identity file C:\\Users\\lmole\\.ssh\\openssh2.key-cert type -1
debug1: Local version string SSH-2.0-OpenSSH_for_Windows_8.6
debug1: Remote protocol version 2.0, remote software version OpenSSH_8.4p1 Debian-5+deb11u1
debug1: compat_banner: match: OpenSSH_8.4p1 Debian-5+deb11u1 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.0.150:22 as 'lucas'
debug1: load_hostkeys: fopen C:\\Users\\lmole/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ssh-ed25519
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: SSH2_MSG_KEX_ECDH_REPLY received
debug1: Server host key: ssh-ed25519 SHA256:slphIsy0RzP60Ewpt2tpXexiXgiS9YH0blskOgX4/Ns
debug1: load_hostkeys: fopen C:\\Users\\lmole/.ssh/known_hosts2: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts: No such file or directory
debug1: load_hostkeys: fopen __PROGRAMDATA__\\ssh/ssh_known_hosts2: No such file or directory
debug1: Host '192.168.0.150' is known and matches the ED25519 host key.
debug1: Found key in C:\\Users\\lmole/.ssh/known_hosts:1
debug1: rekey out after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey in after 134217728 blocks
debug1: Will attempt key: C:\\Users\\lmole\\.ssh\\openssh2.key explicit
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,[email protected],ssh-rsa,rsa-sha2-256,rsa-sha2-512,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,[email protected],[email protected]>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey
debug1: Next authentication method: publickey
debug1: Trying private key: C:\\Users\\lmole\\.ssh\\openssh2.key
Enter passphrase for key 'C:\Users\lmole\.ssh\openssh2.key':
输入我的密码后:
debug1: identity added to agent: C:\\Users\\lmole\\.ssh\\openssh2.key
debug1: Authentication succeeded (publickey).
Authenticated to 192.168.0.150 ([192.168.0.150]:22).
debug1: channel 0: new [client-session]
debug1: Requesting [email protected]
debug1: Entering interactive session.
debug1: pledge: filesystem full
debug1: ENABLE_VIRTUAL_TERMINAL_INPUT is supported. Reading the VTSequence from console
debug1: ENABLE_VIRTUAL_TERMINAL_PROCESSING is supported. Console supports the ansi parsing
debug1: client_input_global_request: rtype [email protected] want_reply 0
debug1: client_input_hostkeys: searching C:\\Users\\lmole/.ssh/known_hosts for 192.168.0.150 / (none)
debug1: client_input_hostkeys: searching C:\\Users\\lmole/.ssh/known_hosts2 for 192.168.0.150 / (none)
debug1: client_input_hostkeys: hostkeys file C:\\Users\\lmole/.ssh/known_hosts2 does not exist
debug1: client_input_hostkeys: no new or deprecated keys from server
debug1: Remote: /home/lucas/.ssh/authorized_keys:2: key options: agent-forwarding port-forwarding pty user-rc x11-forwarding
Linux nas.xxx.xxx 5.10.0-21-amd64 #1 SMP Debian 5.10.162-1 (2023-01-21) x86_64
这些是我遵循的步骤。密码未存储。我忽略了什么?
答案1
我遇到了同样的问题。我通过将“c:\program files\openssh”中的文件替换为 Windows 10 安装中的文件来修复它。Windows 10 使用 ssh 8.1p1,而 Windows 11 使用 9.2.p1。
答案2
我也遇到了同样的问题。它帮助了我:
您不应使用 Windows 版 Git 附带的 Open SSH 客户端。相反,Windows 10 有自己的 Open SSH 实现,与系统集成在一起。要实现这一点:
- 从 Windows 服务启动
ssh-agent
:
- 输入或然后输入
Services
以启动服务窗口;Start Menu
Win+R
services.msc
- 在列表中找到
OpenSSH Authentication Agent
并双击它;- 在
OpenSSH Authentication Agent Properties
出现的窗口中,Automatic
从Startup type:
下拉列表中选择并单击Start
。Service status:
确保现在显示为Service status: Running
。
通过在 Powershell 中发出以下命令,配置 Git 以使用 OpenSSH 的 Windows 10 实现:
git config --global core.sshCommand C:/Windows/System32/OpenSSH/ssh.exe
通过编辑(完整路径 - )
config
处的文件,配置 SSH 以在启动时自动将密钥添加到代理,并添加以下行: 如果您生成了具有自定义名称或多个 SSH 密钥的 SSH 密钥,还可以添加以下行:$HOME\.ssh\config
C:\Users\%YOUR_USERNAME%\.ssh\config
Host * AddKeysToAgent yes IdentitiesOnly yes
Host github.com HostName github.com User your_user_name IdentityFile ~/.ssh/your_file_name
ssh-agent
通过发出ssh-add
命令并输入密码将您的 SSH 密钥添加到:ssh-add $HOME/.ssh/your_file_name
完成!现在重新启动 Powershell,甚至重新启动 Windows(如果需要)。
如果这有用,你可以在这里给我买杯咖啡。 谢谢你!
来源: https://gist.github.com/danieldogeanu/16c61e9b80345c5837b9e5045a701c99