How to Install OpenSSH SFTP Server on nixOS Latest

This tutorial will guide you through the process of installing OpenSSH SFTP server on nixOS Latest.

Prerequisites

Make sure you have root access to the nixOS system and have an existing SSH server installed.

To confirm that you have an SSH server installed, run the following command:

systemctl status sshd.service 

If you see a message that SSH is not installed, you'll need to install it first before moving on to the next step.

Installation

1. Install OpenSSH SFTP server

To install OpenSSH SFTP server on nixOS Latest, run the following command:

nix-env -i openssh

2. Configure OpenSSH SFTP server

Once you've installed OpenSSH SFTP server, you'll need to create a configuration file for it.

  1. Open the SSH configuration file by running the following command:

    sudo nano /etc/ssh/sshd_config
    
  2. Add the following lines to the bottom of the file:

    Subsystem sftp internal-sftp
    Match Group sftp-users
        ChrootDirectory %h
        ForceCommand internal-sftp
        X11Forwarding no
        AllowTcpForwarding no
    
  3. Save and close the file by pressing Ctrl+X, then Y and Enter.

Note: Make sure you have a group called sftp-users created. If you don't, create it using the following command:

sudo groupadd sftp-users

3. Restart OpenSSH server

To apply the changes made to the SSH configuration file, you will need to restart the OpenSSH server.

  1. Run the following command to restart the OpenSSH server:
    sudo systemctl restart sshd.service
    

4. Create SFTP Users

By default, only existing system users can use SFTP. To add users to the sftp-users group, follow these steps:

  1. Create a new user:

    sudo useradd -m -G sftp-users <username>
    

    Note: replace <username> with the actual username of the user you want to create.

  2. Set a password for the user:

    sudo passwd <username>
    

    Note: replace <username> with the actual username of the user you want to create.

  3. Restart the OpenSSH server to apply the changes:

    sudo systemctl restart sshd.service
    

5. Test OpenSSH SFTP Server

To test if OpenSSH SFTP server is working correctly, you can use an SFTP client like Filezilla or WinSCP to connect to your server.

  1. Open your SFTP client and enter the following information:

    • Server: Your server's IP address
    • Protocol: SFTP
    • Port: 22
    • Username and password: The credentials of an existing system user in the sftp-users group you created.
  2. Click the connect button to connect to your server.

  3. Once connected, try transferring files to and from your server.

Conclusion

Congratulations! You've installed and configured OpenSSH SFTP server on nixOS Latest. You can now securely transfer files to and from your server using an SFTP client.

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!

Alternatively, for the best virtual desktop, try Shells!