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 12/06/2026, à 11:46

iznobe

vérification / configuration accés ssh

Bonjour , j ' aimerais configuré un pi ( serveur ssh ) pour un accès uniquement en local , et vérifier que c ' est effectivement le cas , sauf que je ne vois pas tellement comment faire pour vérifier .

Actuellement ( et théoriquement ) , le fichier " /etc/ssh/sshd_config " est celui par défaut :

iznobe@k-pi3:~ $ cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj 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.

Include /etc/ssh/sshd_config.d/*.conf

#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 ~/.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
#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
iznobe@k-pi3:~ $

ma config est dans le fichier suivant :

iznobe@k-pi3:~ $ cat /etc/ssh/sshd_config.d/config.perso.conf
StrictModes yes
PubkeyAuthentication yes
PasswordAuthentication yes
LoginGraceTime 300
MaxAuthTries 3
PasswordAuthentication no
PermitRootLogin no
AllowUsers iznobe@192.168.1.0/24
iznobe@k-pi3:~ $

est ce que l ' ordre dans lequel on dispose les lignes a une importance ?

Dernière modification par iznobe (Le 12/06/2026, à 12:02)

Hors ligne

#2 Le 15/06/2026, à 12:30

steph810

Re : vérification / configuration accés ssh

Bonjour,
l'ordre na pas d'importance mais dans ton config.perso.conf il y as un doublon -->PasswordAuthentication yes & PasswordAuthentication no

Hors ligne

#3 Le 15/06/2026, à 13:21

O_20_100_O

Re : vérification / configuration accés ssh

Bonjour,
Et aussi, quel est ton choix pour "PasswordAuthentication" ?
Si c'est "no", tu renforces avec  "AuthenticationMethods publickey" et tu ajoutes la clé publique ssh de ceux que tu autorises dans authorized_keys  . Peu importe s'ils sont en local ou distant.

Si c'est "yes" alors tu as une piste ici.

Dernière modification par O_20_100_O (Le 15/06/2026, à 13:21)

Hors ligne

#4 Le 15/06/2026, à 15:04

iznobe

Re : vérification / configuration accés ssh

Bonjour .
Pour le " doublon " , j ' essayais de voir si on pouvait faire : par mot de passe en local uniquement et par clé en provenance d ' ailleurs .


Si c'est "yes" alors tu as une piste ici.

Merci , j ' ai déjà vu cette discussion.



D ' après les tests que j' ai pu faire sur mon pi , il y a certaines choses ( de bases ) que je ne comprends pas :

cat /etc/ssh/sshd_config.d/config.perso.conf
StrictModes yes
PubkeyAuthentication yes
PasswordAuthentication yes
Match Address 192.168.1.0/24,192.168.2.0/24,192.168.10.0/24,192.168.11.0/24
#LoginGraceTime 300
MaxAuthTries 3
PermitRootLogin no
AllowUsers iznobe@192.168.1.0/24

# AllowUsers iznobe@192.168.2.0/24 ne fonctionne pas !!!!!!
# alors que Match Adress permet la connexion
iznobe@k-pi3:~ $

actuellement , avec ce fichier et redémarrage , je ne peux pas me connecter .
il y a demande de mot de passe , mais il est refusé .

Si je commente la ligne : " #AllowUsers iznobe@192.168.1.0/24 " , je redémarre le serveur , et là je peux me connecter ...
si je dé-commente : " #LoginGraceTime 300 " , le serveur ne re-démarre pas :

iznobe@k-pi3:~ $ sudo systemctl restart ssh
Job for ssh.service failed because the control process exited with error code.
See "systemctl status ssh.service" and "journalctl -xe" for details.
iznobe@k-pi3:~ $

Dernière modification par iznobe (Le 15/06/2026, à 15:08)

Hors ligne

#5 Le 15/06/2026, à 15:23

O_20_100_O

Re : vérification / configuration accés ssh

Donc tu veux : par mot de passe en local uniquement et par clé en provenance d ' ailleurs .

Je n'ai jamais essayé mais cela devrait fonctionner :

#En général
PasswordAuthentication no
PubkeyAuthentication yes

#Et si local
Match Address 192.168.1.0/24 ... et les autres 
    PasswordAuthentication yes

Hors ligne

#6 Le 15/06/2026, à 15:30

steph810

Re : vérification / configuration accés ssh

re:
essaie de voir erreur exacte avec, si tu ne voir rien c'est que c'est OK:

sudo sshd -t

puis voir la config réellement appliqué:

sudo sshd -T -C user=iznobe,addr=192.168.1.100 | grep -E 'allowusers|passwordauthentication|maxauthtries|permitrootlogin|logingracetime'

Dernière modification par steph810 (Le 15/06/2026, à 15:30)

Hors ligne

#7 Le 15/06/2026, à 15:51

iznobe

Re : vérification / configuration accés ssh

ça a l ' air de marcher pour :

Je n'ai jamais essayé mais cela devrait fonctionner :

#En général
PasswordAuthentication no
PubkeyAuthentication yes

#Et si local
Match Address 192.168.1.0/24
    PasswordAuthentication yes

Pour " les autres " , il s ' agit de " translation réseau " ( https://www.checkpoint.com/fr/cyber-hub … ation-nat/ ) , ce ne sont donc pas des réseaux locaux a proprement parler , et quand j ' essaie et bien , ca me renvoie : erreur pubkey autorized .
C ' est peut etre normal ?

Dernière modification par iznobe (Le 15/06/2026, à 15:55)

Hors ligne

#8 Le 15/06/2026, à 16:39

O_20_100_O

Re : vérification / configuration accés ssh

C'est un PAT ?
♬ Il n'y mit pas la PAT ♬♬ et ron et ron ♬♬

Hors ligne

#9 Le 11/07/2026, à 17:38

Majex

Re : vérification / configuration accés ssh

iznobe a écrit :

Bonjour , j ' aimerais configuré un pi ( serveur ssh ) pour un accès uniquement en local , et vérifier que c ' est effectivement le cas , sauf que je ne vois pas tellement comment faire pour vérifier .

Actuellement ( et théoriquement ) , le fichier " /etc/ssh/sshd_config " est celui par défaut :

iznobe@k-pi3:~ $ cat /etc/ssh/sshd_config
#       $OpenBSD: sshd_config,v 1.103 2018/04/09 20:41:22 tj 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.

Include /etc/ssh/sshd_config.d/*.conf

#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 ~/.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
#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
iznobe@k-pi3:~ $

ma config est dans le fichier suivant :

iznobe@k-pi3:~ $ cat /etc/ssh/sshd_config.d/config.perso.conf
StrictModes yes
PubkeyAuthentication yes
PasswordAuthentication yes
LoginGraceTime 300
MaxAuthTries 3
PasswordAuthentication no
PermitRootLogin no
AllowUsers iznobe@192.168.1.0/24
iznobe@k-pi3:~ $

est ce que l ' ordre dans lequel on dispose les lignes a une importance ?

Resalut iznobe (comme on se retrouve...). Je me permets d'intervenir vu que ton sujet est resté techniquement inachevé.

Pour ton histoire de NAT/PAT ("les autres"), fais super attention. Si ton routeur fait du masquerading (SNAT) pour rediriger le flux vers ton Pi, ce dernier va voir toutes les connexions externes comme si elles venaient de l'IP locale de la box. Du coup, ton bloc Match Address 192.168.1.0/24 risque d'autoriser la terre entière par simple mot de passe (lol).

Il faut vraiment t'assurer que ton routeur ne fait que du transfert de port (DNAT) pour préserver l'IP publique d'origine.

Ensuite, pour ton plantage avec #AllowUsers, c'est normal : dans OpenSSH, une condition Match s'applique jusqu'à la fin du fichier (ou au prochain Match). Si tu as mis ton AllowUsers en dessous de ton Match Address, la règle ne s'appliquait plus globalement.

Mets toujours tes règles globales en premier et tous tes blocs Match tout à la fin de ton fichier de conf. Ca devrait aller avec ça


"L'homme est un loup pour l'homme, ce qui, vous en conviendrez, n'est pas très gentil pour le loup"

Hors ligne

#10 Le 11/07/2026, à 19:13

krodelabestiole

Re : vérification / configuration accés ssh

iznobe a écrit :

pour un accès uniquement en loca

vérifies que tu n'y aies pas accès en IPv6 !

tu peux aussi autoriser seulement un utilisateur depuis seulement une adresse :

AllowUser utilisateur@IP

// tu en parles dans le message précédent, pas vu, déso !

Dernière modification par krodelabestiole (Le 11/07/2026, à 19:13)

Hors ligne