Usare gli account di linux per fare upload limitati a un'area ben definita e impedire che l'account possa scrivere o leggere in altre zone e lanciare comandi.
Riferimento d'installazione
Installazione ubuntu server 10.04 LTS 64 bit
Ho provato tutto su ubuntu server 10.04 LTS 64 bit, vedi sotto per la 12.04
apt-get install scponly
In fase di installazione chiederà se attivare il bit suid per chroot le guide dicono di rispondere si. Se si sbaglia successivamente si può lanciare
dpkg-reconfigure -plow scponly
e cambiare l'opzione.
Dopo questo apparirà in /etc/shells la shell di scponly se la mettiamo come shell predefinita per un account otteniamo che si possa solo usare sftp e non si possano dare più comandi. Il problema è che si può ancora navigare in giro per tutto il sistema dove si hanno i permessi.
Per rinchiudere l'accesso a una directory
cd /usr/share/doc/scponly/setup_chroot
sudo gunzip setup_chroot.sh.gz
sudo chmod +x setup_chroot.sh
sudo ./setup_chroot.sh
Lui chiede il nome utente si può anche lasciare quello di default scponly. Dopo creerà in /home/scponly/ tutta una struttura in cui c'è anche la cartella incoming dove l'utente può depositare quello che gli serve.
Risolviamo il bug
La sorgente di questa sezione è questa
C'è un bug a partire da ubuntu 10 che nella versione 8 non c'era e che persiste anche nella 11 a sentire alcuni forum, che impedisce la connessione dopo aver fatto le operazioni di creazione utente tramite lo script sopra.
Il bug si risolve copiando per ogni utente una libreria e creando un link simbolico.
sudo cp /lib/libnss_files-2.12.1.so $chroot/lib
cd $chroot/lib
sudo ln -s libnss_files-2.12.1.so libnss_files.so.2
Installazione on ubuntu 12.04 WORKS
It's possible to do without install the packet scponly
The source for this section is this https://wiki.archlinux.org/index.php/SFTP-chroot is not so much clear so I try to summarize.
create a group
addgroup sftponly
in /etc/ssh/sshd_config, modify the Subsystem line for sftp in this way
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
#add at the end those lines
Match Group sftponly,!othergroups
ChrootDirectory /home/%u
X11Forwarding no
AllowTcpForwarding no
ForceCommand internal-sftp
In the guide there is either the version for single user
othergourps is a group in which the access is permitted
/home/%u indicate all the user home
For the home is not necessary but if we choose another directory we must change the ownership to root
chown root /home
Restart sshd
/etc/rc.d/sshd restart
When create an user he must stay in the group choose before
adduser $1 --ingroup sftponly
chown root /home/$1
chmod 755 /home/$1
Advance options http://en.wikibooks.org/wiki/OpenSSH/Cookbook/SFTP
Umask
Starting with OpenSSH 5.4 (ubuntu 14.04 has OpenSSH_6.6.1p1 ), sftp-server(8) can set a umask to override the default one set by the user’s account. The in-process SFTP server, internal-sftp, accepts the same options as the external SFTP subsystem.
Subsystem sftp internal-sftp -u 0022
Install on Red Hat
on version 5.9 it do not work beacuse the version of ssh is 4.3 , It's necessary update to 5.3 or major http://www.usr-local-share.com/?p=564
Installazione ubuntu 12.04 NON FUNZIONANTE
Qui non sono riuscito ad installare bene la cosa.
Il pacchetto deb si recupera da questa sorgente http://security.ubuntu.com/ubuntu/pool/universe/s/scponly/
wget http://security.ubuntu.com/ubuntu/pool/universe/s/scponly/scponly-full_4.8-4.1_amd64.deb
sudo su
dpkg -i scponly-full_4.8-4.1_amd64.deb
cd /usr/share/doc/scponly-full/setup_chroot/
gunzip setup_chroot.sh.gz
chmod +x setup_chroot.sh
./setup_chroot.sh
lo script non mi ha dato esito completamente positivo e mi dava sempre l'errore anche operando le modifiche sulle librerie che diceva la guida http://slug.blog.aeminium.org/2011/02/20/scponly-debian-64bit-unknown-user/
In passwd c'è questa situazione
scponly:x:1003:1003::/home/scponly:/usr/sbin/scponlyc
user:x:1004:1004:,,,:/home/user:/usr/bin/scponly
la prima riga la creava lui ma di da alla connessione un
unknown user 1003
con la seconda creata da me non riesce a fare login perchè non ha la shell però può fare scp in qualunque parte del file system dove ha i permessi indovinando i path e i nomi dei file
FTP server
Su centos ho provato un ottimo servizio vsftp tutte le info a questo link
http://nolabnoparty.com/installare-un-server-ftp-con-vsftpd-su-centos/