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 04/02/2017, à 05:26

johnnybegood

SSH et SFTP

Bonjour,

Tout d'abord, je vous prie de m'excuser si mon sujet n'est pas au bon endroit.

Je viens vers vous, n'ayant pas trouvé la solution, pour vous poser une question sur laquelle je bute.
Je souhaiterais configurer mon serveur pour qu'il n'autorise que les connexions SSH par clé publiques. Pour ça, aucun soucis.
Mais j'ai également besoin d'avoir une connexion SFTP mais qui puisse se faire via une identification par mot de passe.
Sauf que bien sur, si SSH est en passkey, SFTP par mot de passe est refusé.

Y a t'il une solution à ce problème ?
Je vous souhaite une bonne journée et vous remercie vivement pour votre aide wink
Johnnybegood.

Dernière modification par johnnybegood (Le 04/02/2017, à 10:31)

Hors ligne

#2 Le 04/02/2017, à 10:16

bruno

Re : SSH et SFTP

Bonjour,

Effectivement je pense que ta question aurait autant sa place dans la section « serveur ».
Ce que tu veux faire doit être possible (je n'ai pas testé) avec une configuration du type :

PasswordAuthentication no

Match group sftpusers
    PasswordAuthentication yes

Ainsi la connexion  par mot de passe est globalement désactivée, mais elle est autorisée pour les membres du groupe sftpusers

En ligne

#3 Le 04/02/2017, à 12:33

maxire

Re : SSH et SFTP

Bonjour,

La proposition de Bruno fonctionne sauf qu'il faut utiliser Group et non group dans l'instruction Match et bien évidemment rattacher les utilisateurs sftp au groupe sftpusers.

man sshd_config a écrit :

Match   Introduces a conditional block.  If all of the criteria on the Match line are satisfied, the keywords on the following lines
             override those set in the global section of the config file, until either another Match line or the end of the file.  If a
             keyword appears in multiple Match blocks that are satisfied, only the first instance of the keyword is applied.

             The arguments to Match are one or more criteria-pattern pairs or the single token All which matches all criteria.  The avail‐
             able criteria are User, Group, Host, LocalAddress, LocalPort, and Address.  The match patterns may consist of single entries
             or comma-separated lists and may use the wildcard and negation operators described in the PATTERNS section of ssh_config(5).

             The patterns in an Address criteria may additionally contain addresses to match in CIDR address/masklen format, such as
             192.0.2.0/24 or 2001:db8::/32.  Note that the mask length provided must be consistent with the address - it is an error to
             specify a mask length that is too long for the address or one with bits set in this host portion of the address.  For exam‐
             ple, 192.0.2.0/33 and 192.0.2.0/8, respectively.

             Only a subset of keywords may be used on the lines following a Match keyword.  Available keywords are AcceptEnv,
             AllowAgentForwarding, AllowGroups, AllowStreamLocalForwarding, AllowTcpForwarding, AllowUsers, AuthenticationMethods,
             AuthorizedKeysCommand, AuthorizedKeysCommandUser, AuthorizedKeysFile, AuthorizedPrincipalsCommand,
             AuthorizedPrincipalsCommandUser, AuthorizedPrincipalsFile, Banner, ChrootDirectory, ClientAliveCountMax, ClientAliveInterval,
             DenyGroups, DenyUsers, ForceCommand, GatewayPorts, GSSAPIAuthentication, HostbasedAcceptedKeyTypes, HostbasedAuthentication,
             HostbasedUsesNameFromPacketOnly, IPQoS, KbdInteractiveAuthentication, KerberosAuthentication, MaxAuthTries, MaxSessions,
             PasswordAuthentication, PermitEmptyPasswords, PermitOpen, PermitRootLogin, PermitTTY, PermitTunnel, PermitUserRC,
             PubkeyAcceptedKeyTypes, PubkeyAuthentication, RekeyLimit, RevokedKeys, StreamLocalBindMask, StreamLocalBindUnlink,
             TrustedUserCAKeys, X11DisplayOffset, X11Forwarding and X11UseLocalHost.

Tu peux également restreindre cette règle d'identification par mot de passe à un unique utilisateur avec:

Match User toto
    PasswordAuthentication yes

ou plusieurs utilisateurs

Match User toto,tata,titi
 PasswordAuthentication yes

Utiliser des «patterns» etcetera comme indiqué dans la page man de ssh_config:

PATTERNS
     A pattern consists of zero or more non-whitespace characters, ‘*’ (a wildcard that matches zero or more characters), or ‘?’ (a wild‐
     card that matches exactly one character).  For example, to specify a set of declarations for any host in the ".co.uk" set of domains,
     the following pattern could be used:

           Host *.co.uk

     The following pattern would match any host in the 192.168.0.[0-9] network range:

           Host 192.168.0.?

     A pattern-list is a comma-separated list of patterns.  Patterns within pattern-lists may be negated by preceding them with an excla‐
     mation mark (‘!’).  For example, to allow a key to be used from anywhere within an organization except from the "dialup" pool, the
     following entry (in authorized_keys) could be used:

           from="!*.dialup.example.com,*.example.com"

Les possibilités de paramétrages sont larges.


Maxire
Archlinux/Mate + Ubuntu 22.04 + Archlinux/Gnome sur poste de travail

Hors ligne

#4 Le 04/02/2017, à 12:49

johnnybegood

Re : SSH et SFTP

Tout d'abord, merci à tout les deux.
Alors j'ai essayé d'autoriser un seul utilisateur donc avec

Match User johnnybegood
PasswordAuthentication yes

J'ai mis cette instruction juste après

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

Donc, soit l'instruction doit être à un autre endroit, soit ça marche pas.

Hors ligne

#5 Le 04/02/2017, à 13:03

maxire

Re : SSH et SFTP

L'ordre des instructions est important dans sshd_config, mets les instructions Match en fin de sshd_config.
Je te mets un sshd_config qui fonctionne, dont tu peux t'inspirer:

#	$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_dsa_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
PermitRootLogin no
#StrictModes yes
#MaxAuthTries 6
#MaxSessions 10

#PubkeyAuthentication yes

# The default is to check both .ssh/authorized_keys and .ssh/authorized_keys2
# but this is overridden so installations will only check .ssh/authorized_keys
AuthorizedKeysFile	.ssh/authorized_keys

#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
IgnoreUserKnownHosts yes
# Don't read the user's ~/.rhosts and ~/.shosts files
#IgnoreRhosts yes

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

# Change to no to disable s/key passwords
ChallengeResponseAuthentication no

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes

# 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 no
X11Forwarding yes
#X11DisplayOffset 10
#X11UseLocalhost yes
#PermitTTY yes
PrintMotd no # pam does that
#PrintLastLog yes
#TCPKeepAlive yes
#UseLogin no
#UsePrivilegeSeparation sandbox
#PermitUserEnvironment no
#Compression delayed
#ClientAliveInterval 0
#ClientAliveCountMax 3
#UseDNS no
#PidFile /run/sshd.pid
#MaxStartups 10:30:100
#PermitTunnel no
#ChrootDirectory none
#VersionAddendum none

# no default banner path
#Banner none

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

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

Maxire
Archlinux/Mate + Ubuntu 22.04 + Archlinux/Gnome sur poste de travail

Hors ligne

#6 Le 04/02/2017, à 13:07

johnnybegood

Re : SSH et SFTP

Super !
Ça marche ! Merci beaucoup !
C'est vous les plus fort wink

Hors ligne