1

I followed this, to restrict user to a determinate directory and it works perfectly, but i need to chroot a user in a directory that is

/dir1/dir2/dir3/dir4

Suppose dir1 is owned by root, dir2 by www-data, dir3 by www-data and dir4 by root, and that i cannot change this state of things, nor i can use another software to achieve my purpose.

The sshd chrooting works for dir1, but not for dir4 even if it is owned by root, maybe for dir2 and dir3 are not.

How do i manage this?

2
  • Can you make a symbolic link in dir1 referring to dir4, chown it to root, then try again? Jul 3, 2015 at 10:29
  • did it, no fortune. After creating the link i referenced it like ChrootDirectory /var/www/foo but the user was not able to connect anymore. Jul 3, 2015 at 10:29

1 Answer 1

2

Sorry, the solution was in the last paragraph of the page, named 'Write access to chroot dir'

Quote: "As above, if a user is able to write to the chroot directory then it is possible for them to escalate their privileges to root and escape the chroot. One way around this is to give the user two home directories - one "real" home they can write to, and one SFTP home that is locked down to keep sshd happy and your system secure. By using mount --bind you can make the real home directory appear as a subdirectory inside the SFTP home directory, allowing them full access to their real home directory. This can also be used to achieve other goals. For example, a user's home directory can be locked down per the sshd chroot rules, and bind mounts used to provide users access to other directories:

  # mkdir /home/user/web
  # mount --bind /srv/web/example.com /home/user/web

Optional add an entry to /etc/fstab:

  # echo '/srv/web/example.com/ /home/user/web        none    bind' >> /etc/fstab

Now the user can log in with SFTP, they are chrooted to /home/user, but they see a folder called "web" they can access to manipulate files on a web site (assuming they have correct permissions in /srv/web/example.com."

1
  • Took me a day to find this, thank you!!! Dec 11, 2023 at 23:01

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .