Categories

Category cover

Automation
43 posts

Category cover

Security
20 posts

Category cover

Notes
19 posts

Category cover

Personal Security
15 posts

Category cover

CISO
14 posts

Category cover

Infrastructure
12 posts

Category cover

Learning paths
9 posts

Category cover

OT/ICS
6 posts

Category cover

UNetLab
4 posts

Category cover

Books
3 posts

Category cover

Write-up
3 posts

Category cover

OSInt
2 posts

Category cover

My life
1 posts

Chrooted SFTP

Andrea Dainese
February 24, 2014
Post cover

OpenSSH allows SSH/SFTP users to connect to the whole system by default. In many cases this is not the expected behavior: users should be relegated to the home their home directory only.

Sometimes this is called “Chrooted SFTP”.

As we discussed before, SFTP users can see the whole system by default:

# sftp andrea@localhost
Connecting to localhost...
andrea@localhost's password:
sftp> pwd
Remote working directory: /home/andrea

Users can be confined to changing the SFTP backend:

# /etc/ssh/sshd_config
[...]
#Subsystem sftp /usr/libexec/openssh/sftp-server
Subsystem sftp internal-sftp
[...]

Users part of the webmaster group should only access the webserver directory; other users should be restricted to their home directory:

# /etc/ssh/sshd_config
[...]
Match User webmaster
 ChrootDirectory /var/www/html
 AllowTCPForwarding no
 X11Forwarding no
 ForceCommand internal-sftp
Match Group users
 ChrootDirectory /home
 AllowTCPForwarding no
 X11Forwarding no
 ForceCommand internal-sftp
[...]

Now users are restricted and cannot leave the configured directory:

andrea@localhost's password:
sftp> pwd
Remote working directory: /

Enabling a restricted SSH is more complicated: SSH needs many components like BASH, libraries, and so on. The reason is simple: if a user enters a confined environment, it cannot access components outside the confined environment. All required components must be copied to the path where users are “chrooted”.