Setting up a Linux SFTP Server

To get started, you’ll need to use the following:

Configuring the User

First, SSH into the server and install OpenSSH:

sudo apt install -y ssh openssh-server

Now create the group to have access, alongside a user to be able to access:

Now set up the directories to allow for the following:

Setting up User Access

There are two ways to have the user access – by key or by password. Key is preferred in production scenarios as it’s overall more secure.

By Key

Basically, you will be storing the public key on the FTP server, and the client connecting into the server will use the associated private key. Easiest way is to have the client generate a public/private key pair and then add the public key to /home/ftpuser/.ssh/authorized_keys.

Once that’s done, make sure the ftpuser user has ownership of the authorized_keys file.

By Password

To allow for password, just use the following command:

Setting up SFTP

To set up SFTP, append the following to the end of /etc/ssh/sshd_config:

As you’re using a password to authenticate the above user, make sure the following is in the file as well:

PasswordAuthentication yes

Restart the service:

<code>sudo systemctl restart sshd

Verification

To verify everything is in place, try logging into the server as the new user:

<code>sftp ftpuser@YOUR_DOMAIN

Once connected in, try uploading a file:

PUT D:/local-file.png file.png

And then check that the file is there:

GET file.png D:/downloaded-file.png