I am not a security expert, so take it for what its worth.
OpenSSH has this ability built in, few people just seem to use the feature. Below is what works for me, but if you have a better way please share the uninformed.
- First create a new app inside of the SP control panel
- Now, decide what direcoty you want to put the users directory; either
<app_name>
or<app_name>/public
. This will keep trolls at bay.- NOTE: The entire path MUST be owned by
root
.
- NOTE: The entire path MUST be owned by
- Update your directory PATH to
root
:
sudo chown root:root /srv
sudo chown root:root /srv/users
sudo chown root:root /srv/users/serverpilot
sudo chown root:root /srv/users/serverpilot/apps
sudo chown root:root /srv/users/serverpilot/apps/<app_anme>
- 4. Create the new user account:
sudo adduser --home /srv/users/serverpilot/apps/<app_name> <new_sftp_user>
Follow the prompt and note that this will create a user and group with the name you supplied.
- 5. Create a new group that has only SFTP access (no SSH access)
sudo groupadd <new_sftp_group>
- 6. Add the new user to the new group and change ownership of their home directory to
root
sudo usermod -a -G <new_sftp_user> <new_sftp_user>
sudo usermod -a -G <new_sftp_group> <new_sftp_user>
sudo chown root:root /srv/users/serverpilot/apps/<app_name>
Now that the user is all setup and has the correct permission, we need to configure OpenSSH.
- 7. Configure the internal sftp server, by editing the
sshd_config
file
sudo vim /etc/ssh/sshd_config
If you don't use
vim
the replace with whatever editor - ie:nano
-
8. Search for
Subsystem
(I like to duplicate the line and comment out the original)-
Add the following:
# Subsystem sftp /usr/lib/openssh/sftp-server Subsystem sftp internal-sftp
-
-
9. Set up the
chroot
environment - (You should still have the file open)- add to the very BOTTOM of the
sshd_config
Match Group <new_sftp_group> ChrootDirectory %h X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
- It's important that
Match Group <new_sftp_group>
is the same group you created earlier.
- add to the very BOTTOM of the
-
10. Save and restart the ssh server
# restart SSH sudo service ssh restart
That's all there is to it.
So if you want to test. You'll need to use an FTP client that supports SFTP.
Also the user would be able to escalate and view and download everything down to the root which normally is not happening with a normal SP system user (except in 14.04 where the SP system user can get into the /etc/nginx-sp/vhost.d if he guess we're using ServerPilot).
Not good :(