Skip to content

Set Up SFTP with Chroot on Ubuntu 24.04

Richard
Written by
Richard
Feb 26, 2025 Updated Mar 20, 2026 2 min read
Set Up SFTP with Chroot on Ubuntu 24.04

You set up SFTP with chroot on Ubuntu 24.04 to securely restrict user file access to specific directories.

SFTP (SSH File Transfer Protocol) provides a secure way to transfer files using SSH, while chroot creates a confined virtual filesystem environment.

This configuration limits users to their designated home directory, preventing them from browsing outside it when they log in via SFTP.

For instance, you can grant a client access only to their project files without exposing your server’s entire file system.

⚡ 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

Creating a restricted group is the first step to setting up SFTP chroot on Ubuntu 24.04, which helps keep your users’ access limited to only what they need.

Run the command below to create a new group.

🐧Bash / Shell
sudo groupadd chgroup

Next, run the command below and put a user in the chgroup created above.

🐧Bash / Shell
sudo usermod -aG chgroup username

Replace username in the command above with the account’s actual username.

Configure SSH

Next, you’ll need to configure SSH to enable SFTP chroot on Ubuntu 24.04 by editing the main SSH settings file.

🐧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 the file and then exit.

Restart SSH by running the command below.

🐧Bash / Shell
sudo  systemctl restart ssh

Test SSH and sFTP

After making the changes, it’s important to test your SFTP chroot setup on Ubuntu 24.04 to make sure it’s working correctly.

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

SFTP will succeed.

💻Code
sftp richard@srv1.example.com's password:
Connected to srv1.example.com.
sftp>

You’re all set!

Conclusion:

Setting up a chroot restricted SFTP account on Ubuntu 24.04 enhances security by isolating user access to specific directories. Here are the key takeaways:

  • 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.

Follow these steps to create a secure file transfer environment that’s still accessible for users.

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.

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

Leave a Comment

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

Exit mobile version