GH-CODESPACE-SSH(1) GitHub CLI manual GH-CODESPACE-SSH(1)

# [NAME](#NAME)

gh-codespace-ssh - SSH into a codespace

# [SYNOPSIS](#SYNOPSIS)

**gh codespace ssh \[&lt;flags&gt;...] \[-- &lt;ssh-flags&gt;...] \[&lt;command&gt;]**

# [DESCRIPTION](#DESCRIPTION)

The **ssh** command is used to SSH into a codespace. In its simplest form, you can run **gh cs ssh**, select a codespace interactively, and connect.

The **ssh** command will automatically create a public/private ssh key pair in the **~/.ssh** directory if you do not have an existing valid key pair. When selecting the key pair to use, the preferred order is:

1\.

Key specified by **-i** in **&lt;ssh-flags&gt;**

2\.

Automatic key, if it already exists

3\.

First valid key pair in ssh config (according to **ssh -G**)

4\.

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. 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 is set up (see the second example below), you can ssh to codespaces as if they were ordinary remote hosts (using **ssh**, not **gh cs ssh**).

Note that the codespace you are connecting to must have an SSH server pre-installed. If the docker image being used for the codespace does not 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](#OPTIONS)

[**-c**, **--codespace** **&lt;string&gt;**](#c)

Name of the codespace

[**--config**](#config)

Write OpenSSH configuration to stdout

[**-d**, **--debug**](#d)

Log debug data to a file

[**--debug-file** **&lt;string&gt;**](#debug_file)

Path of the file log to

[**--profile** **&lt;string&gt;**](#profile)

Name of the SSH profile to use

[**-R**, **--repo** **&lt;string&gt;**](#R)

Filter codespace selection by repository name (user/repo)

[**--repo-owner** **&lt;string&gt;**](#repo_owner)

Filter codespace selection by repository owner (username or org)

[**--server-port** **&lt;int&gt; (default 0)**](#server_port)

SSH server port number (0 =&gt; pick unused)

# [EXIT CODES](#EXIT_CODES)

0: Successful execution

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.

# [EXAMPLE](#EXAMPLE)

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

# [SEE ALSO](#SEE_ALSO)

[**gh-codespace(1)**](/man/os/gh/gh-codespace.1)

Oct 2026

---

Document: gh-codespace-ssh(1) from gh 2.103.2-r0 (Chainguard OS)
Source: https://github.com/cli/cli
