• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 933
  • Last Modified:

Chroot SFTP not workng in Ubuntu

Guys,

I'm facing a weird problem while trying to setup Chroot SFTP on ubuntu server. SSH is getting crashed whenever I am trying to setup Chroot SFTP. Logs are not showing any error. The only error in logs was related to LOCALE environment and I had fixed now. This error does not seem to be related to chroot. In short I'm clueless. I had tried the following steps.

1. Created new user for SFTP
2. Commented the existing "Subsystem sftp" and added the following.

Subsystem sftp internal-sftp

3. Added the following lines for user.

Match User sftpuser
    ChrootDirectory /home
    AllowTCPForwarding no
    X11Forwarding no
    ForceCommand internal-sftp

4, Set permissions for sftp directory to root.user
5. Restarted ssh and its down.

I had tried commenting the "UserPam" in ssh config as well. This is the same for ubuntu 11 and ubuntu 12. Can anyone share some ideas?

Regards,
Asv.
0
LinuxGuru
Asked:
LinuxGuru
  • 3
  • 2
2 Solutions
 
woolmilkporcCommented:
Run sshd this way, to find out which part of sshd_config it doesn't like:

sudo /usr/sbin/sshd -D

sshd will stay in the foreground, so you can watch its messages.

Are you aware that "ChrootDirectory" is always relative to the user's HOME?

So if the HOME directory is /home/users the chroot directory is "/home/users/home", and
thus all components of /home/users/home must be root owned directories that are not writable by any other user or group.
0
 
LinuxGuruLinux Server AdministratorAuthor Commented:
Hi,

Thanks.

Yes I'm aware that chroot is relative to users home directory.

I will try sudo /usr/sbin/sshd -D and let you know.

Thank you.
0
 
LinuxGuruLinux Server AdministratorAuthor Commented:
Hi,

Thanks man.

Just to let you know that I have fixed it by

/usr/sbin/sshd -D

UsePam was the culprit. I had to disable it and sftp is working fine as expected.

I had tried by changing UsePam yes and no earlier. But not sure it didnt work.

Also now one more question,

I had set chroot for a user. So I have the users file in some other partition say

Exact user home is /home/user

Some files at /var/files/user and this is owned by user. I have setup a symlink to /var/files/user under /home/user. Any way to make this symlink work when we use chroot in sftp ?

Thanks!
0
What Security Threats Are We Predicting for 2018?

Cryptocurrency, IoT botnets, MFA, and more! Hackers are already planning their next big attacks for 2018. Learn what you might face, and how to defend against it with our 2018 security predictions.

 
woolmilkporcCommented:
No way. Please remember that "chroot" is meant for jailing users in their homes.

Allowing symlinks to the outside of the jail would heaviliy contradict this intention.

Symlinks as set up by you are relative to the system root ( / ), but chroot establishes a new root, thus making the system root inaccessible - that's how it should work.

You could add a whole directory structure to the jail by means of "mount --bind":

mkdir /home/user/files
mount --bind /var/files/user /home/user/files

(just an example!)
0
 
gheistCommented:
Chroot directory for SFTP needs to be read-only for anyone not root.
After it cd-s to full homedir path in that chroot

say you might need
cd /home
ln -s / home

to make normal users work
0
 
LinuxGuruLinux Server AdministratorAuthor Commented:
thanks for the assist..
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

  • 3
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now