from small one page howto to huge articles all in one place

search text in:




Other .linuxhowtos.org sites: www.linuxhowtos.org
toolsntoys.linuxhowtos.org



Last additions:
How to make X listen on port 6000

How to make X listen on port 6000

words:

34

views:

86057

userrating:

average rating: 1.2 (52 votes) (1=very good 6=terrible)


May, 25th 2007:
April, 26th 2007:
Apr, 10th. 2007:
Druckversion . pdf icon
You are here: Tutorials per portage category->net-misc->openssh

Create a chrooted ssh user

This tutorial explains how to install and configure a chroot enviroment for an ssh user. This setup enables you to give out ssh accounts without having to fear that this user can see all files on the system.

Installing ssh

First you need to have a patched version of the sshd server. Luckily these patches can be enabled with the use flag "chroot" in the sshd use flags.
#echo "net-misc/openssh chroot" >> /etc/portage/package.use
#emerge openssh

creating the chroot enviroment

We will create our chroot enviroment in /home/chroot.
To make the chroot work, run the following commands to make the needed directories and devices for the chrooted user.
mkdir /home/chroot/
mkdir /home/chroot/home/
cd /home/chroot
mkdir etc
mkdir bin
mkdir lib
mkdir usr
mkdir usr/bin
mkdir dev
mknod dev/null c 1 3
mknod dev/zero c 1 5

Now we need to populate the directories with some binaries.
copy the following script into a file. If you need more apps, add them
to the APPS line.

APPS="/bin/bash /bin/ls /bin/mkdir /bin/mv /bin/pwd /bin/rm /usr/bin/id /usr/bin/ssh /bin/ping /usr/bin/dircolors"
for prog in $APPS; do
cp $prog ./$prog

# obtain a list of related libraries
ldd $prog > /dev/null
if [ "$?" = 0 ] ; then
LIBS=`ldd $prog | awk '{ print $3 }'`
for l in $LIBS; do
mkdir ./`dirname $l` > /dev/null 2>&1
cp $l ./$l
done
fi
done

After you have run the script, your chroot enviroment is almost done.
run

cp /lib/libnss_compat.so.2 /lib/libnsl.so.1 /lib/libnss_files.so.2 ./lib/
echo '#!/bin/bash' > usr/bin/groups
echo "id -Gn" >> usr/bin/groups
touch etc/passwd
grep /etc/passwd -e "^root" > etc/passwd
to copy some libraries and user information into the chroot.
You should also copy the line of the group in which you will create new users from /etc/group to /home/chroot/etc/group. In this tutorial we will create users in the group users, so we do this:
grep /etc/group -e "^root" -e "^users" > etc/group

and restart SSH:
/etc/init.d/ssh restart

Creating chrooted users

ssh decides which user should be chrooted and which not by the "home directory" entry in the /etc/passwd.
Example for a non-chrooted user:
user_a:x:2002:100:User A:/home/user_a:/bin/bash
This user will be chrooted:
user_b:x:2003:100:User B:/home/chroot/./home/user_b:/bin/bash
Now lets add a testuser to the chrooted user list:
useradd -s /bin/bash -m -d /home/chroot/./home/testuser -c "testuser" -g users testuser

Then we give testuser a password:
passwd testuser

Finally, we have to copy the line for testuser in /etc/passwd to /home/chroot/etc/passwd:
grep /etc/passwd -e "^testuser" >> /home/chroot/etc/passwd


Now log in as testuser and see if everything worked.

Have fun
back



Support us on Content Nation

New Packages

- as rdf newsfeed
- as rss newsfeed
- as Atom newsfeed
2026-06-19
awscli - 1.45.33
Ebuild name:

app-admin/awscli-1.45.33

Description

Universal Command Line Environment for AWS

Added to portage

2026-06-19

ibus - 1.5.34
Ebuild name:

app-i18n/ibus-1.5.34

Description

Intelligent Input Bus for Linux / Unix OS

Added to portage

2026-06-19

magit - 9999
Ebuild name:

app-emacs/magit-9999

Description

A Git porcelain inside Emacs

Added to portage

2026-06-19

magit-popup - 2.13.3-r1
Ebuild name:

app-emacs/magit-popup-2.13.3-r1

Description

Define prefix-infix-suffix command combos

Added to portage

2026-06-19

qemu - 10.0.10
Ebuild name:

app-emulation/qemu-10.0.10

Description

QEMU + Kernel-based Virtual Machine userland tools

Added to portage

2026-06-19

qemu - 10.2.3
Ebuild name:

app-emulation/qemu-10.2.3

Description

QEMU + Kernel-based Virtual Machine userland tools

Added to portage

2026-06-19

virtualbox - 7.2.10
Ebuild name:

app-emulation/virtualbox-7.2.10

Description

Family of powerful x86 virtualization products for enterprise and h

Added to portage

2026-06-19

virtualbox-additions - 7.2.10
Ebuild name:

app-emulation/virtualbox-additions-7.2.10

Description

CD image containing guest additions for VirtualBox

Added to portage

2026-06-19

virtualbox-extpack-oracle - 7.2.10
Ebuild name:

app-emulation/virtualbox-extpack-oracle-7.2.10

Description

PUEL extensions for VirtualBox

Added to portage

2026-06-19

virtualbox-guest-additions - 7.2.10
Ebuild name:

app-emulation/virtualbox-guest-additions-7.2.10

Description

VirtualBox kernel modules and user-space tools for

Added to portage

2026-06-19

virtualbox-guest-modules - 7.2.10
Ebuild name:

app-emulation/virtualbox-guest-modules-7.2.10

Description

Kernel Modules for Virtualbox Guest Additions

Added to portage

2026-06-19

virtualbox-kvm - 7.2.10_pre20260201
Ebuild name:

app-emulation/virtualbox-kvm-7.2.10_pre20260201

Description

Family of powerful x86 virtualization products for

Added to portage

2026-06-19

virtualbox-modules - 7.2.10
Ebuild name:

app-emulation/virtualbox-modules-7.2.10

Description

Kernel Modules for Virtualbox

Added to portage

2026-06-19

2026-06-18
awscli - 1.45.32
Ebuild name:

app-admin/awscli-1.45.32

Description

Universal Command Line Environment for AWS

Added to portage

2026-06-18

magit-popup - 2.13.3-r1
Ebuild name:

app-emacs/magit-popup-2.13.3-r1

Description

Define prefix-infix-suffix command combos

Added to portage

2026-06-18

mailcrypt - 3.5.9-r3
Ebuild name:

app-emacs/mailcrypt-3.5.9-r3

Description

Provides a simple interface to public key cryptography with OpenPGP

Added to portage

2026-06-18

marginalia - 2.10
Ebuild name:

app-emacs/marginalia-2.10

Description

Marginalia in the minibuffer

Added to portage

2026-06-18

mcrypt - 2.6.8-r3
Ebuild name:

app-crypt/mcrypt-2.6.8-r3

Description

Replacement of the old unix crypt(1)

Added to portage

2026-06-18

md5deep - 4.4
Ebuild name:

app-crypt/md5deep-4.4

Description

Expanded md5sum program with recursive and comparison options

Added to portage

2026-06-18

md6sum - 1.0-r3
Ebuild name:

app-crypt/md6sum-1.0-r3

Description

A C implementation of MD6

Added to portage

2026-06-18

mhash - 0.9.9.9-r4
Ebuild name:

app-crypt/mhash-0.9.9.9-r4

Description

Library providing a uniform interface to a large number of hash algorith

Added to portage

2026-06-18

terraform - 1.15.6
Ebuild name:

app-admin/terraform-1.15.6

Description

A tool for building, changing, and combining infrastructure safely

Added to portage

2026-06-18

wine-mono - 11.2.0
Ebuild name:

app-emulation/wine-mono-11.2.0

Description

Replacement for the .NET runtime and class libraries in Wine

Added to portage

2026-06-18

rdf newsfeed | rss newsfeed | Atom newsfeed
Copyright 2004-2025 Sascha Nitsch Unternehmensberatung GmbH
- Copyright and legal notices -
Time to create this page: 81.7 ms