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

如何解决CS50 GitHub Codespace SSH连接权限拒绝问题

解决GitHub Codespace SSH连接权限拒绝问题

问题场景

已安装GitHub CLI,执行gh cs list能正常列出CS50提供的Codespace:

NAME                                                     DISPLAY NAME            REPOSITORY       BRANCH  STATE      CREATED AT
roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9  literate space sniffle  code50/65642985  main    Available  6d

但执行gh cs ssh roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9时,出现权限拒绝错误:

? Choose codespace: code50/65642985 (main): literate space sniffle
ubuntu@localhost: Permission denied (publickey,password).
shell closed: exit status 255

完整操作流程:

linux@linux ~ $ gh cs list
NAME                                                     DISPLAY NAME            REPOSITORY       BRANCH  STATE      CREATED AT
roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9  literate space sniffle  code50/65642985  main    Available  6d
linux@linux ~ $ gh cs ssh roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9
? Choose codespace: code50/65642985 (main): literate space sniffle

ubuntu@localhost: Permission denied (publickey,password).
shell closed: exit status 255
linux@linux ~ [1] $

解决方法

  • 更新GitHub CLI到最新版本
    旧版本CLI可能存在SSH兼容性问题,执行对应系统的更新命令:

    # Debian/Ubuntu系
    sudo apt update && sudo apt install gh -y
    
    # macOS(Homebrew)
    brew upgrade gh
    
    # Windows(Chocolatey)
    choco upgrade gh
    
  • 重新认证GitHub CLI
    本地认证信息可能过期,重新登录并选择SSH作为认证方式:

    gh auth logout
    gh auth login
    
  • 手动添加SSH密钥到Codespace
    若自动密钥同步失败,手动操作:

    1. 生成新SSH密钥(无可用密钥时执行):
      ssh-keygen -t ed25519 -C "your-github-email@example.com"
      
    2. 复制公钥内容:
      cat ~/.ssh/id_ed25519.pub
      
    3. 打开Codespace网页界面,进入Settings -> SSH keys,粘贴公钥并保存。
  • 用原生SSH命令连接
    绕过gh CLI的SSH封装,直接用原生命令连接:

    gh cs ssh --ssh-command "ssh" roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9
    

    或先获取完整连接命令再执行:

    gh cs ssh --format "{{.SSHCommand}}" roshanpaudel111-literate-space-sniffle-g6x64ww79x9cvgg9
    
  • 重启Codespace
    在GitHub网页端找到目标Codespace,点击**...** -> Rebuild或Restart,待重启完成后再尝试连接。

内容的提问来源于stack exchange,提问作者Rosan Paudel

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.08.05 08:10:25