Configuring chroot with SFTP

  • 7025265
  • 31-Aug-2021
  • 31-Aug-2021

Environment

Open Enterprise Server 2018 (OES 2018) Linux Support Pack 3
Open Enterprise Server 2018 (OES 2018) Linux Support Pack 2
Open Enterprise Server 2018 (OES 2018) Linux Support Pack 1
Open Enterprise Server 2018 (OES 2018) Linux

Situation

Configuring chroot with SFTP

Resolution

1)  LUM-enable the user in iManager:  It is recommended to create a lum group specifically for sftp chroot users, such as sftpusers.

2)  Set home directory:  Modify the user object and set the home directory on the Linux Profile tab (ie. /media/nss/VOL1/users/username).  Then run "namconfig cache_refresh".  You can use "namuserlist <username>" to verify the home directory.

3)  Assign NSS rights:  Add rights as needed to the home directory for the user

4)  Set root as owner:  All directories in the path to the chroot directory need to be owned by root.  This would include /media, /media/nss, /media/nss/VOL1, /media/nss/VOL1/users, and /media/nss/VOL1/users/username.  For each of these directories, run chown root:root <directory>.

5)  Set posix permissions:  All directories in the path to the chroot directory must not have posix write set for group and other.  For the linux directories in the path, such as /media and /media/nss, this is set with chmod 755 <directory>.  This is the default for these directories, but will need to be set back if it was changed for any reason.  For the NSS directories in the path, this is set with "nss /posixpermissionmask=0755".  Run this at the commandline to set it immediately.  Add /posixpermissionmask=0755 to /etc/opt/novell/nss/nssstart.cfg to make it persistent across reboots.

6)  LUM-enable SSH:  Run "yast2 novell-lum" and select sshd on the second screen and then select Next to complete the config.

7)  Add chroot setting:  In /etc/ssh/sshd_config add a section at the bottom to match the group and set the ChrootDirectory to the home directory, such as:

Match group sftpusers
        ChrootDirectory %h
        X11Forwarding no
        AllowTcpForwarding no
        PermitTTY no
        ForceCommand internal-sftp

8)  Restart sshd:  Run "systemctl restart sshd" to restart the service and enable the new config.