How to Install SFTPGo on NixOS Latest

SFTPGo is an open-source FTP server that supports SFTP, FTP, and SCP protocols. In this tutorial, we will guide you through the steps to install SFTPGo on the latest version of NixOS.

Prerequisites

To complete this tutorial, you will need the following:

Step 1: Add the NixOS Unstable Channel

The latest version of SFTPGo is available in the NixOS Unstable channel. Therefore, you will need to add this channel to your NixOS system. To add the Unstable channel, follow these steps:

  1. Open a terminal and run the following command to become root:

    sudo su
    
  2. Next, open the NixOS configuration file with a text editor:

    nano /etc/nixos/configuration.nix
    
  3. In the file, add the following line:

    nixpkgs.config.allowUnfree = true;
    
  4. Save and close the file.

  5. Now, update the package list by running the following command:

    nix-channel --add https://nixos.org/channels/nixos-unstable nixos-unstable
    
  6. Finally, update the system:

    nix-channel --update nixos-unstable
    sudo nixos-rebuild switch
    

Step 2: Install SFTPGo

With the Unstable channel added to your system, you can now proceed to install SFTPGo. To install SFTPGo, follow these steps:

  1. Open a terminal window and become root:

    sudo su
    
  2. Install the SFTPGo package by running the command below:

    nix-env -iA nixos-unstable sftpgo
    
  3. Restart the NixOS service by running the command below:

    sudo systemctl restart nixos.service
    

Step 3: Configure SFTPGo

After installing SFTPGo, you need to configure it. To configure SFTPGo, follow these steps:

  1. Open the SFTPGo configuration file:

    nano /etc/sftpgo/conf.json
    
  2. In the configuration file, replace the existing content with the following code:

    {
        "server": {
            "listen_address": "0.0.0.0",
            "listen_port": 22,
            "log_level": "info",
            "ssh_host_keys_path": "/etc/ssh",
            "ssh_host_rsa_key_path": "/etc/ssh/ssh_host_rsa_key",
            "ssh_host_ecdsa_key_path": "/etc/ssh/ssh_host_ecdsa_key",
            "data_dir": "/var/lib/sftpgo",
            "admins": {
                "sftpgo": {
                    "password": "yourpassword",
                    "home_dir": "/"
                }
            },
            "user_aliases": []
        },
        "tls": {
            "enabled": false
        },
        "sftp": {
            "enabled": true,
            "virtual_folders": []
        },
        "ftp": {
            "enabled": false
        },
        "scp": {
            "enabled": false
        },
        "webdav": {
            "enabled": false
        },
        "hooks": {
            "on_user_login_success": "",
            "on_user_login_failure": "",
            "on_upload_success": "",
            "on_delete_file": "",
            "on_delete_directory": "",
            "on_create_directory": "",
            "on_rename_file": "",
            "on_share_file": "",
            "on_move_file": "",
            "on_download_file": ""
        },
        "ban": {
            "history_size": 10000,
            "history_hours": 72,
            "max_attempts": 5,
            "block_seconds": 900,
            "block_minutes": 5
        },
        "ratelimit": {
            "max_requests_per_second": -1,
            "excluded_ips": []
        }
    }
    
  3. Save and close the file.

  4. Generate the ssh host keys required by SFTPGo:

    ssh-keygen -A
    
  5. Restart SFTPGo:

    sudo systemctl restart sftpgo
    

Congratulations, you have successfully installed and configured SFTPGo on NixOS Latest.

If you want to self-host in an easy, hands free way, need an external IP address, or simply want your data in your own hands, give IPv6.rs a try!