Serveur sftp +rssh+chroot

dans le tuto ils disent :
en local

Testons tout ça directement sur le serveur :

–> sur squeeze:

$ sftp -P 666 machin@localhost

Après avoir entré votre mot de passe, si tout va bien, vous devez avoir une invite de commande :

sftp>

donc dans le terminal je tape ceci :

sftp -P 14147 *****@localhost

voici la réponse :

ssh: connect to host localhost port 14147: Connection refused
Couldn't read packet: Connection reset by peer

est-ce juste à cause que mon port 14147 n’est pas ouvert, ou cela ne dérange pas en local

As-tu des règles iptables ou/et fail2ban qui pourraient intervenir ?
Si iptables, envoie :

# iptables-save

fail to ban – non installer, et pour iptables j’ignore ce que c’est :017

Quel est le port utilisé par le service sshd ?

cat /etc/ssh/sshd_config | grep Port

Généralement, c’est le port 22


Tu pourrais nous donner un lien vers ce tuto ?

Merci

root@localhost:/home/daniel# 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 666
# 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
#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 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

# 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
#utilisateurs autorisés
AllowUsers thorhyeux
AllowUsers jessie

isalo.org/wiki.debian-fr/Se … h%2Bchroot

Bon ben alors, puisque le port indiqué dans /etc/ssh/sshd_config est 666, entre ce que te conseillait le tuto :

sftp -P 666 *****@localhost

Bien sûr, remplace les ***** par le nom de un des utilisateurs que tu avais créé (thorhyeux ou jessie)

merci je me sens lourd :blush:
bon voila ce que me dit maintenant :

daniel@localhost:~$ sftp -P 666 jessie@localhost
The authenticity of host '[localhost]:666 ([::1]:666)' can't be established.
ECDSA key fingerprint is e6:d1:ec:d6:da:bd:3d:45:c2:24:06:60:26:78:b5:d9.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '[localhost]:666' (ECDSA) to the list of known hosts.
jessie@localhost's password: 
Connection closed

T’inquiète pas…

=============
Ce qui suit est tout-à fait normal, il viens de te proposer d’ajouter ce serveur à la liste des serveurs connus,
donc il ne te le redemandera pas la fois suivante.

Et là, il l’ajoute à la liste vu que tu as répondu yes:

Donc, jusque là tout va bien.

===============
Par contre, là

On a l’impression que le mot de passe a été refusé ou que la connexion s’est coupée…

===============
Essaie avec l’option “-v” => (verbeuse) pour voir :

sftp -v -P 666 jessie@localhost
daniel@localhost:~$ sftp -v -p 666 jessie@localhost
OpenSSH_6.0p1 Debian-4, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 666 [0.0.2.154] port 22.
debug1: connect to address 0.0.2.154 port 22: Invalid argument
ssh: connect to host 666 port 22: Invalid argument
Couldn't read packet: Connection reset by peer

pourquoi il parle toujour du port 22 il me semble que c’est le 666 ?

essaie plutôt avec un “P” majuscule

sftp -v -P 666 jessie@localhost
daniel@localhost:~$ sftp -v -P 666 jessie@localhost
OpenSSH_6.0p1 Debian-4, OpenSSL 1.0.1e 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to localhost [::1] port 666.
debug1: Connection established.
debug1: identity file /home/daniel/.ssh/id_rsa type -1
debug1: identity file /home/daniel/.ssh/id_rsa-cert type -1
debug1: identity file /home/daniel/.ssh/id_dsa type -1
debug1: identity file /home/daniel/.ssh/id_dsa-cert type -1
debug1: identity file /home/daniel/.ssh/id_ecdsa type -1
debug1: identity file /home/daniel/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.0p1 Debian-4
debug1: match: OpenSSH_6.0p1 Debian-4 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_6.0p1 Debian-4
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: server->client aes128-ctr hmac-md5 none
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: sending SSH2_MSG_KEX_ECDH_INIT
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ECDSA e6:d1:ec:d6:da:bd:3d:45:c2:24:06:60:26:78:b5:d9
debug1: Host '[localhost]:666' is known and matches the ECDSA host key.
debug1: Found key in /home/daniel/.ssh/known_hosts:2
debug1: ssh_ecdsa_verify: signature correct
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/daniel/.ssh/id_rsa
debug1: Trying private key: /home/daniel/.ssh/id_dsa
debug1: Trying private key: /home/daniel/.ssh/id_ecdsa
debug1: Next authentication method: password
jessie@localhost's password: 
debug1: Authentication succeeded (password).
Authenticated to localhost ([::1]:666).
debug1: channel 0: new [client-session]
debug1: Requesting [no-more-sessions@openssh.com](mailto:no-more-sessions@openssh.com)
debug1: Entering interactive session.
debug1: Sending environment.
debug1: Sending env LANG = fr_CA.UTF-8
debug1: Sending subsystem: sftp
debug1: client_input_channel_req: channel 0 rtype exit-status reply 0
debug1: client_input_channel_req: channel 0 rtype [eow@openssh.com](mailto:eow@openssh.com) reply 0
debug1: channel 0: free: client-session, nchannels 1
debug1: fd 0 clearing O_NONBLOCK
Transferred: sent 1864, received 1600 bytes, in 0.0 seconds
Bytes per second: sent 54491.6, received 46773.9
debug1: Exit status 1
Connection closed

Jusqu’à la saisie du mot de passe, tout va bien.
donc, côté “sshd”, tout va bien.

Il reste donc à vérifier :
/etc/rssh.conf et la création du chroot.

Bon, envoie moi le contenu de /etc/rssh.conf :

cat /etc/rssh.conf

Merci.

EDIT:
je suis en train de faire la manip du tuto et j’ai des problèmes avec le script “copie_binaire”.

Tout s’est-il bien passé chez toi du côté de l’exécution de ce script ?

daniel@localhost:~$ cat /etc/rssh.conf
logfacility = LOG_USER
allowsftp
umask = 066
chrootpath = "/home/sftp"

il me semble que oui

nb. :

#!/bin/bash
install -D $1 $2$1
for i in `ldd $1 | grep -o '/[^[:space:]]*'`; do 
       if  ! -e $2$i ]; then install -D $i $2$i; fi
done

à enlever de trop:
 

Merci pour le dernier retour.

Tout est correct dans le fichier /etc/rssh.conf


if [ ! -e $2$i ]; then install -D $i $2$i; fi

j’ai même pas fait attention,
il va falloir corriger ça dans le tuto (qui est excellent d’ailleurs).
EDIT: Correction faite dans le tuto.


Pourrais-tu vérifier que le contenu de ton dossier /home/sftp est le même que le mien avec la commande suivante :

ls -R /home/sftp

ce qui devrait donner:

lib  lib64  usr

/home/sftp/lib:
x86_64-linux-gnu

/home/sftp/lib/x86_64-linux-gnu:
libbsd.so.0  libc.so.6  libtinfo.so.5

/home/sftp/lib64:
ld-linux-x86-64.so.2

/home/sftp/usr:
bin  lib

/home/sftp/usr/bin:
sftp

/home/sftp/usr/lib:
x86_64-linux-gnu

/home/sftp/usr/lib/x86_64-linux-gnu:

il semble y avoir plusieurs différences :

/home/sftp:
dev  etc  lib  lib64  usr

/home/sftp/dev:
null

/home/sftp/etc:
passwd

/home/sftp/lib:
x86_64-linux-gnu

/home/sftp/lib/x86_64-linux-gnu:
libbsd.so.0  libc.so.6  libnss_files.so.2  libtinfo.so.5

/home/sftp/lib64:
ld-linux-x86-64.so.2

/home/sftp/usr:
bin  lib

/home/sftp/usr/bin:
sftp

/home/sftp/usr/lib:
openssh  x86_64-linux-gnu

/home/sftp/usr/lib/openssh:
sftp-server

/home/sftp/usr/lib/x86_64-linux-gnu:
libedit.so.2
daniel@localhost:~$

Pour les quelques différences, c’est normal vu que je n’avais pas encore créé le répertoire dev et autres détails.
J’aurais dû terminer le tuto avant de te demander ça.
Désolé. Mais ça donne quand même une idée.


Pourrais-tu me transmettre le retour de la commande suivante ? (histoire de vérifier les attributs des fichiers)

ls -l /home/sftp/dev /usr/lib/rssh/rssh_chroot_helper /home/sftp/etc/passwd
daniel@localhost:~$ ls -l /home/sftp/dev /usr/lib/rssh/rssh_chroot_helper /home/sftp/etc/passwd
-rw-r--r-- 1 root root   132 aoû 18 19:20 /home/sftp/etc/passwd
-rwxr-xr-x 1 root root 30760 nov 27  2012 /usr/lib/rssh/rssh_chroot_helper

/home/sftp/dev:
total 0
crw-rw-rw- 1 root root 1, 3 aoû 18 19:02 null

Merci

Il faudrait aussi vérifier la présence des utilisateurs dans le fichier passwd du chroot:

grep thorhyeux /home/sftp/etc/passwd
grep jessie /home/sftp/etc/passwd
daniel@localhost:~$ grep thorhyeux /home/sftp/etc/passwd
thorhyeux:x:1001:1001:,,,:/home/thorhyeux:/usr/bin/rssh

daniel@localhost:~$ grep jessie /home/sftp/etc/passwd
jessie:x:1002:1002:jessie,2,,:/home/jessie:/usr/bin/rssh