OpenSSH et chroot

Bonsoir !

Alors voilà, j’ai voulu chroot un utilisateur dans un dossier :

Pour ce faire, j’ai utilisé ceci dans /etc/ssh/sshd_config :

Subsystem       sftp    internal-sftp

Match Group littleboy62
         ChrootDirectory /var/www/littleboy62
         ForceCommand internal-sftp
         AllowTCPForwarding no
         X11Forwarding no

Et voilà le message d’erreur…

Mon dossier /var/www est bien root… mais il doit y avoir un souci de ce côté car il me dit le dossier /var/www dans la ligne, pas /var/www/littleboy62. J’ai testé le chroot dans son home et ça marchait très bien.

Aussi j’ai modifié le home de l’utilisateur dans /etc/passwd :

Et voilà…

Merci à vous :slightly_smiling:

[quote=“fatal”]bad ownership or modes for chroot directory “/var/www/”[/quote] => pas le bon propriétaire ou attributs d’accès, pour faire un chroot avec le dossier “/var/www”

[quote=“Dinath”]… Mon dossier /var/www est bien root…[/quote]Mais encore ?
[ul]propriétaire “root” ou groupe “root”?
propriétaire et groupe “root”?
[/ul]

Quels sont les attributs d’accès au dossier “/var/www/littleboy62” concernant le propriétaire, le groupe, et les autres (u g o) ?

Quel est l’uid et à quel groupe(s) appartiens l’utilisateur “littleboy62” ?

===============
Il faudrait donc vérifier ces informations au sujet de ce dossier, pour:
[ul]soit les adapter à l’utilisateur,
soit adapter l’utilisateur à ces informations.
[/ul]

Donc:

==============
Quel est l’uid et à quel groupe(s) appartiens l’utilisateur “littleboy62” ?
(avec les privilèges du compte root)

(ou depuis le compte de l’utilisateur “littleboy62”)

==============
Merci de transmettre les informations complètes, c’est à dire :
[ul]avec le prompt,
la commande entrée,
et le retour complet de la commande.
[/ul]

Avec une seule commande et son retour par bloc de code.
Comme par exemple:

michel@deb9550:~$ id uid=1000(michel) gid=1000(michel) groupes=1000(michel),24(cdrom),25(floppy),29(audio),30(dip),44(video),46(plugdev),104(scanner),109(bluetooth),110(netdev),119(libvirt) michel@deb9550:~$

michel@deb9550:~$ ls -la /mnt
total 17
drwxr-xr-x  11 root   root   1024 sept. 16 09:06 .
drwxr-xr-x  23 root   root   1024 août  26 01:34 ..
drwxrwx---+ 38 michel michel 4096 sept. 14 04:47 1500-1
drwxr-xr-x   3 root   root   4096 sept. 12 16:50 500-17-virt-img
michel@deb9550:~$ 

De cette façon, on évite des malentendus concernant:
[ul]les privilèges du compte utilisateur qui a lancé la commande,
les erreurs de syntaxe dans la ligne de commande,
les messages d’erreurs incomplets ou absents,
etc…
[/ul]

Merci encore.

Bonjour,

Merci de ta réponse.

root@alexandre:/home/dinath# id littleboy62
uid=1005(littleboy62) gid=1004(littleboy62) groupes=1004(littleboy62),33(www-data)
root@alexandre:/home/dinath# ls -la /var/
total 52
drwxr-xr-x 13 root     root     4096 sept. 20 23:15 .
drwxr-xr-x 22 root     root     4096 juin   6 14:00 ..
drwxr-xr-x  2 root     root     4096 sept. 21 06:25 backups
drwxr-xr-x 12 root     root     4096 sept.  5 10:24 cache
drwxr-xr-x 34 root     root     4096 juil.  9 14:15 lib
drwxrwsr-x  2 root     staff    4096 janv. 22  2012 local
lrwxrwxrwx  1 root     root        9 juin   6 14:29 lock -> /run/lock
drwxr-xr-x 11 root     root     4096 sept. 21 12:55 log
drwxrwsr-x  2 root     mail     4096 sept. 20 18:35 mail
drwxr-xr-x  2 root     root     4096 avril 16  2012 opt
lrwxrwxrwx  1 root     root        4 juin   6 14:29 run -> /run
drwxr-xr-x  7 root     root     4096 juin   6 13:58 spool
drwxrwxrwt  2 root     root     4096 sept.  1 00:01 tmp
drwxr-xr-x  3 www-data www-data 4096 sept. 21 14:19 webdav
drwxrwxr-x 11 root     root     4096 sept. 20 10:12 www


root@alexandre:/home/dinath# ls -la /var/www
total 168
drwxrwxr-x 11 root root  4096 sept. 20 10:12 .
drwxr-xr-x 13 root root  4096 sept. 20 23:15 ..
drwxrwxr-x 11 root root  4096 août  16 00:12 blog
drwxrwxr-x  3 root root  4096 sept. 19 11:34 docs
drwxr-xr-x  2 root root  4096 sept. 18 19:33 download
-rw-r--r--  1 root root 82726 mai   19 15:55 favicon.ico
drwxrwxr-x 10 root root  4096 août  23 12:06 forum
drwxr-xr-x  6 root root  4096 juil. 27 23:51 gen-hackman
-rwxrwxr-x  1 root root 19967 sept. 12 19:42 .htaccess
drwxrwxrwx  4 root root  4096 août  13 16:25 image
drwxrwxr-x 48 root root  4096 août  13 22:29 img
-rw-r--r--  1 root root    94 sept. 12 14:02 index.php
drwxrwxrwx  3 root root  4096 sept. 20 19:14 littleboy62
-rwxrwxr-x  1 root root    32 sept.  9  2012 mywot699d325d23af65eba421.html
-rwxrwxr-x  1 root root    30 mars  17  2013 robots.txt
drwxrwxr-x  4 root root  4096 août  20 14:26 Tools
-rwxrwxr-x  1 root root    48 juil. 13 22:03 update.dat

Si tu as besoin d’autres choses… :wink:

La commande “ls -la /var/www” a permis de mettre en évidence que le répertoire “/var/www/littleboy62” appartient à “root” et au groupe “root”.
(Bien que tout le monde (u, g, o) puisse y accéder, lire et écrire.)

root@alexandre:/home/dinath# ls -la /var/www ... drwxrwxrwx 3 root root 4096 sept. 20 19:14 littleboy62 ...Dans le message d’erreur on peut lire : " …bad ownership …"
Il faudrait donc que ce répertoire soit la propriété du compte “littleboy62”.

Depuis le compte root (puisque c’est le propriétaire actuel de ce répertoire), tu pourrais utiliser la commande “chown” :

chown -R littleboy62:littleboy62 /var/www/littleboy62L’option -R permettra d’appliquer ce changement de proriétaire et de groupe à tous les sous-répertoires et fichiers du répertoire “/var/www/littleboy62”

======================
Mais la commande précédente ne modifiera pas les droits d’accès à ce répertoire et ce qu’il contient.
Peut-être serait-il prudent de modifier ces droits d’accès avec la commande “chmod”.

J’avais déjà testé, toujours pareil :

Sep 21 19:28:56 alexandre sshd[13029]: fatal: bad ownership or modes for chroot directory component "/var/www/"
Sep 21 19:28:56 alexandre sshd[13025]: pam_unix(sshd:session): session closed for user littleboy62
root@alexandre:/home/dinath# ls -l /var/www
total 140
drwxrwxr-x 11 root        root         4096 août  16 00:12 blog
drwxrwxr-x  3 root        root         4096 sept. 19 11:34 docs
drwxr-xr-x  2 root        root         4096 sept. 18 19:33 download
-rw-r--r--  1 root        root        82726 mai   19 15:55 favicon.ico
drwxrwxr-x 10 root        root         4096 août  23 12:06 forum
drwxr-xr-x  6 root        root         4096 juil. 27 23:51 gen-hackman
drwxrwxrwx  4 root        root         4096 août  13 16:25 image
drwxrwxr-x 48 root        root         4096 août  13 22:29 img
-rw-r--r--  1 root        root           94 sept. 12 14:02 index.php
drwxrwxrwx  3 littleboy62 littleboy62  4096 sept. 20 19:14 littleboy62
-rwxrwxr-x  1 root        root           32 sept.  9  2012 mywot699d325d23af65eba421.html
-rwxrwxr-x  1 root        root           30 mars  17  2013 robots.txt
drwxrwxr-x  4 root        root         4096 août  20 14:26 Tools
-rwxrwxr-x  1 root        root           48 juil. 13 22:03 update.dat

Pourrais-tu nous transmettre le contenu complet du fichier “/etc/ssh/sshd_config” de ton installation ?
Merci

root@alexandre:/home/dinath# cat /etc/ssh/sshd_config
# Package generated configuration file
# See the sshd_config(5) manpage for details

# What ports, IPs and protocols we listen for
Port 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
#ListenAddress 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

# Lifetime and size of ephemeral version 1 server key
KeyRegenerationInterval 3600
ServerKeyBits 768

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin no
StrictModes yes

RSAAuthentication yes
PubkeyAuthentication yes
#AuthorizedKeysFile	%h/.ssh/authorized_keys

# Don't read the user's ~/.rhosts and ~/.shosts files
IgnoreRhosts yes
# For this to work you will also need host keys in /etc/ssh_known_hosts
RhostsRSAAuthentication no
# similar for protocol version 2
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
#IgnoreUserKnownHosts yes

# To enable empty passwords, change to yes (NOT RECOMMENDED)
PermitEmptyPasswords no

# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

# Change to no to disable tunnelled clear text passwords
#PasswordAuthentication yes

# Kerberos options
#KerberosAuthentication no
#KerberosGetAFSToken no
#KerberosOrLocalPasswd yes
#KerberosTicketCleanup yes

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

X11Forwarding yes
X11DisplayOffset 10
PrintMotd no
PrintLastLog yes
TCPKeepAlive yes
#UseLogin no

#MaxStartups 10:30:60
#Banner /etc/issue.net

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*

# for chroot
Subsystem sftp /usr/lib/openssh/sftp-server

# Set this to 'yes' to enable PAM authentication, account processing,
# and session processing. If this is enabled, PAM authentication will
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication.  Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# the setting of "PermitRootLogin without-password".
# If you just want the PAM account and session checks to run without
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
UsePAM yes

AllowUsers dinath yoann pascal littleboy62

Match Group littleboy62
         ChrootDirectory /var/www/littleboy62
         ForceCommand internal-sftp
         AllowTCPForwarding no
         X11Forwarding no

Si tu utilises une authentification par clefs, il est nécessaire que les permissions du répertoire prsonnel et de .ssh soient correctes donc non totalement permissives. Remez ces permissions correctement (cf man ssh ou plusieurs fils pour voir lesquelles)

François a raison, c’est souvent là que ça coince.
~/.ssh doit être en 700
~/.ssh/id_rsa doit être en 600
Sinon, il y a refus de connexion;

Salut,

root@alexandre:/home/dinath# su littleboy62
littleboy62@alexandre:/home/dinath$ ls ~/.ssh
ls: impossible d'accéder à /var/www/littleboy62/.ssh: Aucun fichier ou dossier de ce type

Je crois que le problème viendrait de là…

root@alexandre:/home/dinath# find / -name '.ssh'
/home/dinath/.ssh

Je vais supprimer l’utilisateur et le re-créer pour re-généré le .ssh.

Y’a quelque chose que je ne comprends pas…

Y’a que moi qui ai un “.ssh”, pourtant j’ai d’autres utilisateurs. Dernièrement j’ai voulu chroot un utilisateur dans son dossier dans /var/www/… même erreur. Mais là encore tout fonctionne dans /home/utilisateur.

dinath@Dinath:~$ ssh pascal@security-helpzone.com
pascal@security-helpzone.com's password: 
This service allows sftp connections only.
Connection to security-helpzone.com closed.

dinath@Dinath:~$ sftp pascal@security-helpzone.com
pascal@security-helpzone.com's password: 
Connected to security-helpzone.com.
sftp> pwd
Remote working directory: /
Sep 27 12:10:27 alexandre sshd[22244]: Accepted password for pascal from 78.112.96.13 port 45709 ssh2
Sep 27 12:10:27 alexandre sshd[22244]: pam_unix(sshd:session): session opened for user pascal by (uid=0)
Sep 27 12:10:27 alexandre sshd[22248]: Received disconnect from 78.112.96.13: 11: disconnected by user
Sep 27 12:10:27 alexandre sshd[22244]: pam_unix(sshd:session): session closed for user pascal

Sep 27 12:11:16 alexandre sshd[22257]: Accepted password for pascal from 78.112.96.13 port 45711 ssh2
Sep 27 12:11:16 alexandre sshd[22257]: pam_unix(sshd:session): session opened for user pascal by (uid=0)
Sep 27 12:11:16 alexandre sshd[22267]: subsystem request for sftp by user pascal

Encore merci.

J’ai réussi :wink:

chmod 755 /var/www

Tout simplement… d’où les erreurs.

Merci à tous pour votre aide !