How to Setup SFTP Server on Ubuntu 22.04

To set up an SFTP (Secure File Transfer Protocol) server on Ubuntu 22.04, you can follow these steps:

Step 1 : Update System Packages:

Step 2 : Install OpenSSH Server:

Step 3 : Configure SSH Server:

Open the SSH server configuration file using a text editor like Nano or Vim:

Locate the following lines and ensure they are set as shown below:

Add the SFTP Server Configuration

Save and exit the file.

Step 4 : Restart SSH Service:

Step 5 : Create an SFTP Group:

It is recommended to create a separate group for SFTP users. Create a group named "sftpusers" using the following command:

Step 6 : Create an SFTP User and Prompt for Information:

To create an SFTP user and prompt for additional information, use the following command:

Replace <username> with the desired username for your SFTP user.

When running this command, you will be prompted to enter additional information for the user, such as the full name, room number, work phone, and home phone. You can provide the information or leave it blank by pressing Enter.

Step 7 : Assign the User to the Group:

To assign the SFTP user to the "sftpusers" group, use the following command:

Replace <username> with the username you created in the previous step.

Step 8 : Configure Permissions

Step 9 : Allow SSH and SFTP through UFW (Optional):

If you are using UFW (Uncomplicated Firewall), follow these steps to allow SSH and SFTP connections:

- Check the current status of UFW:

Ensure that UFW is currently disabled (status should be "inactive"). If UFW is already enabled, consider whether the SFTP configuration aligns with your existing rules.

- Allow SSH connections:

- Enable UFW:

- Confirm the status of UFW:

Verify that the rules for SSH and SFTP have been added and are allowed.

Step 10 : Restart SSH Service:

Restart the SSH service to apply the changes:

Step 11 : Test the SFTP Connection:

- Open an SFTP client on your local machine (FileZilla)

- Configure the Connection:

  • Click on "File" in the top menu and select "Site Manager."
  • In the Site Manager, click on the "New Site" button and give it a name (e.g., "SFTP Server").
  • Under the "Host" field, enter the IP address or hostname of your Ubuntu 22.04 server.
  • Set the "Port" to 22 (unless you modified the SSH server configuration to use a different port).
  • Choose "SFTP - SSH File Transfer Protocol" as the protocol.
  • Set the "Logon Type" to "Normal."
  • Enter the username and password of the SFTP user you created.

- Test the Connection:

  • Click on the "Connect" button to establish the SFTP connection.
  • FileZilla will connect to the SFTP server and display the remote directory (typically the user's home directory) on the server.
  • You can now navigate the server's file system using FileZilla's interface and perform file transfer operations (upload, download, delete, etc.) securely over SFTP.

You have successfully set up an SFTP server on Ubuntu 22.04. Users belonging to the "sftp" group can securely connect to the server using SFTP, and if you configured UFW, SSH and SFTP connections will be allowed through the firewall.