Categories
Uncategorized

Setting up a Linux SFTP Server

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

  • A virtual machine with a public IP address.
  • SSH address to the above virtual machine

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:

sudo groupadd sftpg
sudo useradd -g sftpg ftpuser
sudo passwd ftpuser

Now set up the directories to allow for the following:

  • The user can view the contents of their own folder.
  • The user can upload files to the uploads/ folder.
sudo mkdir -p /data/ftpuser/upload
sudo chown -R root.sftpg /data/ftpuser
sudo chown -R ftpuser.sftpg /data/ftpuser/upload

Setting up SFTP

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

Match Group sftpg
     ChrootDirectory /data/%u
     ForceCommand internal-sftp

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:

sudo systemctl restart sshd

Verification

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

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

Leave a Reply

Your email address will not be published. Required fields are marked *