Services Réseaux
FreeBSD - Chroot SFTP secure file transfer program
But: donner accès à un utilisateur ne le permettant pas de sortir de son home directory !
Important : le serveur sftp est lancé d'office avec ssh, l’exécutable se trouve /usr/bin/sftp
vim /etc/ssh/sshd_config LogLevel VERBOSE
Vérifier dans le /var/log/auth.log
vim /etc/ssh/sshd_config Match group chroot #ChrootDirectory /home/%u/ # c'est ici que l'on va signifier le chroot pour le sftp ChrootDirectory /nfs4/vftp/home/%u/ X11Forwarding no AllowTcpForwarding no ForceCommand internal-sftp
service sshd restart Performing sanity check on sshd configuration. Stopping sshd. Waiting for PIDS: 19610, 19610. Performing sanity check on sshd configuration. Starting sshd.
pw addgroup chroot
mkdir -p /nfs4/vftp/home/
drwxr-xr-x 9 root wheel 1.0K Apr 30 21:00 nfs4 drwxr-xr-x 4 root wheel 512B May 4 11:47 vftp drwxr-xr-x 3 root wheel 512B May 4 17:10 home drwxr-xr-x 3 root chroot 512B May 4 17:13 nuxbsd
Attention : si les droits ne sont pas correctes on a une erreur de type
“: fatal: bad ownership or modes for chroot directory component ”/nfs4/vftp/home/“ que l'on peut visualiser avec la commande cat /var/log/auth.log
adduser Username: nuxbsd Full name: nuxbsd Uid (Leave empty for default): Login group [nuxbsd]: Login group is nuxbsd. Invite nuxbsd into other groups? []: chroot Login class [default]: Shell (sh csh tcsh bash rbash nologin) [sh]: nologin Home directory [/home/nuxbsd]: /nfs4/vftp/home/nuxbsd Home directory permissions (Leave empty for default): Use password-based authentication? [yes]: Use an empty password? (yes/no) [no]: Use a random password? (yes/no) [no]: Enter password: Enter password again: Lock out the account after creation? [no]: Username : nuxbsd Password : ***** Full Name : nuxbsd Uid : 1010 Class : Groups : nuxbsd chroot Home : /nfs4/vftp/home/nuxbsd Home Mode : Shell : /usr/sbin/nologin Locked : no OK? (yes/no): yes adduser: INFO: Successfully added (nuxbsd) to the user database. Add another user? (yes/no): no Goodbye!
chown -R root:chroot /nfs4/vftp/home/nuxbsd
Cela empêche l'utilisateur de supprimer ses propres fichiers et de ne plus pouvoir se connecter par la suite.
mkdir /nfs4/vftp/home/nuxbsd/data chown -R nuxbsd:chroot /nfs4/vftp/home/nuxbsd/data