Contenu | Rechercher | Menus

Annonce

Si vous avez des soucis pour rester connecté, déconnectez-vous puis reconnectez-vous depuis ce lien en cochant la case
Me connecter automatiquement lors de mes prochaines visites.

À propos de l'équipe du forum.

#1 Le 14/08/2014, à 23:55

saintjimmy

[Résolu] Utilisateur SFTP bloqué dans son répertoire

Bonjour à tous,

Je cherche a créer un utilisateur qui serait bloqué dans son répertoire de transfert de fichier. J'ai créé l’utilisateur bob et le groupe sftpusers puis j'ai modifié mon /etc/ssh/sshd_config comme ceci:

 Subsystem sftp internal-sftp

Match group sftpusers
        ChrootDirectory %h
        X11Forwarding no
         AllowTcpForwarding no
       ForceCommand internal-sftp

Ensuite j'ai créé /home/bob et /home/bob/stockage, le premier appartenant à root avec les droits en 755 et le deuxième appartenant à bob:sftpusers.

Cela fonctionne quand je me connecte je suis bien dans le répertoire et je ne peux pas créer de dossier ailleurs. Cependant je peux naviguer dans toute l'arborescence. Quelqu'un a-t-il un idée pour que l'utilisateur ne puisse pas naviguer ailleurs que chez lui ?

Merci d'avance

Dernière modification par saintjimmy (Le 13/09/2014, à 16:31)


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#2 Le 15/08/2014, à 02:08

Kooothor

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Salut,

C'est le retour de la commande ls -l /home/bob qu'il faut nous donner.

Et lis la réponse de ça : http://askubuntu.com/questions/134425/h … heir-homes
Il faut que /home/bob soit super verrouillé.

@+
~ktr

Hors ligne

#3 Le 05/09/2014, à 07:23

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Je réponds avec pas mal de retard:

Les permissions sur /home/bob:
drwxr-xr-x  3 root                root                4096 sept.  5 07:05 bob

Les permissions sur /home/bob/stockage:
drwxrwxr-x 3 bob     root 4096 sept.  5 08:12 stockage

Au niveau de l'écriture c'est tout bon mais je veux juste que bob ne puisse pas naviguer dans l'arborescence au dessus de son répertoire.


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#4 Le 05/09/2014, à 07:53

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Normalement ce que tu as fait est correct et bob ne devrait pas pouvoir sortir de /home/bob
As-tu bien pensé à relancer le service ssh après tes modifications :

sudo service ssh restart

/home/bob est-il bien le dossier personnel de bob :

cat /etc/passwd | grep bob

Autre vérification :

ssh bob@serveur

-> normalement bob se fait jeter avec comme message : This service allows sftp connections only.

Hors ligne

#5 Le 05/09/2014, à 08:14

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Oui j'ai bien redémarré le service SSH

Le résultat de la commande demandée:

cat /etc/passwd | grep bob
bob:x:1000:1000::/home/bob/stockage:/bin/false

Pour la connexion SSH avec bob ça me dit juste que la connexion a été fermée après m'avoir affiché le message d'accueil.


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#6 Le 05/09/2014, à 08:19

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Le dossier personnel de bob n'est pas correct…

sudo usermod -d /home/bob bob

et rendre à bob ce qui appartient à bob :

sudo chown -R bob:bob /home/bob/stockage

Dernière modification par bruno (Le 05/09/2014, à 08:21)

Hors ligne

#7 Le 05/09/2014, à 08:26

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

C'est fait merci de l'avoir remarqué j'étais passé à coté !
Ceci dit ça ne fonctionne toujours pas, bob peut toujours remonter à la racine et se balader ou il veut.


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#8 Le 05/09/2014, à 08:34

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Donne-nous le résultat de :

groups bob

Hors ligne

#9 Le 05/09/2014, à 09:00

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

groups bob
bob : bob sftpusers

Dernière modification par saintjimmy (Le 05/09/2014, à 09:00)


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#10 Le 05/09/2014, à 09:29

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Alors je ne comprends pas d'où vient le souci hmm
Le fait que tu n'aies pas de message « This service allows sftp connections only » quand tu tentes une connexion SSH me laissait penser que ta directive « Match group sftpusers » n'était pas prise en compte (d'où ma question sur l'appartenance de bob à sftpusers).
Tu peux éventuellement tester en remplaçant par : Match user bob

Il faudrait voir le contenu complet de sshd_config

Dernière modification par bruno (Le 05/09/2014, à 09:30)

Hors ligne

#11 Le 05/09/2014, à 10:21

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Et voilà:

# 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
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
#PermitRootLogin without-password
PermitRootLogin yes
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 no
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_*

 
AllowUsers root bob

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

Match group sftpusers
        ChrootDirectory %h
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp


# 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

Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#12 Le 05/09/2014, à 11:17

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

À part le PermiRootLogin sur yes il n'y a rein qui me choque et ta configuration doit fonctionner.

Avec :

sftp bob@ton_serveur

tu peux vraiment voir toutes l’arborescence du serveur ?

Hors ligne

#13 Le 05/09/2014, à 13:25

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Oui je confirme et je ne comprends pas non plus :-)


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#14 Le 05/09/2014, à 13:42

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Bon il y a un truc que je n'avias pas remarqué : ton bloc Match n'est pas fermé et la directive UsePAm est située après ce bloc. Du coup cela ne devrait même pas fonctionner…

Essaie ainsi :


#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

# 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

Match group sftpusers
        ChrootDirectory %h
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp
Match

Hors ligne

#15 Le 05/09/2014, à 14:03

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Ok j'ai essayé cela et plus moyen de me connecter avec bob...
Et bizarrement rien dans auth.log ou syslog


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#16 Le 06/09/2014, à 06:50

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Je pense que c'est l'ordre de tes directives dans sshd_config, voici ta config remise en ordre

# 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
HostKey /etc/ssh/ssh_host_ecdsa_key
HostKey /etc/ssh/ssh_host_ed25519_key
#Privilege Separation is turned on for security
UsePrivilegeSeparation yes

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

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
#PermitRootLogin without-password
PermitRootLogin yes
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 no
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_*


#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp

# 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 root bob

Match group sftpusers
        ChrootDirectory %h
        X11Forwarding no
        AllowTcpForwarding no
        ForceCommand internal-sftp
Match

Après modification de ta configuration, teste là avec :

sudo sshd -t

Hors ligne

#17 Le 13/09/2014, à 09:38

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

J'ai remis tous ça dans l'ordre par contre si je termine par "Match" j'ai ce message :

One or more attributes required for Match
/etc/ssh/sshd_config line 103: Bad Match condition

Je l'ai enlevé et je n'ai pas de soucis ! Tout fonctionne parfaitement !

Merci a toi bruno !


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#18 Le 13/09/2014, à 09:41

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

J'ai parlé trop vite: impossible de connecter en root en SSH: seulement le SFTP est autorisé !
Une idée ?


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#19 Le 13/09/2014, à 09:47

jplemoine

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Par défaut, sous ssh, on ne peut pas se connecter en root. Il faut se connecter avec l'utilisateur "normal" et faire un sudo.
Pour plus de détail, voir cette page. (notamment le §4 et la directive PermitRootLogin)

Dernière modification par jplemoine (Le 13/09/2014, à 09:48)


Membre de l'ALDIL (Association Lyonnaise pour le Développement de l'Informatique Libre)
- En pro, après 20 ans de développement, administrateur Linux / Unix depuis Avril 2019.
- En privé, sous Ubuntu-Xubuntu depuis 2009.

Hors ligne

#20 Le 13/09/2014, à 09:51

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Soit root est membre du groupe sftpusers, soit il y a encore une erreur dans ton fichier de configuration. L'erreur que tu signales concernant la directive Match n'est pas normale…

Hors ligne

#21 Le 13/09/2014, à 14:44

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

jplmenoine Merci de ton aide mais le problème ne vient pas de là.

bruno j'ai installé un shell php sur mon serveur web et j'ai pu lire le contenu de /etc/group effectivement j'ai ajouté root au groupe utilisateurs comme un boulet pendant mes tests. Dés que j'ai réussi a régler ça je met à jour le topic.


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#22 Le 13/09/2014, à 16:30

saintjimmy

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

OK c'est bon j'ai pu retirer root du groupe et maintenant tout est OK !
Merci bruno de ton aide précieuse !


Thinkpad X230 & P51
Linux Mint 19.1

Hors ligne

#23 Le 15/11/2014, à 00:11

CyrilLR

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Bonsoir, Désolé de remettre sur le tapis ce problème, Mon symptome est le suivant, l'utilisateur "cedric" ne peut pas se connecter en ssh ni en sftp (via filazilla). J'ai mis mon ssh_config et quelques commande en rapport avec l'utilisateur cedric. J'ai l'impression d'être conforme au indication ci-dessus mais cela ne fonctioonne pas . Root arrive a se connecter en ssh et via sft (via filezilla)

Je suis perdu, Pourriez-vous m'aider ?




Le ssh_config :

# Package generated configuration file
# See the sshd(8) 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 1024

# Logging
SyslogFacility AUTH
LogLevel INFO

# Authentication:
LoginGraceTime 120
PermitRootLogin yes
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_*

#Subsystem sftp /usr/lib/openssh/sftp-server
Subsystem sftp internal-sftp 


UsePAM yes


AllowUsers root cedric atest


Match group sftponly
    ChrootDirectory %h
    X11Forwarding no
    AllowTcpForwarding no
    ForceCommand internal-sftp
Match

La mise a jour de la config ssh (pas d'erreur)

NexOne:/etc/ssh# service ssh reload
[ ok ] Reloading OpenBSD Secure Shell server's configuration: sshd.
NexOne:/etc/ssh#

PUIS Quelque info sur cedric

NexOne:/home# ls -l
total 36
drwxr-xr-x 2 atest  atest     4096 nov.  14 22:39 atest
drwxr-xr-x 2 cedric cedric    4096 nov.  14 21:32 cedric
drwxrwxrwx 9 root   root      4096 nov.  14 20:39 dl
drwxrwxrwx 2 root   download  4096 nov.  14 20:39 dltermine
drwx------ 2 root   root     16384 nov.  11 08:18 lost+found
drwxr-xr-x 3 nexus  nexus     4096 nov.  11 12:24 nexus
NexOne:/home#
NexOne:/home#
NexOne:/home# groups cedric
cedric : download sftponly
NexOne:/home#
NexOne:/home#
NexOne:/home#
NexOne:/home#

Et enfin un extrait de ect/passwd

cedric:x:1001:1002:Cedric J,,,:/home/cedric:/bin/bash

Je n'en peux plus HELP !!

Hors ligne

#24 Le 15/11/2014, à 09:26

bruno

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Enlève le dernier Match à la fin du fichier sshd_config

Hors ligne

#25 Le 15/11/2014, à 13:05

CyrilLR

Re : [Résolu] Utilisateur SFTP bloqué dans son répertoire

Dernier Match enlevé => Mais c'est le même résultat . J'ai fais un test avec nouvel utilisateur créer pour l’occasion (pareil)

Mon system pour info :

NexOne:/etc/ssh# lsb_release -a
No LSB modules are available.
Distributor ID: Debian
Description:    Debian GNU/Linux 7.4 (wheezy)
Release:        7.4
Codename:       wheezy

Hors ligne