> For the complete documentation index, see [llms.txt](https://documentation.hak5.org/lan-turtle-hub/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://documentation.hak5.org/lan-turtle-hub/payload-development/duckyscript-for-lan-turtle/autossh.md).

# AUTOSSH

AutoSSH automatically establishes a SSH connection to a remote server, and restarts the connection automatically if it is interrupted. SSH connections may be used to tunnel traffic from local and remote ports.

The AUTOSSH command set allows for configuration of the AutoSSH remote access service. This configuration allows AUTOSSH to establish and monitor an SSH tunnel that forwards traffic between the LAN Turtle Hub local ports and remote ports.

## AUTOSSH

The `AUTOSSH` command controls the configuration of the AutoSSH tool.&#x20;

One forwarded port is always required:  This port functions as a remote shell from the SSH server into the LAN Turtle Hub.

### Options

The `AUTOSSH` command expects several options:

```
AUTOSSH enable [host] [port] [user] [remoteport] [localport]
```

#### Host

The IP address or domain name of the remote server you want to connect to.

#### Port

The SSH port on the remote server (typically 22).

#### User

The username used to log into the remote server.

#### Remote Port

The port number on the remote server you want to forward.

#### Local Port

The local port on the LAN Turtle Hub to which you want the remote port forwarded.

### Example

`AUTOSSH enable remote.host 22 turtlehub 2022 22`

## AUTOSSH\_ADD\_PORT

The `AUTOSSH_ADD_PORT` command adds a local or remote port to the AutoSSH configuration. SSH port forwarding is a mechanism for tunneling TCP ports between the LAN Turtle Hub and a remote server. Multiple port forwards may exist for any given AutoSSH host.

### Options

The AUTOSSH\_ADD\_PORT command expects several options:

```
AUTOSSH_ADD_PORT local [localport] [host] [remoteport]
AUTOSSH_ADD_PORT remote [localport] [host] [remoteport]
```

The AUTOSSH\_ADD\_PORT command may add port forwarding rules for the remove destination or local destination. Refer to the `AUTOSSH` command options above for local port, host and remote port descriptions.

## AUTOSSH\_CLEAR

The `AUTOSSH_CLEAR` command will clear the entire AutoSSH configuration. No confirmation is necessary, so be careful when executing this command.

## AUTOSSH\_DISABLE

The `AUTOSSH_DISABLE` command will disable the AutoSSH service.

The configuration values remain.

## AUTOSSH\_ENABLE

The `AUTOSSH_ENABLE` command will enable the AutoSSH service.

The AutoSSH service must be configured before it can be enabled; this command toggles an existing configuration.

## SSH\_ADD\_KNOWN\_HOST

The `SSH_ADD_KNOWN_HOST` command adds a server fingerprint for a known SSH host.

To connect to a server over SSH, the fingerprint must be known by the LAN Turtle Hub.  This can be accomplished by using the `SSH_ADD_KNOWN_HOST` command, manually SSHing to the desired host and accepting the fingerprint, or directly adding the fingerprint to the known hosts file.

```
SSH_ADD_KNOWN_HOST [hostname] [keytype] [keydata]
```

The hostname must match the hostname you plan to use to connect to the remote server (for instance, if you plan to connect using the IP address only, you need to add the key using the IP address).

The keytype and keydata can be determined by using SSH on a normal system to extract the fingerprint and key type (by using the `ssh` command or inspecting the SSH `known_hosts` file), or by using the `ssh-keyscan` and `ssh-keygen` commands to fetch the public key and generate the fingerprint:

```bash
ssh-keygen -lf <(ssh-keyscan [hostname] 2>/dev/null)
```

Often a host will specify multiple key types - for maximum compatibility, each key type should be added with a `SSH_ADD_KNOWN_HOST` command.

A SSH host fingerprint only needs to be added once, typically during device setup or the first time a payload is installed.
