SCP and SFTP
The Secure copy (SCP) is a protocol to transfer files via a Secure Shell connection. The SSH file transfer protocol (SFTP) is a related protocol, also relying on a secure shell back-end. Both protocols allow secure file transfers, encrypting passwords and transferred data. The SFTP protocol, however, features additional capabilities like, for example, resuming broken transfers or remote file manipulation like deletion.
Secure file transfer protocol (SFTP)
Install and configure OpenSSH. Once running, SFTP is available by default.
Access files with the sftp program or SSHFS. Many standard FTP programs should work as well.
Secure file transfer protocol (SFTP) with a chroot jail
Sysadmins can jail a subset of users to a chroot jail usingthus restricting their access to a particular directory tree. This can be useful to simply share some files without granting full system access or shell access. Users with this type of setup may use SFTP programs such as to put/get files in the chroot jail.
Setup the filesystem
Create a jail directory:
# mkdir -p /var/lib/jail
Bind mount the live filesystem to be shared to this directory. In this example, /mnt/data/share is to be used. It is owned by root and has octal permissions of 755.
# mount -o bind /mnt/data/share /var/lib/jail
Create an unprivileged user
Create the share user and setup a good password:
# useradd -g sshusers -d /var/lib/jail foo # passwd foo
Add the following to the end of
/etc/ssh/sshd_config to enable the share and to enforce the restrictions:
... Match group sshusers ChrootDirectory %h X11Forwarding no AllowTcpForwarding no PasswordAuthentication yes ForceCommand internal-sftp
sshd.service to re-read the config file.
Test that in fact, the restrictions are enforced by attempting an ssh connection via the shell. The ssh sever should return a polite notice of the setup:
$ ssh firstname.lastname@example.org email@example.com's password: This service allows sftp connections only. Connection to someserver.com closed.
Secure copy protocol (SCP)
More features are available by installing additional packages, for exampleAUR or described below.
Scponly is a limited shell for allowing users scp/sftp access and only scp/sftp access. Additionally, one can setup scponly to chroot the user into a particular directory increasing the level of security.
For existing users, simply set the user's shell to scponly:
# usermod -s /usr/bin/scponly username
Adding a chroot jail
The package comes with a script to create a chroot. To use it:
# cd /usr/share/doc/scponly/
- Provide answers
- Check that
- Change the shell for selected user to
- sftp-server may require some libnss modules such as libnss_files. Copy them to chroot's