SFTP MySecureShell

Setting up SFTP on a server.


Introduction

SFTP (Secure File Transfer Protocol) is typically implemented over SSH, port 22. This tool, MySecureShell, makes setting that up really easy. This tutorial will go over its installation and the basic configuration I use with it.

What This Tutorial Covers

What This Tutorial Covers
  1. SFTP.
  2. MySecureShell

What You Need For This Tutorial

What You Need For This Tutorial

Ubuntu



Install MySecureShell

Installing is as simple as running a single apt-get command.


apt-get install -y mysecureshell
      

Configuring MySecureShell

All configuration is done in a single file: /etc/ssh/sftp_config. The file explains all the configuration options you can use.

The one thing I typically change is the directory users see when they use SFTP. I change that directory from /home/$USER to $HOME. That way, I can set a user's home to something outside the home directory. The following sed command makes that change automatically and then reloads the sshd daemon so the change takes effect.


sed -i 's@/home/\$USER@$HOME@g' /etc/ssh/sftp_config
service sshd reload
      

Creating Users

In order to enable a user to use SFTP, you just have to set their default shell to mysecureshell. So create users using the following commands.


useradd -s /usr/bin/mysecureshell -d HOME-DIRECTORY -g GROUP USER
password USER
      

Final Checks

You can view which users have their shell set to mysecureshell using this command:


sftp-user list
      

Make sure your server allows ssh logins with password by setting the PasswordAuthentication option to yes in the file: /etc/ssh/sshd_config. You can do that automatically with the following sed command:


sed -i 's/.*PasswordAuthentication.*/PasswordAuthentication: yes/g' /etc/ssh/sshd_config
service sshd reload
      

Using SFTP

Now you just need to install an FTP client like Cyberduck or Filezilla on the computer you want to use to connect to your server. All you need to know when configuring the client is the info below. It's pretty typical except for the port. FTP doesn't usually use port 22, so you'll probably have to specify that somewhere as well as the fact that you want to use SFTP.


Done!

That's it. This program makes installing SFTP way easier than it used to be.