> ## Documentation Index
> Fetch the complete documentation index at: https://docs.prequel.co/llms.txt
> Use this file to discover all available pages before exploring further.

# SFTP

> Connect your SFTP server as a source

By default, SFTP uses keypair authentication for access. We generate the keypair and provide you with the public key to register on a user on your SFTP server. The private key is securely generated and stored in our system and is never shared externally.

## Step 1: locate your public key

Locate the public key provided to you. The public key will look roughly like this:

```shell title="Public key" icon="terminal" theme={null}
ssh-rsa <ssh_public_key_beginning_with_AAAA> some-comment
```

You will register this public key on the SFTP user you create in Step 2. Reach out to your account representative if you have not been provided a public key.

## Step 2: create a user on the SFTP server

Log in to the SFTP server and complete the steps below.

<Steps>
  <Step title="Create the group">
    Create the `sftpreader` group.

    ```shell title="Create the group" icon="terminal" theme={null}
    sudo groupadd sftpreader
    ```
  </Step>

  <Step title="Create the user">
    Create the `sftpreader` user.

    ```shell title="Create the user" icon="terminal" theme={null}
    sudo useradd -m -g sftpreader sftpreader
    ```
  </Step>

  <Step title="Create the .ssh directory">
    Switch to the `sftpreader` user, create the `.ssh` directory, and set its permissions.

    ```shell title="Create the .ssh directory" icon="terminal" theme={null}
    sudo su - sftpreader
    mkdir ~/.ssh
    chmod 700 ~/.ssh
    ```
  </Step>

  <Step title="Create the authorized_keys file">
    Create the `authorized_keys` file and set its permissions.

    ```shell title="Create authorized_keys" icon="terminal" theme={null}
    cd ~/.ssh
    touch authorized_keys
    chmod 600 authorized_keys
    ```
  </Step>

  <Step title="Add the public key">
    Add the public key from Step 1 to the `authorized_keys` file. The key, including the `ssh-rsa` prefix and comment, should be all on one line in the file, without linebreaks.

    ```shell title="Add the public key" icon="terminal" theme={null}
    echo "ssh-rsa <ssh_public_key_beginning_with_AAAA> sftpreader-public-key" >> authorized_keys
    ```
  </Step>

  <Step title="Grant read access to your data">
    Ensure the `sftpreader` user has read access to the directory that contains the files you want to sync.
  </Step>
</Steps>

<Note>
  The SFTP protocol encrypts files in transit. Allow the static IP to connect on your SFTP port (usually `22`) at your firewall or network perimeter. Reach out to your account representative for the static IP address to use.
</Note>

## Step 3: submit your connection details

Provide the following details to complete the source setup:

1. The **name** is a descriptive name of the source.
2. The **host** of your SFTP server.
3. The **port** (most likely `22`).
4. The **username** from Step 2.
