Facebook Twitter Instagram
    TecAdmin
    • Home
    • Ubuntu 20.04
      • Upgrade Ubuntu
      • Install Java
      • Install Node.js
      • Install Docker
      • Install LAMP Stack
    • Tutorials
      • AWS
      • Shell Scripting
      • Docker
      • Git
      • MongoDB
    • FeedBack
    • Submit Article
    • About Us
    Facebook Twitter Instagram
    TecAdmin
    Home»Network Services»SSH»How to Create SFTP User without Shell Access on Ubuntu 18.04 & 16.04

    How to Create SFTP User without Shell Access on Ubuntu 18.04 & 16.04

    RahulBy RahulJanuary 10, 20192 Mins ReadUpdated:January 24, 2019

    This tutorial will help you to create SFTP only user (without ssh access) on Ubuntu systems. The user can connect the server with SFTP access only and allowed to access the specified directory. User can’t SSH into the server. Follow the below tutorial to create sftp only account.

    Step 1 – Create User

    First of all, create a user account to use for sftp access. Below command will create user named sftpuser with no shell access.

    sudo adduser --shell /bin/false sftpuser
    

    Step 2 – Create Directory for SFTP

    Now, create the directory structure to be accessible by sftp user.

    sudo mkdir -p /var/sftp/files
    

    Change the ownership of the files directory to sftp user. So that sftpuser can read and write on this directory.

    sudo chown sftpuser:sftpuser /var/sftp/files
    

    And set the owner and group owner of the /var/sftp to root. The root user has read/write access on this access. Group member and other account have only read and execute permissions.

    sudo chown root:root /var/sftp
    sudo chmod 755 /var/sftp
    

    Step 3 – Configure SSH for SFTP Only

    Now edit the SSH configuration file in a text editor

    sudo vim /etc/ssh/sshd_config
    

    and add the following settings at end of file.

    Match User sftpuser
    	ForceCommand internal-sftp
    	PasswordAuthentication yes
    	ChrootDirectory /var/sftp
    	PermitTunnel no
    	AllowAgentForwarding no
    	AllowTcpForwarding no
    	X11Forwarding no
    

    Save the configuration and restart SSH service to apply changes.

    sudo systemctl restart ssh
    

    Step 4 – Test SFTP Connection

    I am using FileZilla for the connection to SFTP instance from my Windows systems. Linux desktop users can also use Filezilla for connection.

    For Linux server, users can use sftp command line utility to connect to remote sftp instance.

    sftp [email protected]
    
    Connecting to sftp.tecadmin.net...
    [email protected]'s password:
    sftp>
    

    Connect with FileZilla:

    As this account is configured for SFTP only connection. So if any user tried to connect via SSH will be disconnected immediately after successful authentication. User will get below message:

    ssh [email protected]
    
    [email protected]'s password:
    This service allows sftp connections only.
    Connection to sftp.tecadmin.net closed.
    
    SFTP sftp-server
    Share. Facebook Twitter Pinterest LinkedIn Tumblr Email WhatsApp
    Previous ArticleHow to Get Absolute Directory Path in PHP Script
    Next Article How to Install Ionic Framework on Linux Mint 19/18

    Related Posts

    (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms

    Updated:May 10, 20221 Min Read

    How to Create SFTP Only User in Debian 11

    Updated:September 26, 20214 Mins Read

    How to Use SSH Config File

    5 Mins Read

    How to Set Up Passwordless SSH login

    4 Mins Read

    How To Setup FTP Server with VSFTPD on Ubuntu 20.04

    Updated:July 15, 20215 Mins Read

    How To Create SFTP User for a Web Server Document Root

    5 Mins Read

    5 Comments

    1. Miguel on February 18, 2020 12:03 am

      Hi Rahul

      Great guide. Thanks.
      I have created an user, but it can’t upload anything. Filezilla says that it doesn’t have permission.
      Any advice? I want to save almost everywhere, at least from /var on.
      Thanks in advance.

      Miguel

      Reply
    2. Nelson Sanu on August 27, 2019 8:47 am

      Hi,

      This article was very help full for me to create SFTp User. I’m struggling to changes the directory.
      Can you help me to changes the sftpuser director /var/sftp ~ /var/www/html/… ?
      Thanks in Advance

      Reply
      • Rahul on August 28, 2019 9:23 am

        Hi Nelson, What issue are you facing? You can change the ChrootDirectory value to do this.

        Reply
        • Miguel on February 18, 2020 1:14 pm

          Hi Rahul

          Great guide. Thanks.
          I have created an user, but it can’t upload anything. Filezilla says that it doesn’t have permission.
          Any advice? I want to save almost everywhere, at least from /var on.
          Thanks in advance.

          Miguel

          Reply
          • Rahul on February 19, 2020 3:11 am

            What is the permissions on directory?

            Reply

    Leave A Reply Cancel Reply

    Recent Posts
    • How to Install Sublime Text 4 on Ubuntu 22.04
    • How to Enable / disable Firewall in Windows
    • How to Install JAVA on Ubuntu 22.04
    • Switching Display Manager in Ubuntu – GDM, LightDM & SDDM
    • Changing the Login Screen Background in Ubuntu 22.04 & 20.04
    Facebook Twitter Instagram Pinterest
    © 2022 Tecadmin.net. All Rights Reserved | Terms  | Privacy Policy

    Type above and press Enter to search. Press Esc to cancel.