• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
  • Skip to footer navigation

The Geek Diary

  • OS
    • Linux
    • CentOS/RHEL
    • Solaris
    • Oracle Linux
    • VCS
  • Interview Questions
  • Database
    • oracle
    • oracle 12c
    • ASM
    • mysql
    • MariaDB
  • DevOps
    • Docker
    • Shell Scripting
  • Big Data
    • Hadoop
    • Cloudera
    • Hortonworks HDP

CentOS / RHEL : How to set up chroot jail SFTP

by admin

chrooting sftp is a feature provided by the OpenSSH package in Linux. You can set up a chroot environment to avoid unwanted alterations of the system including uploads in unwanted locations when users are making use of sftp. When you chroot sftp for a specific user or all the users, the users can only access their home directories and subdirectories under it.

Method 1 (by openssh natively)

Starting from openssh-5.x version, sftp could chroot to specific directory. The following steps could implement the native openssh chroot for sftp.

1. Create the jail directory.

# mkdir /chroot/home

2. Mount it to /home as follows:

# mount -o bind /home /chroot/home

3. Edit /etc/ssh/sshd_config as follows:

# vi /etc/ssh/sshd_config
ChrootDirectory /chroot
Subsystem sftp internal-sftp

4. restart the sshd service:

# service sshd restart
Note: Please ensure the jail directory should be root owned and could not writable by any other user or group.

Method 2 (by using pam_chroot)

1. Add chroot into /etc/pam.d/sshd file:

# vi /etc/pam.d/sshd
session required pam_chroot.so

2. Modify /etc/security/chroot.conf to include the chroot directory.

# vi /etc/security/chroot.conf
user /chroot_dir

3. Modify /etc/ssh/ssh_config

# vi /etc/ssh/ssh_config
Subsystem sftp /usr/libexec/openssh/sftp-server

4. Restart sshd to apply new configuration:

# service sshd restart

Filed Under: Linux

Some more articles you might also be interested in …

  1. How to Disable IPv6 in CentOS/RHEL 8
  2. a2enconf: command not found
  3. How to Create a tmpfs Filesystem in CentOS/RHEL
  4. Understanding the rc Scripts in Linux
  5. How to view file size/details from ls command in Unix
  6. fail2ban-client: command not found
  7. Choosing SSSD or Winbind & Samba for Active Directory Integration in CentOS/RHEL
  8. physlock: command not found
  9. ln: command not found
  10. How to Create Yum Repository For System Packages Installation in CentOS/RHEL

You May Also Like

Primary Sidebar

Recent Posts

  • pw-cat Command Examples in Linux
  • pvs: command not found
  • pulseaudio: command not found
  • pulseaudio Command Examples in Linux

© 2023 · The Geek Diary

  • Archives
  • Contact Us
  • Copyright