How to Set Up an SFTP Server on Linux

How to Set Up an Sftp Server on Linux

How to Set Up an SFTP Server on Linux

Home » News » How to Set Up an SFTP Server on Linux
Table of Contents

Any Linux server distribution is a really highly effective server that performs above and past what your online business would possibly want. No matter activity you throw on the server, it will likely be prepared. And, if it isn’t prepared out of the field, you can also make it so.

In the event you aren’t certain about SFTP, it’s the FTP service constructed into Safe Shell (SSH), which permits customers to securely push and pull recordsdata to and from the server, utilizing SSH.

I’m going to stroll you thru the method of establishing an SFTP server. I’ll show by making a single person that’s restricted to solely SFTP logins. As soon as you know the way to do that, you possibly can create as many customers as you want. This course of will work on any Linux distribution.

Let’s make it work.

SEE: Troubleshooting Linux: An Admin’s Information (roosho Premium)

What you’ll want

You’ll want entry to an account with admin rights. When you’ve procured that entry, it’s time to make this work.

SFTP Listing

The very first thing we should do is create a listing that can home our FTP information. Open up a terminal window, su to the basis person (sort su after which, when prompted, sort the basis person password), after which situation the next two instructions:

mkdir -p /information
chmod 701 /information

SEE: The way to Add an SSH Fingerprint to Your known_hosts File in Linux (roosho)

Create the SFTP group and person

Now we’re going to create a particular group for SFTP customers. That is performed with the next command:

groupadd sftp_users

Now we’re going to create a particular person that doesn’t have common login privileges, however does belong to our newly created sftp_users group. What you name that person is as much as you. The command for that is:

useradd -g sftp_users -d /add -s /sbin/nologin USERNAME

The place USERNAME is the identify of the person.

Subsequent, give the brand new person a password. This password would be the password the brand new customers use to log in with the sftp command. To arrange the password, situation the command:

passwd USERNAME

The place USERNAME is the identify of the person created above.

SEE: The way to Begin, Cease, and Restart Companies in Linux (roosho)

Create the brand new person SFTP listing

Now we’re going to create an add listing, particular to the brand new person, after which give the listing the right permissions. That is dealt with with the next instructions:

mkdir -p /information/USERNAME/add
chown -R root:sftp_users /information/USERNAME
chown -R USERNAME:sftp_users /information/USERNAME/add

The place USERNAME is the identify of the brand new person you created above.

Configure sshd

Open up the SSH daemon configuration file with the command:

nano /and so on/ssh/sshd_config

On the backside of that file, add the next:

Match Group sftp_users
ChrootDirectory /information/%u
ForceCommand internal-sftp

Save and shut that file. Restart SSH with the command:

systemctl restart sshd

SEE: 5 Finest Linux CentOS Alternative Choices & Options (roosho)

Logging in

You’re all set to log in. From one other machine in your community that has SSH put in, open up a terminal window and situation the command:

sftp USERNAME@SERVER_IP

The place USERNAME is the identify of our new person and SERVER_IP is the IP tackle of our SFTP server. You’ll be prompted for USERNAME’s password. When you efficiently authenticate, you’ll be greeted with the sftp immediate. Kind pwd to examine the working path and you must see /add as depicted within the picture beneath.

after you might have efficiently accomplished authentication you will notice the sftp immediate picture jack wallen

A easy resolution

That’s all there may be to establishing an SFTP server on Linux. For any firm trying to supply employees and purchasers a easy, safe technique of importing and downloading recordsdata, this can be a not solely an ideal resolution but additionally very finances pleasant one. Get your SFTP server up and working with zero value and nil headache.

This text was initially printed in September 2019. It was up to date by Antony Peyton in January 2025.

author avatar
roosho Senior Engineer (Technical Services)
I am Rakib Raihan RooSho, Jack of all IT Trades. You got it right. Good for nothing. I try a lot of things and fail more than that. That's how I learn. Whenever I succeed, I note that in my cookbook. Eventually, that became my blog. 
share this article.

Enjoying my articles?

Sign up to get new content delivered straight to your inbox.

Please enable JavaScript in your browser to complete this form.
Name