Connection refused  [RESOLU]

Votre Apache se cache, votre Pi gémit, votre SoC fume ? La panne quoi ! C'est ici que vous trouverez sans doute une solution... Sinon du réconfort :)

Modérateurs : Francois, maxty01

marseillois
Messages : 88
Enregistré le : ven. 10 juin 2016 14:18

Connection refused

Message par marseillois » mar. 19 mars 2019 10:52

Bonjour à tous

Après beaucoup de recherches et de modifications et corrections, je me retrouve dans une impasse et je dois faire appel à votre aide

Je dispose d’un Portable sous debian 9 et d’un Raspberry Pi 3 (carte noobs avec Raspbian Strech & LibreElec), tous deux sur mon réseau local à travers une box SFR

Je souhaite gérer le Pi sur l’écran de mon Portable

J’ai donc créé une connexion ssh avec un systéme de clefs publique et privée, et après de nombreux essais et corrections diverses, à l’aide de conseils trouvés sur Internet, parfois contradictoires car il n’est pas toujours faciles de les dater, je suis enfin arrivé à établir une connexion sécurisée où le systéme n’a établi la connexion qu’après m’avoir demander la passphrase : j’ai même pu à cette occasion controler raspi-config à l’écran de mon portable

Et pourtant, lorsque j’ai relancé la connexion, le lendemain, à la réouverture de mon système, qui n’a subi depuis aucune modification, voilà le résultat :

Code : Tout sélectionner

gerard@gerard-L50:~$ ssh -v pi@192.168.1.87
OpenSSH_7.4p1 Debian-10+deb9u6, OpenSSL 1.0.2r  26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.87 [192.168.1.87] port 28841.
debug1: connect to address 192.168.1.87 port 28841: Connection refused
ssh: connect to host 192.168.1.87 port 28841: Connection refused
gerard@gerard-L50:~$ 
A toutes fins utiles , voici les fichiers de configuration du ssh tels qu’ils étaient lorsque j’ai pu établir la connexion et tels qu’ils sont toujours

Fichier /etc/ssh/ssh_config

Code : Tout sélectionner

gerard@gerard-L50:~$ su
Mot de passe : 
root@gerard-L50:/home/gerard# nano /etc/ssh/ssh_config
# This is the ssh client system-wide configuration file.  See
# ssh_config(5) for more information.  This file provides defaults for
# users, and the values can be changed in per-user configuration files
# or on the command line.

# Configuration data is parsed as follows:
#  1. command line options
#  2. user-specific file
#  3. system-wide file
# Any configuration value is only changed the first time it is set.
# Thus, host-specific definitions should be at the beginning of the
# configuration file, and defaults at the end.

# Site-wide defaults for some commonly used options.  For a comprehensive
# list of available options, their meanings and defaults, please see the
# ssh_config(5) man page.

Host *
#   ForwardAgent no
#   ForwardX11 no
#   ForwardX11Trusted yes
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
    Port 28841
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3$
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
fichier /etc/ssh/sshd

Code : Tout sélectionner

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 28841
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

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

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

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

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

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

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
Merci d'avance pour votre attention

domi
Administrateur
Messages : 3230
Enregistré le : mer. 17 sept. 2014 18:12
Localisation : Seine et Marne

Re: Connection refused

Message par domi » mar. 19 mars 2019 18:50

Bonjour,

Beaucoup de chose que je ne comprend pas, tu sembles donner les fichiers de configuration de "gerard" alors que tu fais une connexion sur "pi". De plus, c'est quoi ce port 28841 ?
Donc si tu bricoles les connexion SSH de gerard sans avoir redémarré ssh de gerard, la connexion n'est pas modifiée. Au redémarrage du système, ça ne fonctionne plus car il prend la nouvelle configuration.
Si gerard est ton client, il ne faut rien modifier dans sa configuration ssh.
La config se passe sur PI (si c'est bien lui le serveur), et redémarrer le ssh après chaque modification.

Dans un premier temps, remettre les fichier d'origine du client "Gerard", puis donner ici les fichiers de conf du SSH de PI (du Raspberry).
Passionné de Raspberry, Arduino, ESP8266, ESP32, et objets connectés :
Spécial débutant, concevez vous-même votre domotique DIY : https://www.youtube.com/c/DomoticDIY
Conception d'une station météo DIY, et envoi des infos à votre Domotique.

marseillois
Messages : 88
Enregistré le : ven. 10 juin 2016 14:18

Re: Connection refused

Message par marseillois » mer. 20 mars 2019 14:28

Salut domi, et merci pour ta réponse

Voici les résultats que j'ai obtenu

1 / gerard est bien le client (mon satellite) et pi le serveur (le rasp)

2 / Il me semble bien que le ssh serveur dont il est question dans ma demande est celui du pi
Pour le portable (le client ) je n’ai pas de fichier sshd :
gerard@gerard-L50:~$ su
Mot de passe :
root@gerard-L50:/home/gerard# nano /etc/ssh/sshd
root@gerard-L50:/home/gerard#
Le fichier /etc/ssh/sshd obtenu est vide

3 / le début du fichier /etc/ssh/sshd de ce que je pense être le fichier du serveur précise “This is the sshd server system-wide configuration file” ce qui ma conforté dans ma conclusion OK ??

4 / j’ai remplacé le port 22 du client par 28841 suite aux multiples conseils trouvés sur internet à ce sujet

5 / J’ai remis le fichier client /etc/ss/ssh_config à l’état initial : en fait seul le port était modifié

GNU nano 2.7.4 Fichier : /etc/ssh/ssh_config

Code : Tout sélectionner

#   ForwardX11 no
#   ForwardX11Trusted yes
#   RhostsRSAAuthentication no
#   RSAAuthentication yes
#   PasswordAuthentication yes
#   HostbasedAuthentication no
#   GSSAPIAuthentication no
#   GSSAPIDelegateCredentials no
#   GSSAPIKeyExchange no
#   GSSAPITrustDNS no
#   BatchMode no
#   CheckHostIP yes
#   AddressFamily any
#   ConnectTimeout 0
#   StrictHostKeyChecking ask
#   IdentityFile ~/.ssh/identity
#   IdentityFile ~/.ssh/id_rsa
#   IdentityFile ~/.ssh/id_dsa
#   IdentityFile ~/.ssh/id_ecdsa
#   IdentityFile ~/.ssh/id_ed25519
#   Port 22
#   Protocol 2
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3$
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
#   VisualHostKey no
#   ProxyCommand ssh -q -W %h:%p gateway.example.com
#   RekeyLimit 1G 1h
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
Puis je redémarre ssh :

Code : Tout sélectionner

gerard@gerard-L50:~$ su
Mot de passe : 
root@gerard-L50:/home/gerard# service ssh restart
root@gerard-L50:/home/gerard# 
[code]

Et enfin 
[code]gerard@gerard-L50:~$ ssh -v pi@192.168.1.87
OpenSSH_7.4p1 Debian-10+deb9u6, OpenSSL 1.0.2r  26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.87 [192.168.1.87] port 22.
debug1: Connection established.
debug1: identity file /home/gerard/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.3
debug1: match: OpenSSH_7.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.87:22 as 'pi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:JdvvoYoebCRyoUP9XwJBqj2jHTkKFuzHDeRqCXWpQT4
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!     @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
SHA256:JdvvoYoebCRyoUP9XwJBqj2jHTkKFuzHDeRqCXWpQT4.
Please contact your system administrator.
Add correct host key in /home/gerard/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/gerard/.ssh/known_hosts:3
  remove with:
  ssh-keygen -f "/home/gerard/.ssh/known_hosts" -R 192.168.1.87
ECDSA host key for 192.168.1.87 has changed and you have requested strict checking.
Host key verification failed.
gerard@gerard-L50:~$ 
Pourtant Le fichier existe et , ouvert avec nano, montre 4 clefs dont 2 apparamment identiques (apparamment parce que je n’arrive pas à tout lire, la clef dépasse la longueur de la page

Je tente la correction suggérée :

Code : Tout sélectionner

gerard@gerard-L50:~$ ssh-keygen -f "/home/gerard/.ssh/known_hosts" -R 192.168.1.87
# Host 192.168.1.87 found: line 3
/home/gerard/.ssh/known_hosts updated.
Original contents retained as /home/gerard/.ssh/known_hosts.old
gerard@gerard-L50:~$ 
Puis je relance :

Code : Tout sélectionner

gerard@gerard-L50:~$ ssh -v pi@192.168.1.87
OpenSSH_7.4p1 Debian-10+deb9u6, OpenSSL 1.0.2r  26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.87 [192.168.1.87] port 22.
debug1: Connection established.
debug1: identity file /home/gerard/.ssh/id_rsa type 1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /home/gerard/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Debian-10+deb9u6
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.3
debug1: match: OpenSSH_7.3 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.1.87:22 as 'pi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256@libssh.org
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:JdvvoYoebCRyoUP9XwJBqj2jHTkKFuzHDeRqCXWpQT4
The authenticity of host '192.168.1.87 (192.168.1.87)' can't be established.
ECDSA key fingerprint is SHA256:JdvvoYoebCRyoUP9XwJBqj2jHTkKFuzHDeRqCXWpQT4.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added '192.168.1.87' (ECDSA) to the list of known hosts.
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<rsa-sha2-256,rsa-sha2-512>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Offering RSA public key: /home/gerard/.ssh/id_rsa
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Trying private key: /home/gerard/.ssh/id_dsa
debug1: Trying private key: /home/gerard/.ssh/id_ecdsa
debug1: Trying private key: /home/gerard/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: password
pi@192.168.1.87's password: 
debug1: Authentications that can continue: publickey,password,keyboard-interactive
Permission denied, please try again.
pi@192.168.1.87's password: 
debug1: Authentications that can continue: publickey,password,keyboard-interactive
Permission denied, please try again.
pi@192.168.1.87's password: 
Authentication failed.
gerard@gerard-L50:~$ 
Là j’ai essayé la passphrase que j’attendais que la procédure me réclame, puis les deux mots de passe possibles, sans succès : je me retrouve avec mes difficultés initiales et je ne comprends pas

Peux tu continuer à m'aider
Merci d'avance

marseillois
Messages : 88
Enregistré le : ven. 10 juin 2016 14:18

Re: Connection refused

Message par marseillois » mer. 20 mars 2019 15:01

Une précision complémentaire

Je ne peux pas donner le SSHD du serveur puisque je ne peux pas m'y connecter

La dernière version utilisée, après mes corrections (dont le port 28841) est

Code : Tout sélectionner

fichier /etc/ssh/sshd
#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

Port 28841
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:
#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

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

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication yes
#PermitEmptyPasswords no

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

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

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

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server

domi
Administrateur
Messages : 3230
Enregistré le : mer. 17 sept. 2014 18:12
Localisation : Seine et Marne

Re: Connection refused

Message par domi » mer. 20 mars 2019 19:00

Bonjour,

Si le fichier "/etc/ssh/sshd_config" (et non "/etc/ssh/sshd") que tu donnes est bien celui du Rpi, il faut donc te connecter via le port 28841

Code : Tout sélectionner

ssh pi@192.168.1.87:28841
Puis saisir le mot de passe de l'utilisateur "pi". Cela doit fonctionner car vu ton fichier sshd_config, tu ne l'as pas interdit.

Dans un premier temps il faut effectuer une connexion par mot de passe.
Dans un second temps, il faudra faire l'échange de clé (avec ou sans passphrase, a ton choix), puis tester la connexion par clé.
En dernier lieu, lorsque tout est fonctionnel, on pourra interdire l'accès par mot de passe afin de n'autoriser que l'échange de clé.

Premier test donc : la connexion que je t'ai donnée ci-dessus.
Passionné de Raspberry, Arduino, ESP8266, ESP32, et objets connectés :
Spécial débutant, concevez vous-même votre domotique DIY : https://www.youtube.com/c/DomoticDIY
Conception d'une station météo DIY, et envoi des infos à votre Domotique.

marseillois
Messages : 88
Enregistré le : ven. 10 juin 2016 14:18

Re: Connection refused

Message par marseillois » mer. 20 mars 2019 20:45

Salut domi

Voici le résultat de mon essai

Code : Tout sélectionner

gerard@gerard-L50:~$ ssh -v pi@192.168.1.87:28841
OpenSSH_7.4p1 Debian-10+deb9u6, OpenSSL 1.0.2r  26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
ssh: Could not resolve hostname 192.168.1.87:28841: Name or service not known
gerard@gerard-L50:~$ 
Que puis je faire ??
Merci d'avance

domi
Administrateur
Messages : 3230
Enregistré le : mer. 17 sept. 2014 18:12
Localisation : Seine et Marne

Re: Connection refused

Message par domi » jeu. 21 mars 2019 05:51

C'est donc que le Rpi n'est pas configuré sur le port 28841 mais toujours sur le 22.

Code : Tout sélectionner

ssh pi@192.168.1.87
Puis connexion avec le mot de passe de Pi (attention pour le mot de passe, suivant la config le clavier peut-être en "QUERTY")
Passionné de Raspberry, Arduino, ESP8266, ESP32, et objets connectés :
Spécial débutant, concevez vous-même votre domotique DIY : https://www.youtube.com/c/DomoticDIY
Conception d'une station météo DIY, et envoi des infos à votre Domotique.

marseillois
Messages : 88
Enregistré le : ven. 10 juin 2016 14:18

Re: Connection refused

Message par marseillois » jeu. 21 mars 2019 12:03

Bonjour domi,
Voilà les résultats de mes essais suite à ta denière proposition

Code : Tout sélectionner

gerard@gerard-L50:~$ ssh -v pi@192.168.1.87
OpenSSH_7.4p1 Debian-10+deb9u6, OpenSSL 1.0.2r  26 Feb 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.1.87 [192.168.1.87] port 22.
debug1: connect to address 192.168.1.87 port 22: Connection refused
ssh: connect to host 192.168.1.87 port 22: Connection refused
Pour éclairer notre discussion, je suis allé interroger le fichier /etc/ssh/sshd_config de mon Rpi à l’écran de ma télé :
1ere constatation, il ne m’a pas demandé de mot de passe
je te propose une copie de ce fichier ci après, à toutes fins utiles

Code : Tout sélectionner

#       $OpenBSD: sshd_config,v 1.100 2016/08/15 12:32:04 naddy Exp $

# This is the sshd server system-wide configuration file.  See
# sshd_config(5) for more information.

# This sshd was compiled with PATH=/usr/bin:/bin:/usr/sbin:/sbin

# The strategy used for options in the default sshd_config shipped with
# OpenSSH is to specify options with their default value where
# possible, but leave them commented.  Uncommented options override the
# default value.

#Port 22
#AddressFamily any
#ListenAddress 0.0.0.0
#ListenAddress ::

#HostKey /etc/ssh/ssh_host_rsa_key
#HostKey /etc/ssh/ssh_host_ecdsa_key
#HostKey /etc/ssh/ssh_host_ed25519_key

# Ciphers and keying
#RekeyLimit default none

# Logging
#SyslogFacility AUTH
#LogLevel INFO

# Authentication:

#LoginGraceTime 2m
#PermitRootLogin prohibit-password
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.

#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

#AuthorizedPrincipalsFile none

#AuthorizedKeysCommand none
#AuthorizedKeysCommandUser nobody

# For this to work you will also need host keys in /etc/ssh/ssh_known_hosts
#HostbasedAuthentication no
# Change to yes if you don't trust ~/.ssh/known_hosts for
# HostbasedAuthentication
#IgnoreUserKnownHosts no
#Don’t read the user’s ~/.rhostsand ~/.rosts files
#IgnoreRhosts yes
# To disable tunneled clear text passwords, change to no here !
#PasswordAuthentication yes
#Permit EmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

# 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

#AllowAgentForwarding yes
#AllowTcpForwarding yes
#GatewayPorts no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /var/run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

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

# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
Merci pour ton attention et ta fidélité

Là je m'absente quelques jours dans un trou perdu sans internet.
Je reprendrai nos échanges dès mon retour
Cordialement

domi
Administrateur
Messages : 3230
Enregistré le : mer. 17 sept. 2014 18:12
Localisation : Seine et Marne

Re: Connection refused

Message par domi » jeu. 21 mars 2019 13:59

Le fichier semble correct, l'écoute est bien sur le port 22.
Si tu fais sur le Rpi un :

Code : Tout sélectionner

sudo netstat -anp | grep sshd
Peux tu donner le résultat afin de vérifier que le Rpi écoute bien sur l'IP et sur le port 22 en ipv4.

Pour ôter toute doute, il n'y a pas de Firewall installé sur le Rpi ?

Vu que tu n'es pas là quelques jours, si une idée me viens je la posterai.
Passionné de Raspberry, Arduino, ESP8266, ESP32, et objets connectés :
Spécial débutant, concevez vous-même votre domotique DIY : https://www.youtube.com/c/DomoticDIY
Conception d'une station météo DIY, et envoi des infos à votre Domotique.

Artemus24
Raspinaute
Messages : 1077
Enregistré le : ven. 15 sept. 2017 19:15

Re: Connection refused

Message par Artemus24 » ven. 22 mars 2019 01:51

Salut à tous.

Si vous utilisez une connexion SSH sécurisé, il vous faut connaitre les points suivants :
--> l'adresse IP du destinataire,
--> le compte auquel vous désirez accéder,
--> les clefs qui auront été créés au préalable.

1) vous devez créer vos clefs en utilisant Putty.
Il existe un utilitaire qui se nomme "puttygen.exe"
Je vous laisse chercher sur le net comment l'utiliser.

A l'issu de cela, vous aurez trois fichiers, qui sont :
--> "public_key",
--> "private_key.ppk",
--> "authorized_keys".

2) dans le compte destinataire de la raspberry, par exemple "pi", vous devez créer le répertoire ".ssh" (attention au point devant) à la racine.
Autrement dit, vous devez avoir le chemin "/home/pi/.ssh".

3) vous deplacez le fichier "authorized_keys" en le mettant dans le répertoire ".ssh".

4) Vous devez ensuite attribuer les droits :
--> pour le répertoire "chmod 700 .ssh".
--> pour le fichier "chmod 400 authorized_keys".
sans les droits, votre connexion peut-être rejetée.

5) vous redémarre votre raspberry pi.

6) dans l'émetteur, vous devez placer votre fichier "Private_key.ppk" de manière à ce qu'il soit bien sécurisé.
Dans l'accès par Putty, vous devez faire référence à ce fichier, sinon votre connexion ne sera pas sécurisée, voire rejetée.
Comme j'utilise windows, je pense qu'il existe la même chose sous débian (je parle de votre ordinateur satellite).

7) Vous entrez dans Putty et vous renseignez les points suivants :
--> session, dans Host Name, vous mettez l'adresse IP.
--> window : appearance, vous définissez la largeur de votre écran. J'ai mis 156, 48.
--> window : behaviour, vous nommez le nom de votre écran. J'ai mis pour le compte "pi" : "Raspberry Wifi Pi".
--> connection : data, vous renseignez le compte auquel vous désirez accéder. Je mets "Pi".
--> connection : rlogin, je mets aussi "Pi".
--> SSH : auth, je renseigne le chemin vers le fichier "private_key.ppk".

Quand tout est bien renseigné, je vais dans :
--> session, logging : vous attibuez un nom (par exemple Raspberry) et vous sauvegardez.

8) pour me connecter (depuis windows) à une session vers ma raspberry, pour le compte "pi", je tape :
--> "C:\Program Files\PuTTY\putty.exe" -load Raspberry

Ce qui se trouve après le "load" est la sauvegarde du § 8).

Remarques :

a) ne changez pas le port 22. Si votre connexion est sécurisée, cela ne sert à rien.

b) je ne vois nulle part, une quelconque référence à votre fichier "private_key.ppk" lors d'une connexion sur votre ordi satellite.

c) il est inutile de venir bidouiller dans les fichiers "/etc/ssh/ssh_config" et "/etc/ssh/sshd". Le problème ne se pose pas là.

d) ne pas utiliser la passphrase qui va plus vous gêner qu'autre chose.

e) dans l'ordinateur émetteur, avez-vous une règle dans le pare-feu pour putty et le port 22 ?

f) pour chaque compte destinataire de la raspberry, vous devez créer à nouveau le répertoire ".ssh".

g) pour accéder au compte "root", je ne me souviens plus trop, mais vous devez dans un fichier de configuration, donner l'autorisation de le faire.
Par défaut, l'accès est interdit, par mesure de sécurité au compte "root", par "putty".

@+
RPI4B/8GB + Argon FanHAt
Rpi3A+, Rpi3B+
RPi 2B + Joy-It I2C Serial 20x4 2004 LCD Module
RPi 2B + PIM273 Unicorn HAT HD 16x16 Leds RGB
RPi0v1.3, RPi0W + LibreElec/Kodi, Rpi0WH + Tuner TV HAT
NodeMCU ESP32

Répondre

Retourner vers « En panne ? »