I'm starting a very little hosting company for a few friends and little clients, nothing big.
I want to give my "clients" the right to manage their files on the server. I hate FTP as it is not secure and it's in my opinion obsolete.
So I'd like to allow my users to connect through SFTP but not allow them to connect through SSH. (I know, I know, SFTP is using SSH). But I was just wondering, is it possible?
So I wouldn't have to install a FTP service on the server and everything would be awesome!
Starting with version 4.9 OpenSSH (not available in centos 5.x but ChrootDirectory feature was backported) has an
internal-sftp
subsystem:And then block other uses:
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
orhome/$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:
(scp will hopefully soon be modified to use sftp so this will become easier)
There is a shell scponly what does this. It can chroot too.
Checkout rssh which is a fake shell that allows sftp but denies ssh
More about RSSH
http://www.pizzashack.org/rssh/
RPMs
http://pkgs.repoforge.org/rssh/
You can configure rssh to allow / deny different behaviours like sft, scp etc.
I use the method of specifying the user shell as /bin/false as mentioned. However, you must ensure that /bin/shell is in /etc/shells. Then it works ssh=no ftp=ok.
I also use vsftpd and add this
chroot_local_user=YES to /etc/vsftpd/vsftpd.conf so that ftp-ers can't see date other then their own.
Advantage to these simple changes are no annoying config to ssh config for each user.
You can modify /etc/passwd and give that user a fake shell so that he can not use ssh.
Don't forget to find the line
UsePAM yes
and comment it:Without disabling this, your SSH server would crash on reloading/restarting. Since you do not need fancy functions of PAM, this is fine.
Configuring ssh to enable only sftp for some selected users is a good idea and it works properly, provided that you you install either
scponly
orrssh
.rssh
works fine, unless you need to configure jail, in this case try to follow instruction provided by CHROOT manuals is crazy, leading to "copy" large parts of system executables and library just below "each user jail", includingrssh
shell itself. It is a space-wasting method.scponly
needs a deep understanding in configuration leading to ever-present problem of login rejection in case of jail setup.The straightforward way to allow "ftp" functionalities with jail properly working, SSL/TLS support for secure transactions and login is to use an "old-but-working" VSFTPD, which installs quickly and cleanly and offers all configurability as needed and, last but not least: it works!
Maurizio.
This is the way i set up SFTP and disallowing SSH.
please do the following:
First create sftp user and group sftp
Create separate directory as root for the SFTP files:
sudo mkdir -p /home/sftpdir
Have a tested sshd_config file that allows SSH over port 22 but also SFTP on random port for security reasons
finally Test and you should not be able to connect.
A template to use SFTP client with a SSH key and basic verbosity: