• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Homeverzeichnis in der Chroot-Umgebung

Hallo Linuxgemeinde,

ich bastel gerade an einer chroot-Lösung, die auf openssh (5.1p1, Debian lenny) basiert und bei der jeder User eine eigene chroot-Umgebung erhalten soll

Code:
Match Group chroot
   ChrootDirectory /home/%u     
   AllowTCPForwarding no
   PasswordAuthentication yes
Match
Der Zugriff soll nicht auf sftp beschränkt werden, d.h. ein bash-Zugriff mit ausgewählten Proggies ist angedacht.



Die Schwierigkeit ist nun, dass das Homeverzeichnis in der Chroot-Umgebung das des Servers ist.

Ich erläuter das Problem man detailliert anhand des Beispielusers "chrootruser"

Die /home/chrootruser/etc/passwd sieht so aus

Code:
root:x:0:0:root:/root:/bin/bash
chrootruser:x:10000:1000::/home:/bin/bash
D.h. das Homeverzeichnis des chrootruser ist auf dem Server /home/chrootruser/home


Dass die Publickey-Authentifizierung funktioniert, lautet der Eintrag in der /etc/passwd

Code:
chrootruser:x:10000:1000::/home/chrootruser/home:/bin/bash
denn das .ssh-Verzeichnis ist im Homeverzeichnis des Users in der Chroot-Umgebung


Logge ich mich nun per SSH mit dem User chrootruser ein, zeigt das Home-Verzeichnis auf die Konfiguration des Servers und nicht auf das innerhalb der chroot-Umgebung

Code:
bash-3.2$ ls   
bin  dev  etc  home  lib  lib64  usr
-bash-3.2$ ls  ~
ls: cannot access /home/chrootruser/home: No such file or directory
-bash-3.2$

Hat wer ne Idee, in welcher Datei ich welche Variable o.ä. anpassen muss? .


Schreibe ich in die /home/chrooteduser/etc
Code:
HOME="/home"

ist ~ und $HOME nach dem Einloggen tatsächlich geändert.

Nur landet man dannnach dem Login im

Code:
~/chrooteduser/home$


Es muss noch eine andere zu manipulieren Stelle geben ....


Gruß
Heiko
 
ChrootDirectory in der Art wie du es nutzen willst, muss ein paar Bedingungen erfüllen.
(...must be root-owned directories...)
Die Basis mit /bin/sh, etc. muss auch in dem Verzeichnis drin sein.

man sshd_config

Code:
    ChrootDirectory
             Specifies the pathname of a directory to chroot(2) to after authentication.  All components
             of the pathname must be root-owned directories that are not writable by any other user or
             group.  After the chroot, sshd(8) changes the working directory to the user's home direc-
             tory.

             The pathname may contain the following tokens that are expanded at runtime once the con-
             necting user has been authenticated: %% is replaced by a literal '%', %h is replaced by the
             home directory of the user being authenticated, and %u is replaced by the username of that
             user.

             The ChrootDirectory must contain the necessary files and directories to support the user's
             session.  For an interactive session this requires at least a shell, typically sh(1), and
             basic /dev nodes such as null(4), zero(4), stdin(4), stdout(4), stderr(4), arandom(4) and
             tty(4) devices.  For file transfer sessions using “sftp”, no additional configuration of
             the environment is necessary if the in-process sftp server is used, though sessions which
             use logging do require /dev/log inside the chroot directory (see sftp-server(8) for
             details).

             In the special case when only sftp is used, not ssh nor scp, it is possible to use
             ChrootDirectory %h or ChrootDirectory /some/path/%u. The file system containing this direc-
             tory must be mounted with options nodev and either nosuid or noexec. The owner of the
             directory should be the user. The ownership of the other components of the path must ful-
             fill the usual conditions. No aditional files are required to be present in the directory.

             The default is not to chroot(2).
Haveaniceday
 
Hallo,

ja, die Rechte-Frage ist i.O.

Der Satz ist hier Kasus Knacktus
Code:
After the chroot, sshd(8) changes the working directory to the user's home direc-
             tory.

Es wird das home-Directory des Users genommen, wie es in der /etc/passwd des Servers angegeben ist. Es wird nicht die etc/passwd der chroot-Umgebung verwendet.
Die alte openssh-Lösung mit dem Patch kenne ich nicht.
Die Doku dort ist jedoch recht logisch
Konfiguriert man dort
Code:
/home/chroot/chrootuser/./home
springt er nach dem Chrooten nach /home (innerhalb der chroot-Umbebung /home/chroot/chrootuser/)
Das macht der aktuelle openSSH so nicht.

Ich kann mir kaum vorstellen, dass das ein Bug ist oder von niemandem bemerkt wurde. Ich muss da einen Config-Fehler haben.

Gruß
Heiko
 
Ich meinte eher diesen Teil für die Anmeldung:

Code:
The ChrootDirectory must contain the necessary files and directories to support the user's
             session.  For an interactive session this requires at least a shell, typically sh(1), and
             basic /dev nodes such as null(4), zero(4), stdin(4), stdout(4), stderr(4), arandom(4) and
             tty(4) devices.  For file transfer sessions using “sftp”, no additional configuration of
             the environment is necessary if the in-process sftp server is used, though sessions which
             use logging do require /dev/log inside the chroot directory (see sftp-server(8) for
             details).
Hast du /dev mit Inhalt, sh, libs etc. drin?

Haveaniceday
 
Oben