GH-CODESPACE-SSH(1)

πŸ¦‹ GH-CODESPACE-SSH(1) β€” the "ssh into your codespace" glow-up

okay so this is straight out of the GitHub CLI manual, bestie β€” the gh-codespace-ssh page, and it's genuinely iconic. let's get into it πŸ’…


✨ NAME ✨

gh-codespace-ssh β€” literally just SSH into a codespace. that's the whole vibe 🫢


🌸 SYNOPSIS 🌸

gh codespace ssh [<flags>...] [-- <ssh-flags>...] [<command>]

πŸ’– DESCRIPTION πŸ’–

so the ssh command is the one you use to SSH into a codespace. in its simplest form you just run gh cs ssh, pick a codespace interactively, and boom β€” you're connected. main character energy ✨

here's the cute part: the ssh command will automatically create a public/private ssh key pair in the ~/.ssh directory if you don't already have a valid key pair. it's like a lil gift from the CLI πŸŽ€

when it's picking which key pair to use, the preferred order is:

  1. key specified by -i in <ssh-flags>
  2. the automatic key, if it already exists
  3. the first valid key pair in ssh config (according to ssh -G)
  4. the automatic key, newly created

the ssh command also supports deeper integration with OpenSSH using a --config option that generates per-codespace ssh configuration in OpenSSH format. and like… including this configuration in your ~/.ssh/config improves the user experience of tools that integrate with OpenSSH, such as:

  • Bash/Zsh completion of ssh hostnames
  • remote path completion for scp/rsync/sshfs
  • git ssh remotes
  • and so on πŸ‘‘

once that's set up (peep the second example below 🌈), you can ssh to codespaces as if they were ordinary remote hosts β€” using ssh, not gh cs ssh. no cap.

⚠️ heads up bestie: the codespace you're connecting to must have an SSH server pre-installed. if the docker image being used for the codespace doesn't have an SSH server, install it in your Dockerfile or, for codespaces that use Debian-based images, you can add the following to your devcontainer.json:
"features": {
     "ghcr.io/devcontainers/features/sshd:1": {
          "version": "latest"
     }
}

πŸ’… OPTIONS πŸ’…

  • -c, --codespace <string> β€” name of the codespace 🏷️
  • --config β€” write OpenSSH configuration to stdout πŸ“
  • -d, --debug β€” log debug data to a file πŸ›
  • --debug-file <string> β€” path of the file log to πŸ“
  • --profile <string> β€” name of the SSH profile to use 🧚
  • -R, --repo <string> β€” filter codespace selection by repository name (user/repo) πŸ”
  • --repo-owner <string> β€” filter codespace selection by repository owner (username or org) πŸ‘€
  • --server-port <int> (default 0) β€” SSH server port number (0 => pick unused) πŸ”Œ

πŸ”₯ EXIT CODES πŸ”₯

  • 0: successful execution β€” slay πŸ’–
  • 1: error 😭
  • 2: command canceled πŸ™ˆ
  • 4: authentication required πŸ”
πŸ“Œ NOTE: specific commands may have additional exit codes. refer to the command's help for more information. iykyk.

⭐ EXAMPLE ⭐

$ gh codespace ssh
$ gh codespace ssh --config > ~/.ssh/codespaces
$ printf 'Match all\nInclude ~/.ssh/codespaces\n' >> ~/.ssh/config

🌈 SEE ALSO 🌈


and that's the tea πŸ“ β€” this page is from GitHub CLI v2.102.0, dated Oct 2026, so you know it's fresh. periodt. πŸ’œ

πŸ“¦ where this page comes from