You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows到Linux Vagrant虚拟机SSH代理转发失败求助

Windows 10 SSH密钥复用至Vagrant Ubuntu虚拟机的问题排查

你已完成的操作:

  • 在Github添加Windows私钥对应的公钥
  • Windows端已成功连接Github,SSH Agent运行且开启代理转发
  • Ubuntu虚拟机已将Windows公钥加入authorized_keys

但在Ubuntu内执行ssh -T git@github.com -v时,出现Permission denied (publickey),日志提示communication with agent failed,以下是遗漏的关键配置:

  • Vagrant必须显式开启SSH代理转发
    Vagrant默认未开启代理转发,需在Vagrantfile中添加配置:

    Vagrant.configure("2") do |config|
      config.ssh.forward_agent = true
    end
    

    修改后执行vagrant reload重启虚拟机,确保配置生效。

  • Ubuntu端需确保ssh-agent运行
    登录Ubuntu后先检查ssh-agent状态:

    ps aux | grep ssh-agent
    

    若未运行,手动启动:

    eval "$(ssh-agent -s)"
    

    可将这条命令写入~/.bashrc或~/.profile,实现登录自动启动。

  • Windows端登录虚拟机需确保代理转发生效
    若使用Git Bash登录虚拟机,需显式带代理转发参数:

    ssh -A vagrant@<虚拟机IP>
    

    也可在Windows的SSH配置文件(C:\Users\<你的用户名>\.ssh\config)中添加:

    Host <虚拟机主机名或IP>
      ForwardAgent yes
    
  • 验证Ubuntu端是否获取到Windows的SSH密钥
    在Ubuntu内执行:

    ssh-add -l
    

    若能列出Windows上的Github密钥,说明代理转发生效;若提示The agent has no identities.,需回到前几步排查配置。

  • 检查Ubuntu的SSH全局配置
    打开/etc/ssh/ssh_config,确保以下配置未被注释:

    ForwardAgent yes
    

内容的提问来源于stack exchange,提问作者Alex Korobchevsky

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.08.24 11:18:14