Setup user for SFTP access only

Scenario

Step by step

  1. Choose an upload/download/“home” directory
    all components of the path must be owned by root and not writable by anyone else!
    For this example, let's assume /mnt/web/sftpuser
  2. adduser -r -s /usr/sbin/nologin --home /mnt/web/sftpuser --no-create-home sftpuser
  3. /etc/passwd should look like this:
    sftpuser:x:1002:1002::/mnt/web/sftpuser:/usr/sbin/nologin
  4. Set the password
    passwd sftpuser
  5. append a section like this to /etc/ssh/sshd_config:
    Match User sftpuser
            ChrootDirectory /mnt/web/sftpuser
            ForceCommand internal-sftp -u 0002
            X11Forwarding no
            AllowTcpForwarding no
  6. (optionally) Add your own user to the newly created user's group: usermod -aG sftpuser user