How to Install OpenSSH SFTP Server on Ubuntu Server Latest

OpenSSH SFTP server is a powerful tool that allows you to secure file transfers over an encrypted SSH connection. In this tutorial, we will guide you through the process of installing OpenSSH SFTP server on Ubuntu Server Latest.

Prerequisites

Before proceeding with the installation process, you must have the following prerequisites:

Step 1: Update and Upgrade System

The first step is to update and upgrade the system to ensure that all the packages are up to date.

$ sudo apt-get update && sudo apt-get upgrade 

Step 2: Install OpenSSH Server

Next, we need to install the OpenSSH server on Ubuntu. Run the following command:

$ sudo apt-get install openssh-server

Step 3: Configure the OpenSSH Server

Once the installation is complete, we need to configure the OpenSSH server to enable SFTP service. Here's how:

  1. Open the configuration file /etc/ssh/sshd_config using any text editor.
$ sudo nano /etc/ssh/sshd_config 
  1. Uncomment the following line:
#Subsystem sftp /usr/lib/openssh/sftp-server

Change it to:

Subsystem sftp internal-sftp
  1. Add the following configuration at the end of the file:
Match group sftp
ChrootDirectory %h
ForceCommand internal-sftp
AllowTcpForwarding no
  1. Save and close the file.

Step 4: Create SFTP User

In this step, we will create an SFTP-only user that will be used to upload/download files. Run the following commands:

$ sudo groupadd sftp
$ sudo useradd -g sftp -d /incoming -s /usr/sbin/nologin sftp_user
$ sudo passwd sftp_user
$ sudo mkdir /home/sftp_user/incoming
$ sudo chown sftp_user:sftp /home/sftp_user/incoming

These commands will create a new sftp group, an SFTP-only user called sftp_user, and a directory called incoming within the home directory of sftp_user.

Step 5: Restart the SSH Service

After making the necessary changes, restart the SSH service to apply the new settings.

$ sudo systemctl restart ssh

Step 6: Test the SFTP Server

Now that the SFTP server is configured, it's time to test if it's working. Here's how:

  1. Open any SFTP client (FileZilla, WinSCP, Cyberduck, etc.)
  2. Connect to the Ubuntu server using the SFTP-only user account (sftp_user in our case).
  3. Try uploading/downloading files to/from the incoming directory.

If everything is working perfectly, the files should upload/download successfully.

Conclusion

Congratulations! You have successfully installed and configured the OpenSSH SFTP server on Ubuntu Server Latest. It is a powerful tool that can help you securely transfer files over an encrypted SSH connection.

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!