# Chrooted SFTP-Only Access Configuration This guide describes how to set up a chrooted environment with SFTP-only access for users, using SSH keys. ## Prerequisites - A server running GNU/Linux - Root access to the server. - OpenSSH installed and running. ## Steps ### 1. Create a Chroot User ```bash useradd ``` ### 2. Create SFTP Group ```bash groupadd sftpusers ``` ### 3. Add the User to SFTP Group ```bash usermod -aG sftpusers ``` ### 4. Setup Chroot Directory Create a directory for SFTP users, ensuring proper ownership and permissions. ```bash mkdir -p /sftp/ chown root:root /sftp chmod 755 /sftp mkdir /sftp/ chown : /sftp/ chmod 700 /sftp/ ``` ### 5. Configure SSH for SFTP Access Modify `/etc/ssh/sshd_config` to use internal SFTP and set restrictions. 1. Update the `Subsystem` line: ```bash Subsystem sftp internal-sftp ``` 2. Add a `Match` block at the end: ```bash Match Group sftpusers ChrootDirectory /sftp/%u ForceCommand internal-sftp AllowTcpForwarding no X11Forwarding no ``` ### 6. Setup User's SSH Keys Create and configure SSH directories for the user: ```bash mkdir /home//.ssh touch /home//.ssh/authorized_keys chmod 700 /home//.ssh chmod 600 /home//.ssh/authorized_keys chown : /home//.ssh chown : /home//.ssh/authorized_keys ``` Copy the public SSH key to `/home//.ssh/authorized_keys`. ### 7. Restart SSH Service ```bash systemctl restart sshd ``` ## Verification - Attempt an SFTP connection to verify restricted access. - Ensure users cannot access the shell.