SSH
At a glance
| Topic | Detail |
|---|---|
| What it adds | Tools to run one non-interactive command on a remote machine over SSH, and to send a file to it or read a file from it. A person confirms each call by default. |
| Needs | A connection with a host, a user and a key or a password. |
Run commands on a remote machine from your chats and saved agents over SSH. By default a person confirms each command: the card shows the host, the user and the exact text before anything runs.
A chat can answer questions such as:
- “How full is the disk on the build server?”
- “Show the last 50 lines of the service log.”
- “Restart the worker.” (a change: it waits for your confirmation)
The add-on runs one non-interactive command per call. It has no terminal, no input and no environment variables chosen by the model. It has no interactive shell, no port forwarding, no agent forwarding and no jump hosts. Files move only through upload and download, one regular file at a time.
Set it up
- Install the SSH add-on from Find add-ons and open its page.
- On the machine, make a user just for LocalAI, with only the rights the task needs. A command can change or delete anything that user may touch.
- Make a key pair for that user and add the public key to its
authorized_keys, or choose a password. A key with a passphrase is not supported. - On the add-on page, choose New SSH connection. Type the host (with the port if it is not 22), the user name and the key or the password.
- Press Save. When no host key is trusted yet, the page reads the key the machine presents and asks whether to trust this host, with its fingerprint. Compare it with the one on the machine (
ssh-keygen -lf /etc/ssh/ssh_host_ed25519_key.pub), then choose Trust and save. You can also press Check host key first to look at the fingerprint, and tick that you trust it. If the host cannot be reached, the page says so and offers Retry; nothing is saved until you trust the key. - Press Test: the row shows the user and the system name if the login works.
One connection is one host. For a second machine, add a second connection. A chat uses the connections you enable for it in the Tools menu (see The connections of an add-on). With two or more enabled, the model names the connection in each call.
The secret
The connection keeps one sealed secret. It is either a private key in PEM or OpenSSH format, or user:password. For a password the host splits it at the first colon, so the user name has no colon and the password may have colons.
For a key, the user name is the one in the address of the connection. The page asks for the secret again when you change the user or the host, because the saved one belongs to the old ones.
The secret is never in a result, an error, a log or a preview. The add-on also removes it from command output, in whole and in pieces. It refuses a command that holds the secret, so a model cannot ask the machine to echo it or write it to a file.
How the address is kept
The connection lists one allowed address: user@host:port#sha256=<host key fingerprint>. Every tool takes a host argument. LocalAI compares it with the address on the connection before the add-on is called and refuses any other, so a model cannot send the secret to another machine. The add-on dials only that address.
The host key
The add-on trusts a host key on first use, and you approve it when you save the connection. The page reads the key without sending any secret, shows the fingerprint, and the connection stores it as a pin (the SHA-256 of the key, as ssh-keygen -l shows it).
- The key is checked during the key exchange, before any password or key signature is sent. A machine that presents another key never sees the secret.
- If the key changes, every call is refused with a message that names both fingerprints. A changed key can mean the machine was reinstalled, or that someone is intercepting the connection.
- There is no tool or setting that accepts a new key for the model. Only you can trust a new key, by editing the connection on the page and checking the host key again.
- A connection without a pin never connects.
The mode
Each connection has a mode, set on the page by you and never by a model:
| Mode | What happens to run, upload and download |
|---|---|
| Off | The write tools are refused. The connection only checks the login. A connection made through the API with no mode starts here. |
| Asks you first | Each call waits in your approvals. For a command the card shows the host, the user, the exact command, the time limit and the host key. For a file it shows the host, the remote path and the size, never the content. A new connection made on the page starts here. |
| Runs at once | The call runs as soon as the chat makes it, with no card. |
Choose Runs at once only for a host and a user where a wrong command does no harm. In that mode the model is told to say plainly which command ran. The mode is the host’s write mode of the connection (see Confirming a held write in the chat): the tool declares no approval of its own, so the connection decides. In a messaging chat, the usual rules for who may confirm apply.
Tools
| Tool | Kind | What it does |
|---|---|---|
get-info | read | Logs in with the pinned key and returns the host key fingerprint, uname -a and the user name. |
run | write | Runs one command. Arguments: command (at most 4000 characters) and timeoutSeconds (default 30, at most 45). |
upload | write | Sends one file of your files to the remote machine. Arguments: source (a path among your files), path (the remote destination), fileMode (octal, default 0644) and overwrite (default false). |
download | write | Reads one regular file from the remote machine and publishes it as a chat file. Argument: path. |
run returns the exit code, standard output and standard error. Each stream is cut at 32 KiB, and a flag (stdoutTruncated, stderrTruncated) says when it was cut. A command that does not finish within the time limit gets its connection closed; the result says timedOut and holds the output so far, and the command may still run on the machine.
The limit is 45 seconds because LocalAI stops a write call after 60 seconds, and the login uses part of that.
Files
upload and download use the same connection, login and write mode as run, and they send no command that a model wrote. Each runs one fixed script on the machine with the paths as quoted arguments. Both refuse a path that is empty, longer than 1024 bytes, holds a control character or a .. segment, ends in / or starts with ~. A relative remote path is relative to the login directory. The credential is never in a path, and a file that holds it is not published.
uploadreads its source from your files through the host (the add-on asks for theworkspace.exportoperation, which it declares as optional). The source can also be a file that a tool published to the same chat, such as the result ofdownload, so a file can be copied from one machine to another. A file of another chat is refused. The bytes are written to a temporary file in the destination directory, checked for size and, when the machine hassha256sum, for the SHA-256, given the mode, and moved into place. A failed or cut transfer leaves no partial file. Withoutoverwrite, an existing path is refused. The result has the size, the SHA-256 and what was verified. The card shows the host, the remote path, the size and the SHA-256, not the content. The preview reads the file from your files to measure it, and the call is refused if the file changed after you saw the card.downloadpublishes the file as a chat file with its bytes unchanged, under a name made from the remote file name. The result has the name, the size and the SHA-256. Directories, devices, sockets, pipes and files over 16 MiB are refused with a clear message; a file is never cut. A remote file can hold secrets, so the call follows the write mode. In Asks you first the preview asks the machine for the size, with one read-only command that reads no content.
The size limit is 16 MiB in both directions, and both stop after 40 seconds of transfer.
The page also uses a third tool, scan-host-key, to read the host key for you. No model calls it.
Limits and safety
- One command at a time per connection. A second call is refused while one runs.
- No double runs. The add-on records a command before it sends it. If the same call repeats, LocalAI returns the recorded answer and doesn’t run it again. If the connection drops after the command started, the result is “unknown” and the add-on doesn’t send it again.
- Output is data. Results are marked untrusted, and the skill tells the model never to follow instructions in them.
- Errors are specific. Each of these gives its own message: the host can’t be reached, the login was refused, the host key changed, no host key is pinned, and the host wouldn’t run a command.
- The add-on reaches any address a connection lists, including addresses on your own network and on the LocalAI machine itself. The secret of the connection is the only limit on what a command can do there.