SFTP Jail

From QwikITedia

Jump to: navigation, search

Contents

Introduction

Create a Secure FTP server for your company or your own needs upon Ubuntu. Each group you want to exchange data with expects to have their own individual space (termed; an SFTP Jail) upon the SFTP server such that they alone can see it and they cannot see any other spaces(jails) you might have created for other business partners.

Assumptions

NOTE Before you begin

cd /

SFTP Server Installation

Install the openssh-server

Settings are stored in

  1. /etc/ssh, and
  2. /etc/ssh/sshd_config

Jailkit Installation

Get latest Jailkit release, courtesy of Olivier

# cd /tmp
# wget http://olivier.sessink.nl/jailkit/jailkit-2.x.tar.gz

After downloading Jailkit, compile and install it:

# tar -zxvf jailkit-2.x.tar.gz
# mkdir /ACME-jail
# cd /ACME-jail
# cp -Rf /tmp/jailkit-2.x/* .
# ./configure
# make
# make install

Setting The "Jail" Up

After you've installed it, it's time to set up the "root" directory (the directory to which the users will be jailed to).

# sudo chown root:root /ACME-jail

Creating the Proper Environment

The following lines will allow the logged in user to use whichever set of programs you want to allow:

# sudo jk_init -v /ACME-jail basicshell
# sudo jk_init -v /ACME-jail editors
# sudo jk_init -v /ACME-jail extendedshell
# sudo jk_init -v /ACME-jail scp
# sudo jk_init -v /ACME-jail ssh
# sudo jk_init -v /ACME-jail sftp

Add the jailer shell script to the jail

Place the "jk_lsh" script inside the jail so that you can jail user in next step</p>

sudo jk_init -v /ACME-jail jk_lsh

Creating and Jailing the User

$ sudo useradd -d /home/richard -m richard
$ sudo jk_jailuser -m -j /ACME-jail richard
sudo passwd richard
richard:x:1001:1001::/ACME-jail/./home/richard:/usr/sbin/j k_chrootsh


Setting Up the Home Directory

From the users perspective, logging in to this secured environment "/ACME-jail" will just show up as the "/" directory, so setting up a home directory is also needed:

$ sudo mkdir -p /ACME-jail/home/richard
$ sudo chown richard:richard /ACME-jail/home/richard

Passwords

edit the /ACME-jail/etc/passwd and /ACME-jail/etc/group files with and add these lines
(Note: The numbers mentioned are the user and groups id, which you can check by opening the /etc/passwd file and look for the appropriate user):

paste and save this:


paste and save this:

Profiles and Ownership


Check the configuration by "sftp'ing" your machine:

sftp>quit

If anything's gone wrong /var/log/auth.log will give you the needed details: tail /var/log/auth.log

Test & Check the logs

Personal tools
Namespaces
Variants
Actions
Richard Esmonde.com
Wiki Navigation
Toolbox