Skip to content
Follow
Ubuntu Linux

Set Up SFTP with Chroot on Ubuntu 24.04

Richard
Written by
Richard
Feb 26, 2025 Updated Aug 13, 2026 2 min read
Set Up SFTP with Chroot on Ubuntu 24.04
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.

⚡ Quick Answer

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.

🐧Bash / Shell
sudo groupadd chgroup

Next, add an account to the new group.

🐧Bash / Shell
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.

🐧Bash / Shell
sudo nano /etc/ssh/sshd_config

Adjust the highlighted settings in the file.

💻Code
# 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.

💻Code
ssh richard@srv1.example.com's password:
This service allows sftp connections only.
Connection to srv1.example.com closed.

SFTP connections succeed.

💻Code
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?

Was this helpful?
Richard

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.

📚 Related Tutorials

How to Mount Linux File System on Windows 11 via WSL
Ubuntu Linux How to Mount Linux File System on Windows 11 via WSL
How to Change Screen Brightness in Ubuntu Linux
Ubuntu Linux How to Change Screen Brightness in Ubuntu Linux
Change Power Button Behavior in Ubuntu Linux
Ubuntu Linux Change Power Button Behavior in Ubuntu Linux
Speed Up File Transfers in Windows 11 with Robocopy
Windows Speed Up File Transfers in Windows 11 with Robocopy

No comments yet — be the first to share your thoughts!

Leave a Comment

Your email address will not be published. Required fields are marked *