Tutorial

How To Install and Configure scponly on CentOS 7

How To Install and Configure scponly on CentOS 7

Introduction

scponly is a secure alternative to anonymous FTP. It gives the administrator the ability to setup a secure user account with restricted remote file access and without access to an interactive shell.

Why Use scponly Instead of Normal SSH? With scponly you are giving the user remote access to download and upload specific files. They will not have an interactive shell, meaning they can’t execute commands. The user can only access the server via scp, sftp, or clients that support these protocols. From a security perspective, this lowers your attack surface by limiting unneeded access to an interactive shell on a server.

Prerequisites

For this tutorial, you will need a fresh CentOS 6 or 7 Droplet.

All the commands in this tutorial should be run as a non-root user. If root access is required for the command, it will be preceded by sudo. If you don’t already have that set up, follow this tutorial: Initial Server Setup on CentOS 6 or Initial Server Setup for CentOS 7.

Step 1 — Install Packages

scponly is available in some third party repositories, but these builds of scponly are outdated and are missing some of the features we will be adding when we build scponly from source.

To build scponly from source you will need to install the following 5 packages:

  • wget (To download files via the command line)
  • gcc (To compile scponly from source)
  • man (To read man pages)
  • rsync (To provide advanced file copying)
  • openssh-client-tools (To provide various ssh tools)

We will use yum to install the prerequisite packages needed to build scponly. During the yum install we will pass the required package names as well as -y which automatically answers yes to any prompts.

Install wget, gcc, man, rsync, and openssh-clients using the yum install command:

  1. sudo yum install wget gcc man rsync openssh-clients -y

Step 2 — Download and Extract scponly

In this section we will be downloading the latest build of scponly from sourceforge using wget and extracting the files using tar.

Before downloading scponly, change to the /opt directory. This directory is usually designated for optional software.

  1. cd /opt

As of this article the latest snapshot of scponly is 2011.05.26. You can check the Sourceforge page for a later release and adjust the wget command accordingly.

Download the scponly source using wget:

sudo wget http://sourceforge.net/projects/scponly/files/scponly-snapshots/scponly-20110526.tgz

Extract the scponly source code:

  1. sudo tar -zxvf scponly-20110526.tgz

Step 3 — Build and Install scponly

In this section we will use 3 main commands to build scponly: configure, make, and make install. These are the 3 commands most often used when you are downloading and installing software from source code.

Change to the directory that contains the scponly source code you just uncompressed:

  1. cd /opt/scponly-20110526

First, run the configure command to build a makefile with all the features you want enabled or disabled when building from source:

  1. sudo ./configure --enable-chrooted-binary --enable-winscp-compat --enable-rsync-compat --enable-scp-compat --with-sftp-server=/usr/libexec/openssh/sftp-server

The following options were used:

  • --enable-chrooted-binary: Installs chrooted binary scponlyc
  • --enable-winscp-compat: Enables compatibility with WinSCP, a Windows scp/sftp client
  • --enable-rsync-compat: Enable compatibility with rsync, a very versatile file copying utility
  • --enable-scp-compat: Enables compatibility with the UNIX style scp commands

Next we will build scponly with the make command. The make command take all your options that you passed using the configure command and builds it into the binaries that will be installed and run on the OS.

  1. sudo make

Next we will install the binaries with make install:

  1. sudo make install

Finally add the scponly shells to the /etc/shells file:

  1. sudo /bin/su -c "echo "/usr/local/bin/scponly" >> /etc/shells"

The /etc/shells file tells the operating system which shells are available to the users. So we are telling the operating system that we added a new shell to the system called scponly and that the binary is located at /usr/local/bin/scponly.

Step 4 — Create scponly Group

Now we will create a group called scponly so we can easily manage all the users who will be accessing the server with scponly.

  1. sudo groupadd scponly

Step 5 — Create an Upload Directory and Set Proper Permissions

In this section we will create a centralized upload directory for the scponly group. This allows you control over where and how much data can be uploaded to the server.

Create a directory named /pub/upload this will be a directory dedicated to uploads:

  1. sudo mkdir -p /pub/upload

Change the group ownership of the /pub/upload directory to scponly:

  1. sudo chown root:scponly /pub/upload

The next step is setting up permissions on the /pub/upload directory. By setting the permissions on this directory to 770 we are giving access to only the root users and members of the scponly group.

Change permissions on the /pub/upload directory to read, write, and execute for the owner and group and remove all permissions for others:

  1. sudo chmod 770 /pub/upload

Step 6 — Create a User Account with scponly Shell

Now we are going to setup a test user account to verify our scponly configuration.

Create a user named testuser1 and specify scponly as an alternative group and /usr/local/bin/scponly as the shell:

sudo useradd -m -d /home/testuser1 -s "/usr/local/bin/scponly" -c "testuser1" -G scponly testuser1

Note: Next is a very important step. The user’s home directory should not be writable because they could modify certain SSH parameters and possibly subvert the scponly shell.

Change permissions on the testuser1 home directory to read and execute only for the owner:

  1. sudo chmod 500 /home/testuser1

Finally, set a password for the testuser1 user:

  1. sudo passwd testuser1

Step 7 — Verify User Does Not Have Access to Interactive Shell

Now we will test the scponly shell access and verify that it works as expected.

Let’s verify that the testuser1 account does not have access to a terminal.

Try to log into the server as testuser1:

  1. su - testuser1

Your terminal will hang since you do not have access to an interactive shell. Press CTRL+C to exit the scponly shell.

You can also test access from your local machine:

  1. ssh testuser1@your_server_ip

Again, your terminal will hang because testuser1 is not allowed shell access. Press CTRL+C to exit the scponly shell.

Step 8 — Test Users Ability to Download Files

In this section we will be connecting via sftp from your local machine to your DigitalOcean Droplet to verify that the testuser1 account can download files.

First create a 100 Megabyte file using fallocate:

  1. sudo fallocate -l 100m /home/testuser1/testfile.img

Change ownership of the testfile.img file to testuser1:

  1. sudo chown testuser1:testuser1 /home/testuser1/testfile.img

On your local system change directory to /tmp:

  1. cd /tmp

Next sftp to your DigitalOcean server:

  1. sftp testuser1@your_server_ip

You may be prompted to save the ssh key as you enter the password.

Once logged in issue ls -l at the sftp> prompt:

  1. ls -l

Download the file using the get command:

  1. get testfile.img

Once the file is finished downloading type quit to exit:

  1. quit

Back on your local machine, verify that the file was downloaded successfully:

  1. ls -l testfile.img

Step 9 — Test Users Ability to Upload Files

In this section we will be testing the ability of the testuser1 account to upload files to the server using sftp.

Note: In this section we will be restricting access to the /pub/upload directory. This is not required but is an added security benefit for multiple reasons such as managing quotas or disk usage and easily monitoring all uploads in a central location.

On your local system create an 100 megabyte file called uploadfile.img using fallocate:

  1. fallocate -l 100m /home/testuser1/uploadfile.img

From your local system connect to your DigitalOcean Droplet.

  1. sftp testuser1@your_server_ip

Next upload the uploadfile.img to /pub/upload from the sftp prompt:

  1. put uploadfile.img /pub/upload/

Verify the file was successfully uploaded by issuing the following command at the sftp prompt:

  1. ls -ltr /pub/upload

The results should similar to:

-rw-r--r--    1 testuser1 testuser1 104857600 Jun  5 07:46 uploadfile.img

Finally type quit at the sftp prompt:

  1. quit

Conclusion

scponly should be in every admin’s toolbox. It can be used as a secure alternative to anonymous FTP or as a way of giving authenticated users the ability to download and upload files without having an interactive shell. The logging of scponly occurs in the standard ssh log file /var/log/secure. As always read the man pages and keep your system updated.

For more information about scponly, go to the scponly GitHub page.

Thanks for learning with the DigitalOcean Community. Check out our offerings for compute, storage, networking, and managed databases.

Learn more about our products

About the authors

Default avatar
Tammy Fox

editor


Still looking for an answer?

Ask a questionSearch for more help

Was this helpful?
 
1 Comments


This textbox defaults to using Markdown to format your answer.

You can type !ref in this text area to quickly search our full set of tutorials, documentation & marketplace offerings and insert the link!

As far as I know scponly can be found in the epel-release repo, and can be installed pretty simple using yum.

Try DigitalOcean for free

Click below to sign up and get $200 of credit to try our products over 60 days!

Sign up

Join the Tech Talk
Success! Thank you! Please check your email for further details.

Please complete your information!

Become a contributor for community

Get paid to write technical tutorials and select a tech-focused charity to receive a matching donation.

DigitalOcean Documentation

Full documentation for every DigitalOcean product.

Resources for startups and SMBs

The Wave has everything you need to know about building a business, from raising funding to marketing your product.

Get our newsletter

Stay up to date by signing up for DigitalOcean’s Infrastructure as a Newsletter.

New accounts only. By submitting your email you agree to our Privacy Policy

The developer cloud

Scale up as you grow — whether you're running one virtual machine or ten thousand.

Get started for free

Sign up and get $200 in credit for your first 60 days with DigitalOcean.*

*This promotional offer applies to new accounts only.