SSH `ProxyCommand` lets you proxy an SSH connection to a target to simplify common developer and operator workflows.
For example, you can configure the `.ssh/ssh_config` file to connect to the target ID or the target domain.
## Configure a host using target ID
To use SSH `ProxyCommand`, you must configure a `Host` entry in `.ssh/ssh_config` for `localhost`.
In the following example, `ProxyCommand` configures the SSH client to invoke `boundary connect`.
The command passes the `-exec nc` flag to `boundary connect` to wrap [netcat](http://netcat.sourceforge.net/), and then pass the `boundary.ip` and `boundary.port` environment variables as arguments to `nc`.
This command allows you to proxy your SSH connection through a local netcat tunnel that's managed as a Boundary session:
Using this configuration, if you run `ssh ttcp_1234567890` to connect to a target with the ID `ttcp_1234567890`, SSH invokes `boundary connect`, and tunnels the traffic through the local Boundary proxy in a wrapped netcat session.
Boundary passes the target ID to the `boundary` command as the hostname.
Note that you must authenticate to Boundary before you can use `ssh` to invoke `boundary connect`.
### SSH to target
Once the command is configured, you can run `ssh` as you normally would and all the traffic is proxied over the Boundary proxy to your target machine:
```bash
$ ssh ttcp_1234567890
Password:
Last login: Thu Nov 19 10:32:09 2023
➜ ~
```
On the controller, you can see the session being invoked in the logs:
If you want to use the domain name to SSH to targets, you can set the `Host` value to the target domain instead of the target ID.
This method requires an extra step.
You must authorize the session to the target and store it in your environment, since you do not pass the target ID as part of the SSH command.
Authorizing the session allows Boundary to pull the target information from the token you create using the `authorize session` command.
### Authorize the session
The following example authorizes a session to a target `ttcp_1234567890` and stores the token in the `BOUNDARY_CONNECT_AUTHZ_TOKEN` environment variable.
To use SSH `ProxyCommand`, you must configure a `Host` entry in `.ssh/ssh_config` for `localhost`.
In the following example, `ProxyCommand` configures the SSH client to invoke `boundary connect`.
The command passes the `-exec nc` flag to `boundary connect` to wrap [netcat](http://netcat.sourceforge.net/), and then pass the `boundary.ip` and `boundary.port` environment variables as arguments to `nc`.
This command allows you to proxy your SSH connection through a local netcat tunnel that's managed as a Boundary session:
<CodeBlockConfig filename="./ssh/ssh_config">
```bash
Host localhost
# requires BOUNDARY_CONNECT_AUTHZ_TOKEN to be set from authorize-session command
ProxyCommand sh -c "boundary connect -exec nc -- {{boundary.ip}} {{boundary.port}}"
```
</CodeBlockConfig>
Using this configuration, if you run `ssh user@localhost` to connect to the target you created the authorization session for, SSH invokes `boundary connect`, and tunnels the traffic through the local Boundary proxy in a wrapped netcat session.
Boundary passes the target domain to the `boundary` command as the hostname.
Note that you must authenticate to Boundary before you can use `ssh` to invoke `boundary connect`.
### SSH to target
Once the command is configured, you can run `ssh` as you normally would and all the traffic is proxied over the Boundary proxy to your target machine: