windows - Windows 下使用 Git 的 SSH 失败

标签 windows git ssh

我在构建服务器脚本中使用 Git For Windows(不是 msys 或 GitHub)。我们有一个自托管的 BitBucket 存储库,并配置了 SSH 访问 key 。我正在尝试通过命令行在构建脚本中进行初始克隆,但由于 SSH 错误而失败/

这是我的环境:

  • Windows Server 2012
  • Windows 版 Git 1.9.4
  • SSH key 存储在 %USERPROFILE%\.ssh
  • .ssh\config 指向我的 git 服务器域的正确 SSH key
  • 我的服务器位于我的 known_hosts 文件中
  • SysInternals ProcMon 显示克隆操作期间正在检查 ssh key
  • 使用 Git for Windows 附带的 Git Bash 窗口可以进行相同的克隆操作。所以这排除了无效 key (我相信)

以下是克隆操作期间来自 SSH 的 Loglevel DEBUG3 日志记录:

 [exec] debug3: send packet: type 30
 [exec] debug1: sending SSH2_MSG_KEX_ECDH_INIT
 [exec] debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
 [exec] debug3: receive packet: type 31
 [exec] debug1: Server host key: ssh-rsa SHA256:K7Y..

 [exec] debug3: put_host_port: [x.x.x.x]:7999
 [exec] debug3: put_host_port: [xxxmyserverxxx.local]:7999
 [exec] debug1: checking without port identifier
 [exec] debug1: read_passphrase: can't open /dev/tty: No such device or address
 [exec] Host key verification failed.
 [exec] fatal: Could not read from remote repository.
 [exec]
 [exec] Please make sure you have the correct access rights
 [exec] and the repository exists.

我无法判断“无法打开/dev/tty”问题是否是真正的问题。我什至不知道/dev/tty 在 Windows 命令窗口中相当于什么。

更令人沮丧的是,这种类型的操作在我使用相同 SSH key 对的另一个存储库上成功了。我看不出配置有什么区别

最佳答案

read_passphrase: 无法打开/dev/tty: 没有这样的设备或地址 是你的交易破坏者。 Git 需要获取您的 ssh key 的密码,但无法获取,因为它无法访问 tty (stdin)。您是从 Git Bash 还是其他终端运行 git 命令?

作为一种解决方法,您可以创建一个无密码 ssh key 并使用该 key 。要使其正常工作,请在 Git Bash 主目录中设置类似于此示例的内容:

$ ssh-keygen -b 4096 -t rsa -N "" -f "${HOME}/.ssh/id_rsa_passwordless"

$ cat <<EOF >>.ssh/config
Host github.com
  HostName github.com
  IdentityFile ~/.ssh/id_rsa_passwordless
EOF

当然,最好在 Git Bash 下使用带有密码的 SSH key ,但至少你有一个解决方法。

关于windows - Windows 下使用 Git 的 SSH 失败,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/42443859/

相关文章:

linux - 运行 SSH 命令并从 WinSCP 退出而不中断命令

windows - Windows Installer 本身实际上做了什么,为什么我从来没有看到没有第三方工具制作的 msi?

C 文件描述符复制而不共享偏移量或标志

java - 用 Java 创建的线程在 Windows 和 Linux 上的行为是否不同?

windows - 如何使用 bat 文件响应命令行提示 (Windows)

git - 如何通过BIML对SSIS包进行批量更新?

git - 将提交添加到 merge 的分支并开始新的 pull 请求

git - 人们说 "ancestor"关于 git 是什么意思?

git - rsync/git/ssh 问题 macos 11.3.1/Big Sur

Git 从 TeamCity 9.0.3 构建推送