Skip to content

Instantly share code, notes, and snippets.

@ilhamarrouf
Last active June 18, 2023 03:01
Show Gist options
  • Save ilhamarrouf/5cab62f9db2af2f45d91363325ee0004 to your computer and use it in GitHub Desktop.
Save ilhamarrouf/5cab62f9db2af2f45d91363325ee0004 to your computer and use it in GitHub Desktop.
Setup SFTP

Enable SFTP Without Shell Access on Ubuntu 22.04

Prerequisites

To follow this tutorial, you will need:

  • One Ubuntu 22.04 server set up with this initial server setup tutorial, including a sudo non-root user and a firewall.

Step 1 — Creating a New User

$ sudo adduser ftpuser

Step 2 — Creating a Directory for File Transfers

$ sudo mkdir -p /var/sftp/uploads
$ sudo chown root:root /var/sftp
$ sudo chmod 755 /var/sftp
$ sudo chown ftpuser:ftpuser /var/sftp/uploads

Step 3 — Restricting Access to One Directory

sudo vi /etc/ssh/sshd_config

Scroll to the very bottom of the file and append the following configuration snippet:

Match User ftpuser
    ForceCommand internal-sftp
    PasswordAuthentication yes
    ChrootDirectory /var/sftp
    PermitTunnel no
    AllowAgentForwarding no
    AllowTcpForwarding no
    X11Forwarding no
$ sudo systemctl restart sshd
$ sftp ftpuser@localhost
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment