VS Code SSH连接为何还要求密码?SSH密钥已配置?

摘要:问题描述 SSH config 已经配置好了密钥登录: Host MyServer HostName xx.xx.xx.xx User root Port 22 IdentityFile "C:Usersone
问题描述 SSH config 已经配置好了密钥登录: Host MyServer HostName xx.xx.xx.xx User root Port 22 IdentityFile "C:\Users\onefly\.ssh\id_rsa" ForwardAgent yes 在 Git Bash 中 ssh MyServer 可以正常免密登录,但通过 VS Code Remote SSH 连接时却弹出密码输入框。 排查过程 1. 检查服务器端 ~/.ssh/authorized_keys 中已有对应公钥 ~/.ssh 权限 700,authorized_keys 权限 600 sshd_config 中 PermitRootLogin yes,PubkeyAuthentication 默认启用 服务器端一切正常。 2. 发现关键线索 查看 VS Code 的 Remote SSH 日志(输出面板 → Remote - SSH),发现关键错误: debug1: Offering public key: C:\\Users\\ranxi\\.ssh\\id_rsa RSA SHA256:xxxxx explicit debug1: Server accepts key: C:\\Users\\ranxi\\.ssh\\id_rsa RSA SHA256:xxxxx explicit Bad permissions. Try removing permissions for user: MSI\CodexSandboxUsers (S-1-5-21-xxxx) on file C:/Users/ranxi/.ssh/id_rsa. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: UNPROTECTED PRIVATE KEY FILE! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ Permissions for 'C:\\Users\\ranxi\\.ssh\\id_rsa' are too open. This private key will be ignored. Load key "C:\\Users\\ranxi\\.ssh\\id_rsa": bad permissions debug1: Next authentication method: password 服务器已经接受了密钥,但客户端在签名阶段拒绝使用它,因为私钥文件权限"太开放"。 3. 根本原因 VS Code Remote SSH 使用的是 Windows 自带的 OpenSSH(C:\Windows\System32\OpenSSH\ssh.exe),而不是 Git Bash 自带的 OpenSSH。 两者的区别: Git Bash OpenSSH Windows OpenSSH 路径 C:\Program Files\Git\usr\bin\ssh.exe C:\Windows\System32\OpenSSH\ssh.exe 权限检查 使用 POSIX 模拟,较宽松 使用 Windows ACL,严格检查 Windows OpenSSH 发现私钥文件被 CodexSandboxUsers 用户组拥有继承的读取权限((I)(RX)),认为不安全,直接拒绝使用密钥,fallback 到密码认证。
阅读全文