Easy SFTP and chroot SFTP with Scponly
Posted by Martin Perron on Sep 28, 2007 in HowTo - Linux • 6 commentsHowto: Easy SFTP and chroot SFTP with Scponly
I was getting some problems to get scponly installed. I’ve searched through the forum, but didn’t found any solution. Now I got it working, so I’m posting how I got Scponly installed and working.
Scponly for transferring files securely with ssh, but the user doesn’t have a shell, so he only can transfer files. He cannot execute anything in the server.
There are 2 shells, one normal (scponly), that allows users to transfer files and see all the system files, but can’t execute anything. The other one is scponlyc, the chroot version (the user is locked inside his home folder). Now here we go.
Install the scponly package in the server machine:
Code:
sudo apt-get install scponly
Normal SFTP
Change the shell of the user:
Code:
sudo chsh -s /usr/bin/scponly username
Test it from the remote machine:
Code:
sftp username@server
Painless
Chroot SFTP:
Reconfigure the scponly package so that scponlyc (the chroot version) is activated:
Code:
sudo dpkg-reconfigure -plow scponly
Answer “Yes”. Now setup the chroot scponly user using the setup_chroot script included to do it. It can’t be an existing user, and don’t create him with adduser. He will be created by the setup_chroot script:
Code:
cd /usr/share/doc/scponly/setup_chroot sudo gunzip setup_chroot.sh.gz sudo chmod +x setup_chroot.sh sudo ./setup_chroot.sh
To make this simpler, lets accept the default answers (scponly for username and home folder). At the end, create the password of scponly user.
Scponlyc has a “bug” and don’t work out of the box (https://lists.ccs.neu.edu/pipermail/…er/001692.html). The message is about FreeBSD, but it happens in Linux/Ubuntu too, at least with me. You have to create /dev/null in scponly chroot home folder. Thanks to revertex, the right way to do this is:
Code:
sudo -i cd /home/scponly mkdir /home/scponly/dev mknod -m 666 /home/scponly/dev/null c 1 3 exit
Now test it from the remote computer:
Code:
sftp scponly@server
If you login, it worked. You only can upload files to the “incoming” folder. You can’t leave scponly chroot home, and you cannot execute anything from the server system.
This was suggested by revertex:
To provide access to files that are outside the scponly homedir root jail, bind mount option should be handy.
As example, supose you have a dir /mnt/stuff and want to provide access to a chrooted scponly user.
Code:
Code:
mkdir /home/scponly/stuff mount -o bind /mnt/stuff /home/scponly/stuff
and to make this permanent, edit your /etc/fstab and add something like
Code:
Code:
/mnt/stuff /home/scponly/stuff none rw,bind 0 0
change rw,bind to ro,bind to read only access.
Tested in Ubuntu Feisty 7.04. I think it works on other versions with no or few changes.
I Hope this works for you to.
__________________
Anything that can happen, will happen if…
Last edited by epimeteo : June 8th, 2007 at 09:53 AM. Reason: revertex suggestion for binding dir from outside chroot dir
| epimeteo |
| View Public Profile |
| Send a private message to epimeteo |
| Visit epimeteo’s homepage! |
| Find all posts by epimeteo |
|
#2 |
|||
|
|
|||
|
Re: Howto: Easy SFTP and chroot SFTP with Scponly Very nice tutorial, pretty clear and well writen, surelly deserves a place in ubuntu wiki. i was close, but dunno why this do not worked
Code: mkdir /home/scponly/dev mknod -m 666 /home/scponly/dev/null c 1 3 __________________
Last edited by revertex : June 2nd, 2007 at 01:14 AM. |
| revertex |
| View Public Profile |
| Send a private message to revertex |
| Find all posts by revertex |
|
#3 |
||||
|
|
||||
|
Re: Howto: Easy SFTP and chroot SFTP with Scponly __________________ |

Best written chroot-your-clumsy-users tutorial ever!
Thanks, helped me a lot. I just need scp-login for my users, why make a complete debootstrap?.. This was exactly what I wanted and it works like a charm.
Emm.. Do you appreciate my grey competence I have a good fresh joke for you! What did one cloned sheep say to the other? I am ewe.
Thanks a lot.
It was very helpful for me.
I briefly translated this article in korean (and also with link to your post)
I also think this will help many korean people. We owe you
The posts are(I maintain two blogs)
http://rommance.net/tc/entry/easy-sftp-and-chroot-sftp-with-scponly (also accesible to http://rommance.net/tc/354)
http://rommance.net/blog/?p=661
The tutorial was written by epimeteo on http://ubuntuforums.org/showthread.php?t=451510
Thanks to him!
Ah ha.
That was original. I see.
Thanks
[...] http://geekzine.org/2007/09/28/easy-sftp-and-chroot-sftp-with-scponly/ [...]