Update - 2024
I have had crazy problems getting this thing set up, when I rebuild, for the following stupid reasons:
- Copying and pasting instructions which contained an error - a typo, basically - cost me a ton of time every time I tried to set this up!
I'd quickly scratched out some instructions, awhile back, which alternately said to add the group "sftpusers" and then continued with more
copy and paste stuff in which - instead of using the group name "sftpusers" - I'd left off the letter "s" and was using "sftpuser". Specfically, in an edit to the sshd_config file
I believe I was using "sftpuser" which, of course, was referring to a non-existant group and causing things to not work.
So, we're going to be using "sftpusers" - with the s. It was an idiotic mistake that came with copying and pasting an error.
- I had a variation on the following command but it would not work because
it would always say that the user id was involved in a process - use the following, this is big:
sudo usermod -aG sftpusers guy
The above adds user guy to the sftpusers group. Now, let's check and
make sure that guy is a member of this group - run the following from a terminal:
groupmems -g sftpusers -l
The Process Which Works
- sudo addgroup sftpusers
- sudo usermod -aG sftpusers guy
- mkdir /sftp
(chown root.root)
- mkdir /sftp/guy
(chown root.root)
- mkdir /sftp/guy/incoming
(chown guy.sftpusers)
Edit the bottom of the /etc/ssh/sshd_config file to look like this:
# override default of no subsystems
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
# tail /etc/ssh/sshd_config
Match Group sftpusers
ChrootDirectory /sftp/%u
ForceCommand internal-sftp
For archival purposes - shit which did not work
Below are the instructions I had, at one time, for editing the bottom of sshd_config. I had saved this, originally - which is significantly different than the above code which works.
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
# Example of overriding settings on a per-user basis
#Match User anoncvs
# X11Forwarding no
# AllowTcpForwarding no
# PermitTTY no
# ForceCommand cvs server
# tail /etc/ssh/sshd_config
Match group sftpuser
ChrootDirectory /home
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
While similar to the above noted command (which worked) for adding a pre-existing user to a group my old instructions suggested the following - which did not work.. saying something about
the user's ID being held by a process. So, this is close but no cigar.
sudo usermod -a -G sftpuser guy