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:
- key specified by
-iin<ssh-flags> - the automatic key, if it already exists
- the first valid key pair in ssh config (according to
ssh -G) - 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 sshremotes- 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>(default0) β 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 π
gh-codespace(1)β go read that one too bestie π«Ά
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
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- opensuse-leap 16.0: gh 2.102.0-bp160.1.1 Β· MIT
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms