Set Up SFTP with Chroot on Ubuntu 24.04
SFTP with chroot on Ubuntu 24.04 locks specific users inside a single folder so they cannot browse the rest of your server. A chroot jail acts as a secure sandbox that stops people from seeing system files they should not touch.
You need this setup when you want to give clients or co-workers safe access to upload project files without risking your main server data. This guide shows you step-by-step how to lock down accounts on Ubuntu 24.04 using built-in security tools.
Create a restricted group, add users to it, and then configure the SSH daemon’s `sshd_config` file to use `internal-sftp` and `ChrootDirectory` for that group. Restart the SSH service afterward.
Create restricted group
Begin the setup process by creating a dedicated group named ‘chgroup’. This group enforces access boundaries for assigned accounts. Commands like `groupadd chgroup` and `usermod -g chgroup username` build this structure.
Run the command below to create a new group.
sudo groupadd chgroup
Next, add an account to the new group.
sudo usermod -aG chgroup username
Substitute username in the command above with the actual account name.
Configure SSH
Next, open the primary SSH server configuration file at `/etc/ssh/sshd_config` using a text editor. Modifying this file applies the chroot rules globally for the designated group.
sudo nano /etc/ssh/sshd_config
Adjust the highlighted settings in the file.
# override default of no subsystems
# comment out the line below
#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp
# add the lines below
Match Group chgroup
X11Forwarding no
AllowTcpForwarding no
ChrootDirectory /home
ForceCommand internal-sftp
Save changes and close the editor.
Restart the SSH daemon to apply the new rules.
Test the connection to verify that the sandbox functions correctly. Attempt an SFTP login to confirm the restricted directory view prevents wandering into unauthorized areas. Verification ensures the configuration works before handing access over to real users.
ssh richard@srv1.example.com's password:
This service allows sftp connections only.
Connection to srv1.example.com closed.
SFTP connections succeed.
sftp richard@srv1.example.com's password:
Connected to srv1.example.com.
sftp>
The configuration process finishes here.
Conclusion:
Isolating users inside a chroot sandbox hardens server security. Review these key takeaways from the setup:
- Enhanced Security: Users are confined to their directory, minimizing the risk of unauthorized access to other users' files.
- Group Management: Creating a specific group for SFTP users simplifies the management of user permissions and access.
- SSH Configuration: Proper configuration in the SSH settings is crucial for implementing chroot restrictions effectively.
- Testing: Always test your configuration to ensure that SFTP works as intended without compromising security measures.
Locking down file transfers with a chroot jail protects sensitive host directories. Maintaining strict user boundaries keeps the Ubuntu 24.04 server secure against unauthorized file inspection.
Was this guide helpful?
About the Author
Richard
Tech Writer, IT Professional
Richard, a writer for Geek Rewind, is a tech enthusiast who loves breaking down complex IT topics into simple, easy-to-understand ideas. With years of hands-on experience in system administration and enterprise IT operations, he’s developed a knack for offering practical tips and solutions. Richard aims to make technology more accessible and actionable. He's deeply committed to the Geek Rewind community, always ready to answer questions and engage in discussions.
No comments yet — be the first to share your thoughts!