Grid Guides

Explore How System On Grid Can Work For You

Grid Guide Topics

How to Setup SFTP Server on Ubuntu 18.04

Table Of Contents


    ## Table of Contents

    – [Introduction](#introduction
    – [Prerequisites](#prerequisites
    – [Configure FTP Server](#configure-ftp-server
    – [Configure SSH Daemon](#configure-ssh-daemon
    – [Create SFTP User Account](#create-sftp-user-account
    – [User Login via SFTP](#user-login-via-sftp
    – [Conclusion](#conclusion

    ## Introduction

    FTP stands for “File Transfer Protocol” is a popular method of transferring files between two remote systems. SFTP stands for SSH File Transfer Protocol, or Secure File Transfer Protocol is a separate protocol packaged with SSH that works similarly over a secure connection.

    ## Prerequisites

    SFTP Configuration assumes that you have to configure your FTP server by following the FTP configuration guide. Privileged access to the system as root or via sudo command is required.

    ## Configure FTP Server

    This guide describes FTP over secure SSH protocol. Before starting this guide make sure that you have already configured your FTP server using below link.

    ## Configure SSH Daemon

    If you have not configured till now, you have to install SSH server:
    “`
    $ sudo apt install ssh
    “`
    If you want to configure FTP over OpenSSH server, you have to edit the existing SSHD configuration file as below.

    “`
    $ sudo nano /etc/ssh/sshd_config
    “`
    Add this below file at the end of the file as below.
    “`
    Match group sftp
    ChrootDirectory /home
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp
    “`
    These lines say that users related to sftp group will be able to access their home directories, even though they will be denied SSH shell access.

    ![configuressgdaemon](https://grid.media/assets/images/configure-ssh-daemon.png

    To apply the new changes you have to restart the SSH server.
    “`
    $ sudo service ssh restart
    “`
    ## Create SFTP User Account
    Now you have to create a new user account which is specific to SFTP service. Now you have to create a new group called sftp:
    “`
    $ sudo addgroup sftp
    “`

    ![addgroupsftp](https://grid.media/assets/images/addgroup-sftp.png

    Now you have to create a new user sftpuser assign him to the sftp group by using the below command.
    “`
    $ sudo useradd -m sftpuser -g sftp
    “`
    You have to set a new password for sftpuser user:
    “`
    $ sudo passwd sftpuser

    “`

    ![passwordsftpuser](https://grid.media/assets/images/passwd-sftpuser.png

    At last change access permissions to the user’s home to deny access to it from any others on the same system. To do it use the below command.
    “`
    $ sudo chmod 700 /home/sftpuser/
    “`
    ## User Login via SFTP

    Now the new user called sftpuser can log in to the new sftp server via sftp:// protocol. Now SFTP server can be resolved via eg. hostname ubuntu-sftp use sftp command to create new SFTP connection.
    “`
    $ sftp sftpuser@testsftp

    “`

    ![sftpusertestsftp](https://grid.media/assets/images/sftpuser-testsftp.png

    Now navigate to your home directory and confirm write access by creating a new directory.
    “`
    sftp> cd sftpuser
    sftp> mkdir sftp-test
    sftp> ls
    “`

    ![sftptest](https://grid.media/assets/images/ls.png

    ## Conclusion
    Now you are connected to SFTP