Forums

Skip to content

Advanced search
  • Quick links
    • Unanswered topics
    • Active topics
    • Search
  • FAQ
  • Login
  • Register
  • Board index Discussion & Documentation Documentation, Tips & Tricks
  • Search

Creating a chrooted sftp server without giving shell

Unofficial documentation for various parts of Gentoo Linux. Note: This is not a support forum.
Post Reply
Advanced search
81 posts
  • Previous
  • 1
  • 2
  • 3
  • 4
  • Next
Author
Message
Cicero
Apprentice
Apprentice
Posts: 220
Joined: Mon Jul 21, 2003 3:52 pm

  • Quote

Post by Cicero » Mon Nov 10, 2003 6:48 am

After much research and hard work on this:

http://bugs.gentoo.org/show_bug.cgi?id=33118

Please try it out!
Top
DArtagnan
l33t
l33t
User avatar
Posts: 942
Joined: Tue Apr 30, 2002 11:23 am
Location: Israel, Jerusalem
Contact:
Contact DArtagnan
Website

Re: Creating a chrooted sftp server without giving shell

  • Quote

Post by DArtagnan » Tue Nov 11, 2003 9:05 am

OmniVector wrote:I found little documentation on this subject, and I'm sure if would be of interest to many people trying to create a secure ftp solution, and this is what I came up with.


Firstly you'll need to emerge the restricted rssh shell

Code: Select all

emerge rssh
To configure it, you'll need add /usr/bin/rssh to the list of accepted shells:

Code: Select all

echo /usr/bin/rssh >> /etc/shells
and you'll want to modify the rssh config and make some minor changes to enable chrooting, scp, and sftp.

/etc/rssh.conf:

Code: Select all

logfacility = LOG_USER
allowscp
allowsftp
umask = 022
chrootpath="/home"
If you wish to disable scp, or sftp independently, just remove the line or comment it out with a #.

Next, we need to build a chroot environment for rssh to work.
This involves copying a few files to our chrooted folder (/home).

Code: Select all

cd /home

mkdir -p usr/bin
cp /usr/bin/scp usr/bin
cp /usr/bin/rssh usr/bin

mkdir -p usr/libexec
cp /usr/libexec/rssh_chroot_helper usr/libexec

mkdir -p usr/lib/misc
cp /usr/lib/misc/sftp-server usr/lib/misc
though we're not quite done copying files yet. now we need to copy the dependencies of those files. ldd will tell us what files are needed

Code: Select all

ldd /usr/bin/scp
        libutil.so.1 => /lib/libutil.so.1 (0x4001c000)
        libz.so.1 => /usr/lib/libz.so.1 (0x4001f000)
        libnsl.so.1 => /lib/libnsl.so.1 (0x4002d000)
        libcrypto.so.0.9.6 => /usr/lib/libcrypto.so.0.9.6 (0x40042000)
        libc.so.6 => /lib/libc.so.6 (0x40106000)
        libdl.so.2 => /lib/libdl.so.2 (0x40235000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0x40000000)
so now we need to make the necessary folders, and copy the libs needed for scp

Code: Select all

cd /home

mkdir lib
cp /lib/libutil.so.1 lib
cp /lib/libnsl.so.1 lib
cp /lib/libc.so.6 lib
cp /lib/libdl.so.2 lib
cp /lib/ld-linux.so.2 lib

mkdir -p usr/lib
cp /usr/lib/libz.so.1 usr/lib
cp /usr/lib/libcrypto.so.0.9.6 usr/lib
now run ldd on the other files we copied into our chroot environment

Code: Select all

ldd /usr/bin/rssh
ldd /usr/libexec/rssh_chroot_helper
ldd /usr/lib/misc/sftp-server
copy the libraries associated with those files if there are any we didn't already get from scp. note: for me, there were no other dependencies. copying all the dependencies for scp was enough for me. this should be the case for you as well unless your configuration is very different.

the only thing left to do now is create a user and change their shell to /usr/bin/rssh. there are a couple of ways to do this. you could run superadduser

Code: Select all

emerge superadduser
superadduser

Login name for new user []: testuser

User ID ('UID') [ defaults to next available ]:

Initial group [ users ]:

Additional groups (comma separated) []:

Home directory [ /home/testuser ]
- Warning: '/home/testuser' already exists !
  Do you wish to change the home directory path? (Y/n)  n

Shell [ /bin/bash ] /usr/bin/rssh

Expiry date (YYYY-MM-DD) []:
or simply modify an existing user account

Code: Select all

usermod -s /usr/bin/rssh testuser


finally make sure sshd is running

Code: Select all

/etc/init.d/sshd status
 * status:  started
if not run /etc/init.d/sshd start
and try connecting:

Code: Select all

sftp testuser@yourip.com
Connecting to yourip.com...
testuser@yourip.com's password:
sftp> ls
.
..
.bash_profile
.bashrc
.qmail
sftp> pwd
Remote working directory: /testuser
sftp> exit
ssh testuser@yourip.com
testuser@yourip.com's password:

This account is restricted to scp or sftp.

If you believe this is in error, please contact your system administrator.

Connection to yourip.com closed.

Viola! sftp with chrooting, and no shell allowed!
Also please add this line to your howto in order to make it perfect :-))

Code: Select all

# cp /lib/libcrypt.so.1 /home/lib/
I could not have the chroot working without this line!
All for one and one for All
--

MACPRO machine...
Top
Cicero
Apprentice
Apprentice
Posts: 220
Joined: Mon Jul 21, 2003 3:52 pm

  • Quote

Post by Cicero » Tue Nov 11, 2003 4:35 pm

Cicero wrote:After much research and hard work on this:

http://bugs.gentoo.org/show_bug.cgi?id=33118

Please try it out!
For those too lazy to click on the link without knowing what it is, I made a patch for rssh that added cvs support.
Top
Cicero
Apprentice
Apprentice
Posts: 220
Joined: Mon Jul 21, 2003 3:52 pm

  • Quote

Post by Cicero » Mon Nov 17, 2003 4:25 am

Eh, forget it. It's been brutally rejected.
Top
DArtagnan
l33t
l33t
User avatar
Posts: 942
Joined: Tue Apr 30, 2002 11:23 am
Location: Israel, Jerusalem
Contact:
Contact DArtagnan
Website

HELP!!!

  • Quote

Post by DArtagnan » Thu Nov 20, 2003 9:38 am

Any 1 can understand why I can this error: "user livius attempted to execute forbidden commands" ???
Thanks

My /etc/passw:

Code: Select all

livius:x:1003:501:Voicu Liviu,507,5881253,6310714,067424004:/liviu:/usr/local/bin/rssh
My rssh.conf:

Code: Select all

[root@ayelet liviu]# cat /usr/local/etc/rssh.conf
# This is the default rssh config file

# set the log facility.  "LOG_USER" and "user" are equivalent.
logfacility = LOG_USER # you can use comments at end of line

# Leave these both uncommented to make the default action for rssh to lock
# users out completely...
allowscp
allowsftp

# set the default umask
umask = 022

# If you want to chroot users, use this to set the directory
# if you DO NOT want to chroot users, LEAVE THIS COMMENTED OUT.
# Quotes not required unless path contains a space...
#chrootpath="/usr/local/chroot dir"

##########################################
# EXAMPLES of configuring per-user options
user=livius:077:11:/liviu
From logfile:

Code: Select all

Nov 20 11:35:34 ayelet rssh[23060]: allowing sftp to all users
Nov 20 11:35:34 ayelet rssh[23060]: setting umask to 022
Nov 20 11:35:34 ayelet rssh[23060]: line 21: configuring user livius
Nov 20 11:35:34 ayelet rssh[23060]: setting livius's umask to 077
Nov 20 11:35:34 ayelet rssh[23060]: allowing scp to user livius
Nov 20 11:35:34 ayelet rssh[23060]: allowing sftp to user livius
Nov 20 11:35:34 ayelet rssh[23060]: chrooting livius to /liviu
Nov 20 11:35:34 ayelet rssh[23060]: user livius attempted to execute forbidden commands
Nov 20 11:35:34 ayelet rssh[23060]: command: /usr/libexec/openssh/sftp-server
Nov 20 11:35:34 ayelet sshd(pam_unix)[23059]: session closed for user livius
All for one and one for All
--

MACPRO machine...
Top
Zidge
Tux's lil' helper
Tux's lil' helper
Posts: 86
Joined: Wed Aug 20, 2003 10:52 pm

  • Quote

Post by Zidge » Tue Jan 06, 2004 3:48 pm

I have the exact same problem
does anyone find the solution ?
Top
nulltype
n00b
n00b
Posts: 36
Joined: Wed Aug 13, 2003 7:31 am

  • Quote

Post by nulltype » Sat May 22, 2004 7:21 am

rssh 2.2 has been released, adding cvs, rdist and rsync support, not sure when it will be added to portage though.
Top
nulltype
n00b
n00b
Posts: 36
Joined: Wed Aug 13, 2003 7:31 am

  • Quote

Post by nulltype » Sun May 23, 2004 6:04 am

It appears to have a minor bug, I have submitted a patch to the author. If anyone uses it, just don't use user= lines in your rssh.conf
Top
cbock
Tux's lil' helper
Tux's lil' helper
Posts: 149
Joined: Fri Apr 16, 2004 5:22 pm
Location: san diego
Contact:
Contact cbock
Website

  • Quote

Post by cbock » Thu Jun 17, 2004 6:18 pm

followed the directions in the op and it's working nicely.

thanks.
Top
BoBoeBoe
n00b
n00b
Posts: 69
Joined: Tue Feb 17, 2004 10:58 pm

Cannot follow symlinks

  • Quote

Post by BoBoeBoe » Sat Jul 17, 2004 9:26 pm

I've setup rssh as explained above and this works fine with a regular directory structure. However I have a directory structure like
  • /data/symlink1
    /data/symlink2
    .......

Now I want my rssh-user to be able to access all symlinked subdirectories under /data however the rssh-user cannot access the symlinked subdirectories.
Top
danpixley
n00b
n00b
Posts: 66
Joined: Mon Jun 14, 2004 2:50 am
Contact:
Contact danpixley
Website

You can edit the chrooted passwd file

  • Quote

Post by danpixley » Wed Jul 21, 2004 2:15 am

Steffen wrote: Edit: I forgot to say that I had to copy my /etc/passwd file into the chroot, too. I don't know, but this makes SCP a bit less attractive for me than SFTP...
You only need an entry in passwd for the user. Everything else from your original passwd file can be removed.

Dan
Unanswered Post Initiative:
http://forums.gentoo.org/viewtopic.php?t=119906

My site:
http://danpixley.wordpress.com
Top
Alapan
n00b
n00b
Posts: 43
Joined: Wed Jul 21, 2004 10:16 pm

  • Quote

Post by Alapan » Sun Aug 22, 2004 12:22 pm

Has anyone tried using this method for an AMD64 system? The rssh package is not available for amd64 and I am wondering what the possible problems are.
Top
Alapan
n00b
n00b
Posts: 43
Joined: Wed Jul 21, 2004 10:16 pm

  • Quote

Post by Alapan » Sun Aug 22, 2004 1:47 pm

Ok I tried to see if I could make it work on my system anyway ...

I could compile and install fine; no problems there. For my test user; the rssh shell does provide me with restricted shell usage. However sftp does not seem to work at all - it is almost as if rssh is refusing sftp itself. Sftp itself works for unresticted users.

From another linux machine; the command

Code: Select all

sftp testuser@mymachine
asks for my password and then gives me a "connection closed" message. If I try using winscp for example, I get the following message.

Code: Select all

Connection has been unexpectedly closed. Server sent command exit status 0.

Any ideas on how I could make this work?
Top
Gavinv
n00b
n00b
User avatar
Posts: 10
Joined: Thu Aug 05, 2004 6:56 am

vulnerable?

  • Quote

Post by Gavinv » Wed Aug 25, 2004 12:28 am

For all who have implemented the chroot, beware of a user hard linking a setuid program into the chroot.

The user can then create their own fake supporting files (e.g. /etc/passwd), and the setuid program would use these files thinking they are the real ones. Then, if the user can use this setuid system program to gain root privileges, they can create a new setuid root program that does not require a chroot jail to gain root privileges ..

There are other pitfalls to using chroot.
grsecurity.org provides more information.
Top
milkypostman
n00b
n00b
User avatar
Posts: 45
Joined: Thu Oct 10, 2002 9:57 am

  • Quote

Post by milkypostman » Tue Oct 05, 2004 7:21 am

when i setup my chroot jail i made all the files root.root owned. meaning... they have no way of overwritting their /etc/passwd file. i think that fixes the problem above. just make sure that every file except for what you want them to be able to manage has your information.

if that were the case anyways, then why couldn't i goto any computer, set a chroot then develop a setuid program thats'd faked out? I don't know a lot about chroot but after you chroot aren't you kinda stuck anyways?
cupid packs the pistol
Top
colonel_dolphin
n00b
n00b
User avatar
Posts: 39
Joined: Mon Jan 12, 2004 6:20 pm

  • Quote

Post by colonel_dolphin » Tue Oct 12, 2004 7:35 pm

Code: Select all

info chroot
"On many systems, only the super-user can do this." (for good reasons!)

Try logging in as an ordinary user and hard linking a setuid program somewhere under your control. If you own the parent directory containing the files owned by root, then you can replace those files with your own. If you can also create a fake /etc/passwd in the chroot directory ..

grsecurity addresses some vulnerabilities associated with using chroot.
Top
GurliGebis
Retired Dev
Retired Dev
User avatar
Posts: 509
Joined: Thu Aug 08, 2002 7:40 am
Contact:
Contact GurliGebis
Website

  • Quote

Post by GurliGebis » Sat Oct 30, 2004 2:29 pm

I cannot get this working.
I have users like thing-001, thing-002 etc.

I want to chroot users into /var/www/thing-00X os they can upload thier webpage via SCP/SFTP, how should I do that.

By the way, the helper binary is placed another place in new versions of rssh.
Queen Rocks.
Top
colonel_dolphin
n00b
n00b
User avatar
Posts: 39
Joined: Mon Jan 12, 2004 6:20 pm

  • Quote

Post by colonel_dolphin » Sat Oct 30, 2004 4:48 pm

Try emerging this one ..
rojaro wrote:.. scponly ..
Top
GurliGebis
Retired Dev
Retired Dev
User avatar
Posts: 509
Joined: Thu Aug 08, 2002 7:40 am
Contact:
Contact GurliGebis
Website

  • Quote

Post by GurliGebis » Sun Oct 31, 2004 1:51 pm

emerged scponly, but how do I configure it? 8O
Queen Rocks.
Top
j-m
Retired Dev
Retired Dev
Posts: 975
Joined: Sun Oct 31, 2004 3:54 pm

  • Quote

Post by j-m » Sun Oct 31, 2004 4:02 pm

GurliGebis wrote:emerged scponly, but how do I configure it? 8O
First of all, you need scponly-3.11-r2 (unstable but should be stable in one day or so). Previous version do NOT support chrooted SFTP.

Basically everything is configured. There is a directory /home/scponly which includes all files needed for successful chrooted SFTP. If you want your users to only be able to SFTP via SSH and you don´t want to allow them work interactively in shell, then add them with /sbin/scponlyc as their shell, copy all subdirectories (except incoming) from /home/scponly to their home directory and create a writeable subdirectory for them in their home.

That´s it. :D
Top
GurliGebis
Retired Dev
Retired Dev
User avatar
Posts: 509
Joined: Thu Aug 08, 2002 7:40 am
Contact:
Contact GurliGebis
Website

  • Quote

Post by GurliGebis » Sun Oct 31, 2004 4:45 pm

Okay, that works, is there a way to place the folders somewhere so the user only sees the folder I create for him to upload in?
Queen Rocks.
Top
j-m
Retired Dev
Retired Dev
Posts: 975
Joined: Sun Oct 31, 2004 3:54 pm

  • Quote

Post by j-m » Sun Oct 31, 2004 4:49 pm

GurliGebis wrote:Okay, that works, is there a way to place the folders somewhere so the user only sees the folder I create for him to upload in?
No, this is not possible. The dirs make up the filesystem hierarchy needed for chroot to work and MUST be placed in the chrooted home directory. I don´t see the point why you need this anyway. They are NOT user writeable anyway.
Top
GurliGebis
Retired Dev
Retired Dev
User avatar
Posts: 509
Joined: Thu Aug 08, 2002 7:40 am
Contact:
Contact GurliGebis
Website

  • Quote

Post by GurliGebis » Sun Oct 31, 2004 5:59 pm

to avoid confusing the users that does not know about unix
Queen Rocks.
Top
j-m
Retired Dev
Retired Dev
Posts: 975
Joined: Sun Oct 31, 2004 3:54 pm

  • Quote

Post by j-m » Sun Oct 31, 2004 6:30 pm

GurliGebis wrote:to avoid confusing the users that does not know about unix
Ok, you can´t do that. Period. :wink:
Top
johanseg
n00b
n00b
User avatar
Posts: 18
Joined: Thu Nov 27, 2003 1:12 pm
Location: Sweden
Contact:
Contact johanseg
Website

linux-gate.so.1

  • Quote

Post by johanseg » Mon Nov 15, 2004 4:41 pm

When I run ldd /usr/bin/scp it shows a dependency for linux-gate.so.1 but it doesn't state where it is.

Code: Select all

# ldd /usr/bin/scp
        linux-gate.so.1 =>  (0xffffe000)
        libresolv.so.2 => /lib/libresolv.so.2 (0xb7fcf000)
        libcrypto.so.0.9.7 => /usr/lib/libcrypto.so.0.9.7 (0xb7ed3000)
        libutil.so.1 => /lib/libutil.so.1 (0xb7ed0000)
        libz.so.1 => /lib/libz.so.1 (0xb7ebf000)
        libnsl.so.1 => /lib/libnsl.so.1 (0xb7eaa000)
        libcrypt.so.1 => /lib/libcrypt.so.1 (0xb7e7d000)
        libc.so.6 => /lib/libc.so.6 (0xb7d6b000)
        libdl.so.2 => /lib/libdl.so.2 (0xb7d68000)
        /lib/ld-linux.so.2 => /lib/ld-linux.so.2 (0xb7fea000)
What is linux-gate.so.1 and where is it?
/Johan

Quis custodiet ipsos custodes?
Blog | screenshots
Top
Post Reply

81 posts
  • Previous
  • 1
  • 2
  • 3
  • 4
  • Next

Return to “Documentation, Tips & Tricks”

Jump to
  • Assistance
  • ↳   News & Announcements
  • ↳   Frequently Asked Questions
  • ↳   Installing Gentoo
  • ↳   Multimedia
  • ↳   Desktop Environments
  • ↳   Networking & Security
  • ↳   Kernel & Hardware
  • ↳   Portage & Programming
  • ↳   Gamers & Players
  • ↳   Other Things Gentoo
  • ↳   Unsupported Software
  • Discussion & Documentation
  • ↳   Documentation, Tips & Tricks
  • ↳   Gentoo Chat
  • ↳   Gentoo Forums Feedback
  • ↳   Duplicate Threads
  • International Gentoo Users
  • ↳   中文 (Chinese)
  • ↳   Dutch
  • ↳   Finnish
  • ↳   French
  • ↳   Deutsches Forum (German)
  • ↳   Diskussionsforum
  • ↳   Deutsche Dokumentation
  • ↳   Greek
  • ↳   Forum italiano (Italian)
  • ↳   Forum di discussione italiano
  • ↳   Risorse italiane (documentazione e tools)
  • ↳   Polskie forum (Polish)
  • ↳   Instalacja i sprzęt
  • ↳   Polish OTW
  • ↳   Portuguese
  • ↳   Documentação, Ferramentas e Dicas
  • ↳   Russian
  • ↳   Scandinavian
  • ↳   Spanish
  • ↳   Other Languages
  • Architectures & Platforms
  • ↳   Gentoo on ARM
  • ↳   Gentoo on PPC
  • ↳   Gentoo on Sparc
  • ↳   Gentoo on Alternative Architectures
  • ↳   Gentoo on AMD64
  • ↳   Gentoo for Mac OS X (Portage for Mac OS X)
  • Board index
  • All times are UTC
  • Delete cookies

© 2001–2026 Gentoo Foundation, Inc.

Powered by phpBB® Forum Software © phpBB Limited

Privacy Policy

 

 

magic