Allow SFTP but disallow SSH?
Solution 1:
Starting with version 4.9 OpenSSH (not available in centos 5.x but ChrootDirectory feature was backported) has an internal-sftp
subsystem:
Subsystem sftp internal-sftp
And then block other uses:
Match group sftponly
ChrootDirectory /upload/%u
X11Forwarding no
AllowTcpForwarding no
AllowAgentForwarding no
ForceCommand internal-sftp
Add your users to the sftponly
group. The chroot directory must be owned by root, and cannot be group-writeable, so create a subdirectory for each user, e.g. uploads
or home/$username
that's owned by the appropriate user (if you match their home directory, it will be the default working directory when connecting). I'd also set /bin/false
as the user's shell.
As an example, users can then upload single files with:
sftp username@hostname <<< 'put filename.ext uploads/'
(scp will hopefully soon be modified to use sftp so this will become easier)
Solution 2:
There is a shell scponly what does this. It can chroot too.