Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Hide Home Directories in CHROOT Jail

Posted on 2012-12-31
4
Medium Priority
?
517 Views
Last Modified: 2013-01-03
Hello,

I have a CHROOT jail for SFTP users that's working well but there's one thing that bugs me and I'd like to try to fix it if I could.  

I have the following in my /etc/ssh/sshd_config file:

Subsystem sftp internal-sftp

Match group sftponly
        ChrootDirectory /home
        AllowTcpForwarding no
        X11Forwarding no
        ForceCommand internal-sftp

When I want to add an sftponly user I perform the following steps:

# useradd username
# passwd username
# usermod -g sftponly username
# mkdir /home/username
# chown username /home/username
# chmod 700 /home/username

This allows sftp only access to the user and they only have permissions to read and write in their own directory but, they can see a list of all of the other users directories in /home.  

I would prefer it if when an sftponly user logs in via SFTP, only their home directory is visible or, something runs when they login via an SFTP client that automatically changes their directory and dumps them in their home folder.  

I'm open to other ideas but the end result would be that the user doesn't see the other user's folders.  

Thanks for any help!  Happy New Year!
0
Comment
Question by:ttist25
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
  • 2
4 Comments
 
LVL 68

Expert Comment

by:woolmilkporc
ID: 38733343
You could jail your users into their particular home directories instead of just /home.

This can be done in the "Match" block of sshd_config with

ChrootDirectory /home/%u

or

ChrootDirectory %h

which is equivalent in your case, because "%u" is a placeholder for the userid of the user logging in and "%h" is a placeholder for their complete home directory path.
0
 
LVL 1

Author Comment

by:ttist25
ID: 38733410
Thanks for your response woolmilkporc.  

I tried as you suggested and I end up with an authentication failure.  I seem to remember this from when I was setting it up.  Something about the root folder for the chroot jail must be owned by root.  

In the past I wondered if the best solution was to somehow dump the user over to the /home/%u folder when they connected.  This wouldn't necessarily stop them from traversing up a level to see the other user folders in /home but, it wouldn't smack them in the face with  it either.  Know what I mean?  

I have no idea how I'd do that though if it's even possible (consider that nearly all uers will be connecting with an SFTP client like winscp).  

Thanks again for your help.  It is greatly appreciated.
0
 
LVL 68

Accepted Solution

by:
woolmilkporc earned 2000 total points
ID: 38733517
OK,

I forgot to mention the details.

You're right, the chroot directory and all components of its path must be owned by root with write access by the owner (root) only.

But you can create a user-owned, user-writeable directory below ChrootDir, e..g /home/username/username.

Leave ChrootDir as /home/%u, but change the user's home directory to just "/username". sshd changes to this directory after chrooting (relative to the new root!), which means that the user will end up in /home/username/username.

Once logged in with sftp "pwd" will show

Remote working directory: /username

The user can well issue "cd .. ; ls" or "ls ..", but this will just show the contents of /home/username, not those of /home.

After "cd .." "pwd" will show:

Remote working directory: /

but this is in fact /home/username (the ChrootDir)

Please let me know if you need the detailed commands to implement this.
0
 
LVL 1

Author Closing Comment

by:ttist25
ID: 38742161
Brilliant!  

I've been trying to do that for a while now.  Thanks so much.  

HAPPY NEW YEAR!
0

Featured Post

Concerto's Cloud Advisory Services

Want to avoid the missteps to gaining all the benefits of the cloud? Learn more about the different assessment options from our Cloud Advisory team.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

If you have a server on collocation with the super-fast CPU, that doesn't mean that you get it running at full power. Here is a preamble. When doing inventory of Linux servers, that I'm administering, I've found that some of them are running on l…
Linux users are sometimes dumbfounded by the severe lack of documentation on a topic. Sometimes, the documentation is copious, but other times, you end up with some obscure "it varies depending on your distribution" over and over when searching for …
Learn how to get help with Linux/Unix bash shell commands. Use help to read help documents for built in bash shell commands.: Use man to interface with the online reference manuals for shell commands.: Use man to search man pages for unknown command…
Learn how to navigate the file tree with the shell. Use pwd to print the current working directory: Use ls to list a directory's contents: Use cd to change to a new directory: Use wildcards instead of typing out long directory names: Use ../ to move…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question