<span aria-hidden="true" id="how-do-i-limit-an-sftp-user-to-one-directory"></span>

# How do I limit an SFTP user to one directory?

Use OpenSSH's `ChrootDirectory` with its internal SFTP server on a server you administer. The restricted account sees its assigned directory as `/`, while a separate subdirectory remains writable for uploads. This does not give the account a shell or forwarding access.

The following Linux example assumes an existing, dedicated account named `transloadit`, a primary group named `transloadit`, and a home directory of `/home/transloadit`. First verify that this account can log in with its SSH key under your existing authentication policy. Do not use an administrator's account. Do not change the restricted account's home directory to `/`.

Keep an administrator session open while changing SSH settings, and ensure you have another way to access the server if the new configuration is rejected.

<span aria-hidden="true" id="prepare-the-directories"></span>

## Prepare the directories

Create the restricted root, an empty copy of the account's home path inside it, and the upload directory. SSH still reads the account's existing authorized keys before entering the restricted filesystem; do not copy private keys into it.

```bash
sudo install -d -o root -g root -m 755 /srv/sftp/transloadit
sudo install -d -o root -g root -m 755 /srv/sftp/transloadit/home/transloadit
sudo install -d -o transloadit -g transloadit -m 750 /srv/sftp/transloadit/uploads

```

Every component of `/srv/sftp/transloadit`, including `/srv` and `/srv/sftp`, must be owned by root and must not be writable by other users or groups. Only the `uploads` subdirectory belongs to the restricted account. Do not make the restricted root writable to fix an upload error.

<span aria-hidden="true" id="restrict-the-account"></span>

## Restrict the account

In `/etc/ssh/sshd_config`, replace the existing `Subsystem sftp` line with the following line. Keep it in the global section, before any `Match` blocks; do not add a second SFTP subsystem declaration.

```plaintext
Subsystem sftp internal-sftp

```

Add this account-specific block at the end of the configuration:

```plaintext
Match User transloadit
    ChrootDirectory /srv/sftp/%u
    ForceCommand internal-sftp -d /uploads
    DisableForwarding yes
    PermitTunnel no
    PermitTTY no

```

`ForceCommand` starts SFTP in `/uploads` instead of accepting shell commands. `DisableForwarding` also blocks SSH forwarding, which a forced SFTP command alone does not prevent. The account's existing authentication requirements still apply. Adapt the account name and home path if yours are different, and review any earlier matching rules or included configuration files.

<span aria-hidden="true" id="validate-before-reloading"></span>

## Validate before reloading

Check the syntax and effective configuration for the restricted account:

```bash
sudo sshd -t
sudo sshd -T -C user=transloadit,host=localhost,addr=127.0.0.1

```

In the second command, use the actual client address and hostname when your configuration contains address- or host-specific rules. Confirm that the effective settings include the intended `chrootdirectory`, `forcecommand`, `disableforwarding yes`, `permittunnel no`, and `permittty no`. `DisableForwarding` overrides individual forwarding options that may still appear enabled in this output. Do not reload a configuration that fails validation. Use your operating system's documented SSH service reload command, then verify both a new administrator connection and a new SFTP connection before closing the original session.

From your client, connect with `sftp transloadit@your-server.example` and check the directory:

```console
sftp> pwd
Remote working directory: /uploads
sftp> cd /
sftp> pwd
Remote working directory: /
sftp> cd ..
sftp> pwd
Remote working directory: /

```

Upload a harmless test file into `/uploads` and download it again. Creating a file directly in `/` must fail. Also verify that a shell command and port forwarding are rejected. The SFTP path `/uploads` refers to `/srv/sftp/transloadit/uploads` on the server, not the server's own `/uploads`.

Use the account with [/sftp/import](/docs/robots/sftp-import.md) or [/sftp/store](/docs/robots/sftp-store.md), following the Robot's authentication and path documentation. A chroot restricts filesystem access; it does not replace account authentication, filesystem permissions, or network policy. See the [OpenSSH configuration manual](https://man.openbsd.org/sshd%5Fconfig) for the full directive semantics and your distribution's documentation for service management.

## See also:

[How can I limit the output duration of my videos?](/docs/faq/customffmpeg.md)

[Can I have my own upload progress bar?](/docs/faq/customize-progress.md)

[How do I process uploads by file type?](/docs/faq/filtering.md)
