SFTP – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Tue, 23 Aug 2022 13:14:24 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Create SFTP User in Ubuntu 22.04 (No Shell Access) https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-22-04/ https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-22-04/#comments Tue, 14 Jun 2022 14:21:32 +0000 https://tecadmin.net/?p=30013 SFTP is a protocol that allows for the secure transfer of files over a network. It is often used by businesses and individuals to transfer sensitive data. SFTP is similar to FTP but uses a different protocol for communication. SFTP is more secure than FTP and is often used in conjunction with SSH (Secure Shell) [...]

The post How to Create SFTP User in Ubuntu 22.04 (No Shell Access) appeared first on TecAdmin.

]]>
SFTP is a protocol that allows for the secure transfer of files over a network. It is often used by businesses and individuals to transfer sensitive data. SFTP is similar to FTP but uses a different protocol for communication. SFTP is more secure than FTP and is often used in conjunction with SSH (Secure Shell) to provide an even higher level of security.

In this tutorial, we will help you to set up an SFTP server and create an SFTP-only user on Ubuntu 22.04 systems. That account can connect over SFTP but is not able to connect over SSH. Also, this will restrict (chroot) the SFTP user to a specific directory only.

Prerequisites

  • A running Ubuntu 22.04 LTS system with shell access
  • Requies a sudo privileged account

Step 1 – Installing OpenSSH Server

The Ubuntu servers have already installed the OpenSSH server but the desktop systems may not have it. Use the following command to install and run OpenSSH server:

sudo apt update && sudo apt install openssh-server 

Step 2 – Create SFTP User

First of all, create a new account in your system to use as sftp user.

The following command will create a new account named sftpuser with no shell access. You can change the username of your choice

sudo adduser --shell /bin/false sftpuser 
Create SFTP user in Ubuntu
Creating SFTP user in Ubuntu

Step 3 – Configure SFTP Directory

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

sudo mkdir -p /var/sftp/files 

Here we will allow users to access the “files” directory only.

Now, change the ownership of the files directory to the sftpuser. So that sftpuser can read and write on this directory only.

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 members and other accounts have only read and execute permissions.

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

Step 4 – Update SSH Configuration File

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

Make sure to add configuration after the Subsystem line as shown in below screenshot:

SFTP Only Configuration  on Ubuntu
SFTP only configuration on Ubuntu

Save the configuration file and close it.

Now validate the configuration file.

sudo sshd -t 

If the validation is successful, no output will be displayed. In case, any error shows in the output, make sure to fix it before running the next commands.

Restart the SSH service to apply changes.

sudo systemctl restart ssh 

All done. SFTP-only user is successfully created on your Ubuntu system. Now try logging into the remote system with the new user’s credentials, and check if everything is working correctly.

Step 5 – Connect to SFTP User

One can connect to a remote SFTP server using a command line or graphical applications like Filezilla or WinSCP. In this tutorial, I will show you both ways to connect sftp to only an account on the Ubuntu system.

Linux users can use the sftp command-line utility to connect to a remote sftp instance.

sftp sftpuser@192.168.1.210 

sftpuser@192.168.10.100's password:
sftp>

You can also connect to a remote SFTP server using graphical interface applications like FileZilla. That is available for both Linux and Windows users. Open the Filezilla application and input to sftp details:

  • Host: sftp://system-ip-host
  • Username: Use SFTP user created in step 1.
  • Password: Use SFTP user password created in step 1.
  • Port: Use SSH server port or keep empty for default port.

Click the Quickconnect button:

Connect SFTP to Ubuntu 22.04  with Filezilla

Verify no shell access:

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. The user will get the below message:

ssh sftpuser@192.168.1.210  

sftpuser@sftp.tecadmin.net's password:
This service allows sftp connections only.
Connection to sftp.tecadmin.net closed.

Conclusion

In conclusion, setting up an SFTP server is a great way to securely transfer files between computers. By following the steps in this article, you can set up your own SFTP server in no time on Ubuntu systems. If you have any questions, feel free to leave a comment below and we’ll be happy to help.

The post How to Create SFTP User in Ubuntu 22.04 (No Shell Access) appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-22-04/feed/ 2
(Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms https://tecadmin.net/userauth_pubkey-key-type-ssh-rsa-not-in-pubkeyacceptedalgorithms/ https://tecadmin.net/userauth_pubkey-key-type-ssh-rsa-not-in-pubkeyacceptedalgorithms/#comments Mon, 02 May 2022 12:14:02 +0000 https://tecadmin.net/?p=29385 The Problem: Today, I launched a new AWS instance with Ubuntu 22.04. The default key provided by AWS is working fine with SSH. But when I attached my personal ssh key to the server and tried to access with FileZilla over SFTP, I got the following error in auth.log. May 10 11:52:58 localhost sshd[57650]: Disconnected [...]

The post (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms appeared first on TecAdmin.

]]>
The Problem:

Today, I launched a new AWS instance with Ubuntu 22.04. The default key provided by AWS is working fine with SSH. But when I attached my personal ssh key to the server and tried to access with FileZilla over SFTP, I got the following error in auth.log.

May 10 11:52:58 localhost sshd[57650]: Disconnected from authenticating user ubuntu 203.190.146.202 port 46565 [preauth]
May 10 11:52:59 localhost sshd[57652]: userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]
May 10 11:53:00 localhost sshd[57652]: message repeated 3 times: [ userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms [preauth]]
May 10 11:53:00 localhost sshd[57652]: error: Received disconnect from 203.190.146.202 port 50045:14: No supported authentication methods available [preauth]

The Solution:

First, I make confirm that key-based authentication is working as I was able to log in with the ssh key provided by the AWS console. After that, I created a new key with type ecdsa.

Open a terminal and generate a new key-pair:

ssh-keygen -t ecdsa 

Once the key is generated, add the public key to remote servers ~/.ssh/authorized_key file.

Now, I can successfully connect to the remote server with FileZilla over SFTP.

The post (Resolved) userauth_pubkey: key type ssh-rsa not in PubkeyAcceptedAlgorithms appeared first on TecAdmin.

]]>
https://tecadmin.net/userauth_pubkey-key-type-ssh-rsa-not-in-pubkeyacceptedalgorithms/feed/ 2
How to Create SFTP Only User in Debian 11 https://tecadmin.net/how-to-create-sftp-only-user-in-debian-11/ https://tecadmin.net/how-to-create-sftp-only-user-in-debian-11/#respond Sun, 26 Sep 2021 06:44:55 +0000 https://tecadmin.net/?p=27867 SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Security first is a thumb rule for the system administrators. In some cases, we need to allow remote users to access the filesystem on our system, but you don’t want to allow [...]

The post How to Create SFTP Only User in Debian 11 appeared first on TecAdmin.

]]>
SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Security first is a thumb rule for the system administrators. In some cases, we need to allow remote users to access the filesystem on our system, but you don’t want to allow them to get a shell. This will allow you a secure channel to provide limited access to specific files and directories.

This tutorial will help you to setup SFTP only access (without shell access) on Debian 11 system. It will create a chroot environment on your system to limit the SFTP user to a specific directory only. Also, it will allow SFTP only access without SSH access to the user.

Prerequisites

  • A running Debian 11 Bullseye Linux system
  • You must have sudo privileged account with shell access

Step 1 – Create a New User

First of all, create a new user to connect with the sftp server. The following command will create a new account named sftpuser with no shell access. You can use any name of your choice or requirement.

sudo adduser --shell /bin/false sftpuser 

Step 2 – Create a Directory for SFTP Access

You have created a user for sftp. Now, create a directory to configure as chroot for the sftp. For this example, I will create a /var/sftp directory. The directory must have root ownership to configure as chroot directory. So we will create a subdirectory under /var/sftp with write access to sftp account.

Create the directory structure with the following command:

sudo mkdir -p /var/sftp/files 

Next, we have to set proper permission on directories to configure as chroot access with write access to the user. Here /var/sftp must have the root ownership and group with proper permission. To set that permission, type:

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

Now, change the permission for the "files" directory to allow write access to sftpuser. To set that permissions, type:

sudo chown sftpuser:sftpuser /var/sftp/files 

Once the sftpuser connects to the server, will get /var/sftp as the root directory. He can’t access the filesystem outside it. Also, the user can read/write files under the “files” directory only.

Step 3 – Configure sshd for SFTP Only

Next, you need to configure the SSH server to allow the “sftpuser” to connect the server with sFTP only without shell access. To make necessary changes, edit the SSH configuration file.

sudo nano /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
Chroot Settings for SFTP User
Chroot Configuration for SFTP User

Double-check that all the settings are correct. Then save the changes and restart the SSH service to apply changes.

sudo systemctl restart ssh 

All done, SFTP only use is successfully created on your Debian system. Now try logging into the remote system with the new user’s credentials, and check if everything is working correctly.

Step 4 – Connect to SFTP

One can connect to a remote SFTP server using a command line or graphical applications like Filezilla or WinSCP. In this tutorial, I will show you both ways to connect SFTP server.

Linux users can use sftp command-line utility to connect to remote sftp instances.

sftp sftpuser@sftp.tecadmin.net 

sftpuser@sftp.tecadmin.net's password:
sftp>

GUI interface or Windows users can use graphical sftp clients. For example, use Filezilla client to connect remote sftp only account on the remote system.

connect sftp only user on Debian

Verify no shell access:

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 sftpuser@sftp.tecadmin.net 

sftpuser@sftp.tecadmin.net's password:
This service allows sftp connections only.
Connection to sftp.tecadmin.net closed.

Conclusion

In this how-to guide, you have learned to create chroot jail environment for SFTP users without shell access to the server. The Chroot environment secures the filesystem by preventing users to access files outside of the defined directory. This tutorial is created and tested with Debian 11 Bullseye system but this will work on other Debian versions.

The post How to Create SFTP Only User in Debian 11 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-sftp-only-user-in-debian-11/feed/ 0
How To Setup FTP Server with VSFTPD on Ubuntu 20.04 https://tecadmin.net/how-to-setup-vsftpd-on-ubuntu-20-04/ https://tecadmin.net/how-to-setup-vsftpd-on-ubuntu-20-04/#respond Thu, 15 Jul 2021 09:46:37 +0000 https://tecadmin.net/?p=22749 FTP (File Transfer Protocol) is a network transmission standard that is used to transfer data from client to server and vice versa. It uses TCP (Transmission Control Protocol) which ensures that the data is actually arriving at its destination. TCP is what makes FTP reliable. FTP is very helpful for businesses as it allows them [...]

The post How To Setup FTP Server with VSFTPD on Ubuntu 20.04 appeared first on TecAdmin.

]]>
FTP (File Transfer Protocol) is a network transmission standard that is used to transfer data from client to server and vice versa. It uses TCP (Transmission Control Protocol) which ensures that the data is actually arriving at its destination. TCP is what makes FTP reliable.

FTP is very helpful for businesses as it allows them to perform important functions such as the transfer of large and bulky files on a routine basis. These activities cannot be done over email or through other basic file-sharing programs. It is also used to upload and manage website files to the server.

The FTP is still a very popular way for transferring files but due to the security regions, many peoples prefer SFTP. Use this article to create SFTP only users without shell access.

In this write-up, we will be focusing on how to set up an FTP server with VSFTPD on Ubuntu 20.04.

Installing vsftpd on Ubuntu

VSFTPD is the default FTP server for most Linux distributions. We will start off by installing it on our system. Use the command given below to install VSFTPD.:

sudo apt update 
sudo apt install vsftpd 

installing vsftpd ubuntu 20.04

Now verify the successful installation of VSFTPD by executing the following command:

sudo systemctl status vsftpd 

check vsftpd service status

How to Configure vsftpd on Ubuntu

Now we will configure the newly installed vsftpd. The configuration rules of vsftpd are stored in /etc/vsftpd.conf. Open the configuration file in any text editor. Here we will use nano to open the configuration file:

sudo nano /etc/vsftpd.conf 

Update the following configuration settings:

  1. FTP access

    To only allow local users to access FTP server, make sure your configuration file matches the one given below:

    anonymous_enable=NO
    local_enable=YES
    
  2. FTP Passive connections

    VSFTPD works on the active mode by default. To allow VSFTPD to work on passive mode copy the below-given lines into your configuration file:

    pasv_min_port=40000
    pasv_max_port=45000
    

    You can give any range of ports to the configuration file. The system will connect a random port from the range you’ve chosen.

    The connection is established by the server in active mode whereas in the passive mode the connection is established by the client’s side.

  3. Enable Uploads

    To allow the FTP user to modify the filesystem, search for the following line in the configuration file and uncomment it by removing the ‘#’ (hash) symbol from the beginning of the line:

    write_enable=YES
    
  4. Restrict FTP access

    To allow only certain users to access VSFTPD, copy the below given lines at the end of the configuration file:

    userlist_enable=YES
    userlist_file=/etc/vsftpd.user_list
    userlist_deny=NO
    

These configuration settings are very basic. You can set the configuration rules according to your own needs.

Press Ctrl + X and then hit Enter to save and exit the text file. Now run the following command to restart the VSFTPD service:

sudo systemctl restart vsftpd 

How to Configure the Firewall For FTP on Ubuntu

Now we will configure the firewall to allow FTP traffic. We will open ports 20 and 21, the default/recommended ports for FTP, and ports 40000:45000 for passive FTP. But first, let’s allow SSH by using the command given below otherwise we may get locked out of our server:

sudo ufw allow OpenSSH 

If you get an error “ERROR: Could not find a profile matching ‘OpenSSH’” then you first need to install OpenSSH before running the above command. Use the following command to install OpenSSH on your system:

sudo apt install ssh

Once everything is set up, open the default ports 20 and 21 for FTP:

sudo ufw allow 20:21/tcp

Open the ports 40000:45000 for passive FTP as well:

sudo ufw allow 40000:45000/tcp

Now run the firewall by using the following command. Ignore, if it gives a warning about the disruption of SSH connection. Press y and hit Enter:

sudo ufw enable

The firewall is already active and enabled on my system.

You may run the following command to verify the firewall rules that were just added:

sudo ufw status

UFW Allow FTP

How to Create a user for FTP on Ubuntu

Use the “adduser” command to create a new user. We will use this user to login into FTP.

sudo adduser test_user 

The terminal will ask you to set the password of the new user. It will also ask for a few other details. Just press Enter if you do not want to provide these details.

You can restrict this user’s SSH access if you only want them to log in through FTP. Use the nano editor to open the SSH configuration files:

sudo nano /etc/ssh/sshd_config 

Now copy the following line and paste it into the configuration file to restrict the users access:

DenyUsers test_user

vsftpd deny specific user

(Do remember to replace “test_user” with the actual name of your user)

Save and exit the configuration file and reboot the SSH service using the below-given command to let the changes take effect:

sudo systemctl restart ssh

Now add the user to the list of FTP users by running the following command:

echo "test_user" | sudo tee -a /etc/vsftpd.user_list

Next make a new directory for the user to use for uploading the files:

sudo mkdir -p /home/test_user/ftp/test_dir 

Now give permissions to the new user according to your requirements. Here we are giving the following permission to the test_user:

sudo chmod 550 /home/test_user/ftp 
sudo chmod 750 /home/test_user/ftp/test_dir 
sudo chown -R test_user: /home/test_user/ftp 

Here 550 gives the “read” and “execute” permission in the following way:

chmod 550 permissions

While 750 gives the “write” permission as well to the owner in the following way:

chmod 750 permissions

That’s it. Your FTP server has been fully set up.

Conclusion

FTP is used to transfer files between computers on a network. It is a protocol that dictates (instructs) how data is transferred between computers on the network. People still use FTB but it is not as secure as SCP or SFTP.

In this write-up, we focused on how to install, set up, and configure VSFTPD. Moreover, we comprehended how to configure firewalls and create a new user for FTP.

You may also like another tutorial, how to download and upload files using ftp command line.

The post How To Setup FTP Server with VSFTPD on Ubuntu 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-setup-vsftpd-on-ubuntu-20-04/feed/ 0
How To Create SFTP User for a Web Server Document Root https://tecadmin.net/how-to-create-sftp-user-for-a-web-server-document-root/ https://tecadmin.net/how-to-create-sftp-user-for-a-web-server-document-root/#comments Mon, 12 Jul 2021 10:43:41 +0000 https://tecadmin.net/?p=25790 SFTP (SSH/Secure File Transfer Protocol) is a network transmission standard used to transfer, access, and manage files over a remote network. It contains SSH (Secure Shell), making it a lot more secure than the FTP protocol. Files are transferred through a single control channel in SFTP. It requires authentication and runs on port 22. In [...]

The post How To Create SFTP User for a Web Server Document Root appeared first on TecAdmin.

]]>
SFTP (SSH/Secure File Transfer Protocol) is a network transmission standard used to transfer, access, and manage files over a remote network. It contains SSH (Secure Shell), making it a lot more secure than the FTP protocol.

Files are transferred through a single control channel in SFTP. It requires authentication and runs on port 22. In SFTP, the SSH shell provides encryption that helps protect usernames, passwords, and other personal data transferred through SFTP.

In this how-to guide, we will learn to create SFTP users for web server document root.

Step 1 – Installing SSH (Secure Shell)

SFTP is a very secure file transfer protocol because of the encryption that SSH provides for the data as it is transferred over the network. SSH is mainly installed on Linux distributions by default, but if it is not pre-installed in your system, then you can use the below-given command to install it:

sudo apt install ssh 

Installing SSH Server

If already installed, the command will upgrade OpenSSH packages.

Step 2 – Configuring SSH to use the SFTP Server Code

Now open the configuration file of SSH in a text editor to modify it for SFTP server code. Here we will use the nano editor to edit the configuration file.

sudo nano /etc/ssh/sshd_config 

Locate the line starting from “Subsystem sftp”.

Locate subsystem in ssh config

Comment the line by adding # at the start of the line and write the following line after this line as shown in the screenshot given below:

Subsystem sftp internal-sftp

Adding Subsystem sftp internal-sftp

The SSHD will use the SFTP server code instead of running the SFTP server by changing the above line.

Once you have changed the configuration file, save the file and exit from it using the keyboard shortcut keys CTRL+S and CTRL+X.

After changes, we need to restart the SSHD daemon to let the changes work.

sudo systemctl restart sshd 

Step 3 – Creating a User(SFTP User)

It is an excellent practice to create a new user that only has SFTP access to the document root. It is not recommended to add a user with Sudo privileges to the webserver document root. Create a new user using the adduser command:

sudo adduser sftpuser 

The terminal will ask for a couple of things like setting the password, and user information. It will also ask for a few other details, so either leave them empty or provide the proper information.

Sudo adduser sftp

A new user with the name of sftpuser is successfully created.

Step 4 – Creating Match User Directive in the SSH configuration file

Now we will restrict this user to the document root and we will also disable the user’s access to SSH so that the user will log in through SFTP.

To restrict the user’s access, open up the configuration file of SSH in any text editor:

sudo nano /etc/ssh/sshd_config 

Now go to the end of the file and add the following content in the “sshd_config” configuration file:

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

Make sure to replace the “sftpuser” username with the username you set.

Match User sftpuser in sshd_config

Once the above content is added to the SSH configuration file, save and exit using CTRL+S and CTRL+X shortcut keys.

To check the syntax and verify if everything went well, you can execute the command:

sudo sshd -t 

If no error occurred, we could reload the SSH service for the changes to work.

sudo systemctl restart sshd 

Step 5 – Adding SFTP User to www-data Group

Now we will add the user to the www-data group by executing the following command:

sudo usermod -a -G www-data sftpuser 

On a successful run, no output will be displayed.

Step 6 – Setting Document Root Directory Permission

Please follow the subsequent instructions very carefully as SFTP is very strict regarding chroot directory permissions.

  1. We will start by checking the current permissions and ownership of var:
    sudo ls -ld /var/ 
    
  2. The permissions should be 755 and the owner should be root by default. If not, then execute the command given below to set the proper permissions:
    sudo chmod 755 /var/ 
    
  3. Now use this command to set the correct ownership:
    sudo chown root:root /var/ 
    
  4. Similarly, apply the same permissions to the chroot:

    sudo chmod 755 /var/www/ 
    
  5. Since we have set “/var/www/” to the chroot directory. Now set the right ownership of the chroot directory:
    sudo chown root:root /var/www/ 
    
  6. To allow a group to write to the document root directory, set its permission to 755:
    sudo chmod 755 /var/www/html/ 
    
  7. To grant the ownership of the “/var/www/html” document root and its further directories and files to the www-data group, use the below-given command:
    sudo chown -R www-data:www-data /var/www/html* 
    
  8. Now give 755 permissions to the content placed in the “/var/www/html” document root using the command:
    sudo find /var/www/html/ -type d -exec chmod 775 {} \; 
    
  9. The above command will grant the SFTP user read, write, and executable permissions of the directories.

    We also need to give 664 permissions to all the files that are present in the document root to allow the owner and the SFTP users’ group to read and write the files:

    sudo find /var/www/html/ -type f -exec chmod 664 {} \; 
    
  10. Now for the last step, make certain that all the new files and directories acquire the www-data group that are created the newly created SFTP user:
    sudo find /var/www/html -type d -exec chmod g+s {} \; 
    

Congratulations! your new SFTP user has been created and added to the webserver document root. You can now log in to SFTP.

Conclusion

In this how-to guide, we have learned how to install and configure SSH for using the SFTP server code. After that, we created a new user, restricted them to document root, and disabled their SSH access. Then we added the user to the webserver document root to allow the user to read, write and execute files in the document root.

The post How To Create SFTP User for a Web Server Document Root appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-sftp-user-for-a-web-server-document-root/feed/ 1
How to Create SFTP Only User in Ubuntu & Debian https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-debian/ https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-debian/#comments Mon, 31 May 2021 11:45:24 +0000 https://tecadmin.net/?p=25309 SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Here SFTP only user means to create an account to access the server via SFTP only. That user doesn’t have SSH shell access. This allows you a secure channel to provide limited [...]

The post How to Create SFTP Only User in Ubuntu & Debian appeared first on TecAdmin.

]]>
SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Here SFTP only user means to create an account to access the server via SFTP only. That user doesn’t have SSH shell access. This allows you a secure channel to provide limited access to specific files and directories.

This blog post describes you create SFTP-only users without shell access on Ubuntu and Debian systems.

Step 1- Creating a New User

First of all, create a user account in your system to use as an SFTP user. The following command will create a new account named sftpuser with no shell access. You can change the username of your choice

sudo adduser --shell /bin/false sftpuser 

The command will prompt for the password to be set for a new account.

Step 2 – Create Directory for SFTP

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

sudo mkdir -p /var/sftp/files 

Here we will allow users to access the “files” directory only.

Now, change the ownership of the files directory to the sftpuser. So that SFTP users can read and write on this directory only. No files outside of this directory will be accessible.

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 members and other accounts have only read and execute permissions.

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

It will restrict SFTP users from writing files under /var/sftp directory.

Step 3 – Configure sshd for SFTP Only

/etc/ssh/sshd_config is the main configuration file of the OpenSSH server. Be careful with changing this configuration file, because any mistake can lead to connection loss.

Edit the SSH configuration file in a text editor:

sudo vim /etc/ssh/sshd_config 

then add the following settings at end of the file.

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

Save the file and close.

The directives are:

  • Match User Defines the username, on which the SFTP only configurations applied. In our case it is: sftpuser
  • ForceCommand internal-sftp enforce the SFTP only access to user and restrict for the shell access.
  • PasswordAuthentication yes allows password authentication for the user.
  • ChrootDirectory /var/sftp Restrict user to access directories under this directory only. Here /var/sftp is act as the root directory of the user.
  • AllowAgentForwarding no Specifies whether ssh-agent forwarding is permitted. The default is yes.
  • AllowTcpForwarding no Specifies whether TCP forwarding is permitted. The default is yes.
  • X11Forwarding no Specified where the graphical application is permitted for not

Restart SSH service to apply new settings:

sudo systemctl restart ssh 

That’s it. You have successfully completed the instructions to create an SFTP-only user on Debian-based systems.

Step 4 – Security Tips (Options)

Here are some basic but important security tips for SFTP accounts in a production environment.

  1. Run SSH server on a non-standard port
  2. Disallow the password authentication and configure key-based authentication
  3. Make sure the firewall is restricted to specific IP addresses only
  4. And keep the OpenSSH package up to date

Conclusion

This tutorial describes you create SFTP-only users in the Ubuntu system. It will disabled shell access for the same users to restrict to a specified directory only.

The post How to Create SFTP Only User in Ubuntu & Debian appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-debian/feed/ 2
How to Create SFTP Only User in Ubuntu 20.04 https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-20-04/ https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-20-04/#comments Tue, 25 May 2021 03:50:17 +0000 https://tecadmin.net/?p=25300 SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Security first is an thumb rules for the system administrators. Some times you may need to provide FTP/SFTP access to development or other teams to access file on remote server. This will [...]

The post How to Create SFTP Only User in Ubuntu 20.04 appeared first on TecAdmin.

]]>
SFTP (SSH File Transfer Protocol) is a secure file protocol used to access, manage, and transfer files over an encrypted SSH transport session. Security first is an thumb rules for the system administrators. Some times you may need to provide FTP/SFTP access to development or other teams to access file on remote server. This will allow you a secure channel to provide limited access to specific files and directories.

This tutorial will help you to create SFTP only user (without ssh shell access) on Ubuntu systems. And restrict (chroot) the SFT user account to specific directory only. Also disable the shell access to user.

Prerequisites

  • A running Ubuntu 20.04 LTS system
  • You must have sudo privileged account with shell access

Step 1 – Create User

First of all, create a user account in your system to use as sftp user. The following command will create a new account named sftpuser with no shell access. You can change the username of your choice

sudo adduser --shell /bin/false sftpuser 

Step 2 – Create Directory for SFTP

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

sudo mkdir -p /var/sftp/files 

Here we will allow user to access “files” directory only.

Now, change the ownership of the files directory to the sftpuser. So that sftpuser can read and write on this directory only.

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 sshd 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 

All done, SFTP only use is successfully created on your Ubuntu system. Now try logging into the remote system with the new user’s credentials, and check if everything is working correctly.

Step 4 – Connect to SFTP User

Once can connect to remote SFTP server using command line or graphical applications like Filezilla or WinSCP. In this tutorial, I will show you both ways to connect sftp only account on Ubuntu system.

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

sftp sftpuser@sftp.tecadmin.net 

sftpuser@sftp.tecadmin.net's password:
sftp>

GUI interface or Windows users can use graphical sftp clients. For example, use filezilla client to connect remote sftp only account on remote system.

connect sftp only user on Ubuntu

Verify no shell access:

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 sftpuser@sftp.tecadmin.net 

sftpuser@sftp.tecadmin.net's password:
This service allows sftp connections only.
Connection to sftp.tecadmin.net closed.

Conclusion

This tutorial describes you to create a sftp only user account on Ubuntu system. Disabled shell access for the same account to restrict user to sftp access only.

The post How to Create SFTP Only User in Ubuntu 20.04 appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-create-sftp-only-user-in-ubuntu-20-04/feed/ 2
How to Create SFTP User without Shell Access on CentOS/RHEL 8 https://tecadmin.net/create-sftp-user-without-shell-access-on-centos-8/ https://tecadmin.net/create-sftp-user-without-shell-access-on-centos-8/#comments Sun, 16 Feb 2020 16:06:44 +0000 https://tecadmin.net/?p=20307 SFTP (SSH File Transfer Protocol) is a secure file transfer protocol between two systems. It runs over SSH protocol and shares the same port 22. This tutorial will help you to create SFTP only access users (without ssh access) on CentOS 8 and RedHat 8 systems. The user can connect the server with SFTP only [...]

The post How to Create SFTP User without Shell Access on CentOS/RHEL 8 appeared first on TecAdmin.

]]>
SFTP (SSH File Transfer Protocol) is a secure file transfer protocol between two systems. It runs over SSH protocol and shares the same port 22. This tutorial will help you to create SFTP only access users (without ssh access) on CentOS 8 and RedHat 8 systems. The user can connect the server with SFTP only and allowed to access the specified directory. Users can’t SSH into the server. Follow the below tutorial to create sftp only account on CentOS 8 and RHEL 8.

Step 1 – Create Account

First of all, create a user account for the sftp access. For this tutorial, we are creating a user named sftpuser with no shell access. Also, set a strong password for the user.

sudo adduser --shell /bin/false sftpuser
sudo passwd sftpuser
Changing password for user sftpuser.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.

Step 2 – Create Directory

Now, create the directory structure to be accessible by sftp user. we will restrict the new user to this directory only. So the user can’t access files to other directories.

sudo mkdir -p /var/sftp/files

Change the ownership of the directory to newly created sftp users. So that sftpuser can read and write on this directory.

sudo chown sftpuser:sftpuser /var/sftp/files

You must set the owner and group owner of the /var/sftp to root. The root user has read/write access on this access. Group members and other accounts have only read and execute permissions.

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

Step 3 – Configure SSH for SFTP

As we know the SFTP runs over the SSH protocol, So we need to configure this in the configuration file. Edit the SSH configuration file in a text editor.

sudo vim /etc/ssh/sshd_config

And add the following settings at end of the 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 sshd.service

All done, Your system is ready to accept sftp only connection for the created account. Let’s test the sftp connection and also make sure that the user is not authorized to SSH.

Step 4 – Test SFTP Connection

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

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

sftp sftpuser@sftp.tecadmin.net
Connecting to sftp.tecadmin.net...
sftpuser@sftp.tecadmin.net's password:
sftp>

Connect with FileZilla:

sftp only user centos 8

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 sftpuser@sftp.tecadmin.net
sftpuser@sftp.tecadmin.net's password:
This service allows sftp connections only.
Connection to sftp.tecadmin.net closed.

The above message (This service allows sftp connections only.) shows that the user has sftp access only. Users can’t connect server over SSH.

The post How to Create SFTP User without Shell Access on CentOS/RHEL 8 appeared first on TecAdmin.

]]>
https://tecadmin.net/create-sftp-user-without-shell-access-on-centos-8/feed/ 2
How to Download and Upload files with SFTP Command https://tecadmin.net/sftp-command-line-examples/ https://tecadmin.net/sftp-command-line-examples/#respond Sat, 02 Mar 2019 06:00:32 +0000 https://tecadmin.net/?p=17417 SFTP (SSH File Transfer Protocol) is a secure protocol to transfer files between systems. It uses an encrypted secure shell (SSH) for the communication between two systems. You can also use this or this tutorial to configure sftp only user on your Linux system without SSH access. In this tutorial you will learn: Connect to [...]

The post How to Download and Upload files with SFTP Command appeared first on TecAdmin.

]]>
SFTP (SSH File Transfer Protocol) is a secure protocol to transfer files between systems. It uses an encrypted secure shell (SSH) for the communication between two systems.

You can also use this or this tutorial to configure sftp only user on your Linux system without SSH access.

In this tutorial you will learn:

  1. Connect to remote sftp server
  2. Navigation in file system
  3. Upload files to SFTP server
  4. Download files from SFTP server
  5. Close SFTP connection

Connect to Remote SFTP Server

Use sftp command-line utility to connect remote sftp system. You need the sftp user and hostname or IP address of the remote host.

sftp sftpuser@sftp.tecadmin.net 

Enter sftpuser account password to connect:

sftpuser@sftp.tecadmin.net's password:
sftp>

Navigate and View Files

Navigation in directories on SFTP is as simple as the local system. Use ‘pwd’ command to check the current working directory.

 pwd 

Remote working directory: /

Then use the ‘ls’ command to list all files and directories in the current directory.

 ls 

To navigate to other directories use ‘cd’ command followed by destination directory.

 cd uploads 

Use ‘cd ..’ to navigate to the parent directory.

 cd .. 

Upload files to SFTP

Now, I need to upload some files under uploads directory. Use the ‘put’ command to upload README.md from the local system to the remote sftp directory.

put README.md 

You can also provide the absolute path of the local file and remote directory without navigating directories.

put /var/www/README.md /uploads/20191115/ 

sftp upload command example

Download Files from SFTP

To download files from the remote sftp directory use the ‘get’ command. For example to download REMOTE_FILE.md from the remote system to the current local directory.

get REMOTE_FILE.md

Similarly, you can provide an absolute path to download files.

get /uploads/REMOTE_FILE.md /var/www/

sftp download command example

Quit the SFTP Connection

Simply say bye to your remote SFTP server. This will disconnect the SFTP connection and return to your local shell.

bye 

Alternatively, you can also use quit or exit commands to close the SFTP session.

Conclusion

In this tutorial, you have learned to how to download and upload files using sftp command line.

The post How to Download and Upload files with SFTP Command appeared first on TecAdmin.

]]>
https://tecadmin.net/sftp-command-line-examples/feed/ 0
How to Create SFTP User without Shell Access on CentOS/RHEL 7 https://tecadmin.net/create-sftp-only-user-centos/ https://tecadmin.net/create-sftp-only-user-centos/#comments Tue, 15 Jan 2019 10:03:14 +0000 https://tecadmin.net/?p=17840 This tutorial will help you to create SFTP only user (without ssh access) on CentOS and RedHat systems. The user can connect the server with SFTP access only and allowed to access the specified directory. Users can’t SSH into the server. Follow the below tutorial to create sftp only account. Step 1 – Create Account [...]

The post How to Create SFTP User without Shell Access on CentOS/RHEL 7 appeared first on TecAdmin.

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

Step 1 – Create Account

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
sudo passwd sftpuser

Step 2 – Create Directory

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 the 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 members and other accounts have only read and execute permissions.

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

Step 3 – Configure SSH for SFTP

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 sshd.service

Step 4 – Test SFTP Connection

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

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

sftp sftpuser@sftp.tecadmin.net

Connecting to sftp.tecadmin.net...
sftpuser@sftp.tecadmin.net'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 sftpuser@sftp.tecadmin.net

sftpuser@sftp.tecadmin.net's password:
This service allows sftp connections only.
Connection to sftp.tecadmin.net closed.

The post How to Create SFTP User without Shell Access on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
https://tecadmin.net/create-sftp-only-user-centos/feed/ 2