Set up a SFTP server using an available SSH connection
Contents
Install and setup your SSH
The key of this blog is to deal with the conflict between key-only SSH and password-enabled SFTP.
If you haven't had an available SSH access, set up one first. And we assume you like to disable password logon and use key access only. Otherwise, it would be pretty easy.
Create Unprivileged SFTP User Account
Create a group to assign SFTP user accounts to. Note that this is not necessary as the directories you will be assigning the user may already have specific group assigned to them.
|
|
Next, create a less privileged account for an SFTP user. Replace the username accordingly;
|
|
And set up its password via
|
|
If your like to create more groups and add the user to them,
|
|
or, change the default group
|
|
Restrict SFTP User Access to Directory with Chroot Jail
Open the SSH configuration file for editing;
|
|
Enable SSH in-process SFTP server by commenting (add # at the beginning) the following line:
|
|
and replacing it as follows;
|
|
Next, add the following configuration options after the line above;
|
|
⚠️ Warning: The folder
/var/sftp/
must be owned byroot
androot
group!
Allow SFTP user to connect via password
The key is to use Match
directive in /etc/ssh/sshd_config
, e.g.,
|
|
⚠️ Warning: You must append these lines at the end (this is important!) of your
sshd_config
.
Then you'll also have to restart the ssh process for this to take effect:
|
|
Done! Enjoy your SFTP via any FTP clients.
A quick test could be:
|
|
Author oracleyue
LastMod 2021-12-28