Problème de configuration ssh

Bonjour,
Avant toute chose, je dois vous informer que j’ai quasiment aucune connaissance en réseau…
ma config:
portable(hostname:debian, connexion wifi:wlan0, 192.168.1.3)<----> Bbox(192.168.1.254)<---->pc(debian-htpc, connexion filaire:eth0, 192.168.1.7)
je souhaite me connecter par ssh depuis n’importe laquelle des deux machines sur l’autre.
Sur les deux postes, sont installés openssh-client et openssh-server.

debian:

olivier@debian:~$ cat /etc/hostname 
debian
olivier@debian:~$ cat /etc/resolv.conf
domain home
search home
nameserver 192.168.1.254
olivier@debian:~$ cat /etc/hosts
127.0.0.1	localhost.home	localhost
127.0.1.1	debian.home	debian
127.0.1.1	debian-htpc.home	debian-htpc

# The following lines are desirable for IPv6 capable hosts
::1     ip6-localhost ip6-loopback
fe00::0 ip6-localnet
ff00::0 ip6-mcastprefix
ff02::1 ip6-allnodes
ff02::2 ip6-allrouters
olivier@debian:~$ 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 22
# Use these options to restrict which interfaces/protocols sshd will bind to
#ListenAddress ::
ListenAddress 192.168.1.254
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 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

# 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 no

Sur l’autre pc(debian-htpc), j’ai la même configuration pour le fichier /etc/ssh/sshd_config
J’ai bien sûr lu le wiki de debian-fr.org.
Mais quand je lance


root@debian:/home/olivier# /etc/init.d/ssh status
sshd is not running ... failed!
root@debian:/home/olivier# /etc/init.d/ssh start
Starting OpenBSD Secure Shell server: sshd.
root@debian:/home/olivier# /etc/init.d/ssh status
sshd is not running ... failed!

j’ai le même problème sur mes deux machines…
je vous parles pas encore des clefs… déja réussir a lancer ssh!

merci par avance de votre aide…

Commente la ligne ListenAddress. L’IP .254 est celle de ta Box, pas de ta machine locale, tu ne peux pas écouter sur une IP qui ne t’appartient pas.

[quote=“man sshd_config”]ListenAddress
Specifies the local addresses sshd(8) should listen on.[/quote]

Merci Syam,
sshd se lance bien maintenant sur les deux machines.
j’ai créé ensuite les clefs de la même façon sur les deux machines avec la même passphrase:

olivier@debian:~$ ssh-keygen -t dsa -f ~/.ssh/home
Generating public/private dsa key pair.
/home/olivier/.ssh/home already exists.
Overwrite (y/n)? y
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
Your identification has been saved in /home/olivier/.ssh/home.
Your public key has been saved in /home/olivier/.ssh/home.pub.
The key fingerprint is:
cf:4f:a2:c0:bb:00:b9:c3:64:99:ec:ab:ec:49:13:68 olivier@debian
The key's randomart image is:
+--[ DSA 1024]----+
|                 |
|                 |
|                 |
|.. +             |
|.EO     S        |
|.=.o .   o       |
| o= . o   + .    |
|o oo . o . +     |
|o=.   o..   .    |
+-----------------+

puis:
sur debian:

olivier@debian:~$ cat ~/.ssh/config
Host home
HostName debian-htpc
User olivier
PasswordAuthentication no
IdentityFile ~/.ssh/home

sur debian-htpc:

olivier@debian-htpc:~$ cat ~/.ssh/config
Host home
HostName debian
User olivier
PasswordAuthentication no
IdentityFile ~/.ssh/home

ensuite:
sur debian:

olivier@debian:~$ ssh-copy-id -i ~/.ssh/home.pub olivier@debian-htpc The authenticity of host 'debian-htpc (127.0.1.1)' can't be established. ECDSA key fingerprint is 0f:04:25:0d:97:f1:2d:b2:38:c7:03:a4:a5:90:04:13. Are you sure you want to continue connecting (yes/no)? no Host key verification failed.
sur debian-htpc:

olivier@debian:~$ ssh-copy-id -i ~/.ssh/home.pub olivier@debian The authenticity of host 'debian-htpc (127.0.1.1)' can't be established. ECDSA key fingerprint is 0f:04:25:0d:97:f1:2d:b2:38:c7:03:a4:a5:90:04:13. Are you sure you want to continue connecting (yes/no)? no Host key verification failed.

je sais que je m’y prends mal… :think:

Pourquoi est-ce que tu réponds ‘no’ ? Un ‘yes’ devrait suffire j’imagine.

je réponds non car de toute façon l’authentification ne peut pas être établie!

olivier@debian:~$ ssh-copy-id -i ~/.ssh/home.pub olivier@debian-htpc The authenticity of host 'debian-htpc (127.0.1.1)' can't be established. ECDSA key fingerprint is 0f:04:25:0d:97:f1:2d:b2:38:c7:03:a4:a5:90:04:13. Are you sure you want to continue connecting (yes/no)? yes Warning: Permanently added 'debian-htpc' (ECDSA) to the list of known hosts. olivier@debian-htpc's password: Permission denied, please try again.

  1. Tes clés ne sont pas encore configurées, donc le PasswordAuthentication no dans ~/.ssh/config n’est pas correct (tu veux te connecter avec tes clés sans les avoir installées auparavant).

D’ailleurs il vaut mieux utiliser PreferredAuthentications password,publickey dans le ~/.ssh/config : la stratégie de connexion par mot de passe ou par clé doit se faire avant tout sur le serveur, le client doit s’adapter. L’avantage de mettre la méthode mot de passe avant la méthode par clés côté client, c’est que si le serveur accepte les mots de passe tu le verras tout de suite et tu pourras corriger ça.

Dans un premier temps pour la phase de test, inverse les priorités : PreferredAuthentications publickey,password ça te permettra de tester si l’authentification par clé fonctionne.

Une fois que tes clés seront fonctionnelles, c’est là que tu iras mettre PasswordAuthentication no dans /etc/sshd_config sur chaque machine, et que tu mettras PreferredAuthentications password,publickey dans chaque ~/.ssh/config pour bien vérifier qu’il n’accepte plus la connexion par mot de passe.

  1. Concernant “The authenticity of host … can’t be established.” c’est normal lors de la première connexion : la clé de la machine distante n’est pas encore stockée dans ~/.ssh/known_hosts. Il faut répondre yes au lieu de no.

  2. J’avais pas remarqué au premier coup d’œil, mais tes fichiers /etc/hosts sont mauvais. Sur les deux machines (debian et debian-htpc) tu dis que l’adresse des deux est 127.0.1.1 (ce qui est équivalent à 127.0.0.1). Bref, aucune des deux ne connaît l’adresse de l’autre.
    Sur debian (juste pour la partie IPv4, pour l’IPv6 tu laisses tel quel) :

127.0.0.1 localhost.home localhost 127.0.0.1 debian.home debian 192.168.1.7 debian-htpc.home debian-htpc
Sur debian-htpc (juste pour la partie IPv4, pour l’IPv6 tu laisses tel quel) :

127.0.0.1 localhost.home localhost 127.0.0.1 debian-htpc.home debian-htpc 192.168.1.3 debian.home debian

merci Syam,
je me doutais bien que j’avais un problème avec hosts, c’est pour cela que je l’avais donné…
voilà ce que j’ai fait suivant tes instructions (si j’ai bien compris):
machine debian (idem sur debian-htpc):

olivier@debian:~$ cat ~/.ssh/config Host home HostName debian-htpc User olivier PasswordAuthentication yes PreferredAuthentications publickey,password IdentityFile ~/.ssh/home
le Host et le HostName sont bon?

root@debian:/home/olivier# /etc/init.d/ssh restart
Restarting OpenBSD Secure Shell server: sshd.
root@debian:/home/olivier# exit
exit
olivier@debian:~$ ssh-copy-id -i ~/.ssh/home.pub olivier@debian-htpc
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@       WARNING: POSSIBLE DNS SPOOFING DETECTED!          @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
The ECDSA host key for debian-htpc has changed,
and the key for the corresponding IP address 192.168.1.7
is unknown. This could either mean that
DNS SPOOFING is happening or the IP address for the host
and its host key have changed at the same time.
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    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
16:ab:f9:24:7f:bd:1c:7b:89:15:87:b2:16:79:18:91.
Please contact your system administrator.
Add correct host key in /home/olivier/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/olivier/.ssh/known_hosts:1
ECDSA host key for debian-htpc has changed and you have requested strict checking.
Host key verification failed.

alors là… comprends pas… :119
je précise que j’ai bien effectué les modifs sur debian-htpc et fait un restart du networking et ssh.

j’ai essayé sur debian-htpc:

olivier@debian-htpc:~$ ssh-copy-id -i ~/.ssh/home.pub olivier@debian olivier@debian's password: Permission denied, please try again. olivier@debian's password: Permission denied, please try again. olivier@debian's password: Permission denied (publickey,password).

j’ai pourtant fait exactement le même type de configuration sur les deux postes!
y’a une chose que j’ai du louper… :think:

[quote]@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@[/quote]
Sur debian tu as accepté la clé machine de debian-htpc alors que ton hosts était mauvais. Résultat, la clé machine qui est stockée dans ~/.ssh/known_hosts est en fait celle de debian, et maintenant que tu as corrigé ton hosts il détecte qu’elle a changé (normal…).
Supprime juste ~/.ssh/known_hosts sur les deux machines, ça repartira de zéro.

Avant d’essayer ssh-copy-id, essaye déjà une connexion normale.
Perso je n’utilise jamais ssh-copy-id, je me sers juste de scp :

olivier@debian-htpc:~$ scp ~/.ssh/home.pub olivier@debian:~/.ssh/olivier@debian-htpc.pub olivier@debian's password: olivier@debian-htpc:~$ ssh olivier@debian olivier@debian's password: olivier@debian:~$ cat ~/.ssh/olivier@debian-htpc.pub >> ~/.ssh/authorized_keys

D’ailleurs tu ferais bien de renommer tes fichiers de clés : ils sont spécifiques à un utilisateur donné sur une machine donnée, leur nom devrait refléter ça (et ça éviterait de se mélanger les pinceaux). Genre sur debian-htpc :

mv ~/.ssh/home.pub ~/.ssh/olivier@debian-htpc.pub mv ~/.ssh/home ~/.ssh/olivier@debian-htpc
(ne pas oublier d’adapter ton fichier ~/.ssh/config en conséquence)

J’y pense : le permission denied vient peut-être de mauvaises permissions sur ton répertoire .ssh

bon, je me suis dit que ca marchais pas a cause du même nom de clef publique home.pub sur les deux serveurs j’ai alors régénéré deux clefs différentes:
debian:

olivier@debian:~$ ssh-keygen -t dsa -f ~/.ssh/home-debian

et sur debian-htpc:

olivier@debian-htpc:~$ ssh-keygen -t dsa -f ~/.ssh/home-debian-htpc

puis relancé les servers ssh. (je sais pas si c’est utile… mais bon.)

puis essayer depuis le poste debian:

olivier@debian:~$ ssh-copy-id -i ~/.ssh/home-debian.pub olivier@debian-htpc @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ WARNING: POSSIBLE DNS SPOOFING DETECTED! @ @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ The ECDSA host key for debian-htpc has changed, and the key for the corresponding IP address 192.168.1.7 is unknown. This could either mean that DNS SPOOFING is happening or the IP address for the host and its host key have changed at the same time. @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@ @ 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 16:ab:f9:24:7f:bd:1c:7b:89:15:87:b2:16:79:18:91. Please contact your system administrator. Add correct host key in /home/olivier/.ssh/known_hosts to get rid of this message. Offending ECDSA key in /home/olivier/.ssh/known_hosts:1 ECDSA host key for debian-htpc has changed and you have requested strict checking. Host key verification failed.
encore pareil…
depuis debian-htpc:

olivier@debian-htpc:~$ ssh-copy-id -i ~/.ssh/home-debian-htpc.pub olivier@debian

olivier@debian's password:
Now try logging into machine, with "ssh 'olivier@debian'", and check in:

  ~/.ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

olivier@debian-htpc:~$ ssh 'olivier@debian'
olivier@debian's password:
Last login: Thu Feb 23 21:01:46 2012 from localhost.home
olivier@debian:~$

et là c’est bon!! :dance:
pourquoi j’arrive pas à me connecter depuis debian sur debian-htpc alors??? :think:

Mercy Syam!
j’ai viré comme tu me l’as conseillé le fichier ~/.ssh/known_hosts et désormais cela fonctionne:

[code]olivier@debian:~$ ssh-copy-id -i ~/.ssh/home-debian.pub olivier@debian-htpc
The authenticity of host ‘debian-htpc (192.168.1.7)’ can’t be established.
ECDSA key fingerprint is 16:ab:f9:24:7f:bd:1c:7b:89:15:87:b2:16:79:18:91.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added ‘debian-htpc,192.168.1.7’ (ECDSA) to the list of known hosts.
olivier@debian-htpc’s password:
Permission denied, please try again.
olivier@debian-htpc’s password:
Permission denied, please try again.
olivier@debian-htpc’s password:
Now try logging into the machine, with “ssh ‘olivier@debian-htpc’”, and check in:

~/.ssh/authorized_keys

to make sure we haven’t added extra keys that you weren’t expecting.

olivier@debian:~$ ssh 'olivier@debian-htpc’
olivier@debian-htpc’s password:
Last login: Fri Feb 24 13:17:58 2012
olivier@debian-htpc:~$
[/code]

merci encore! :clap:

Bon, il me reste plus qu’a me documenter sur les différentes commandes que je peux effectuer avec ssh. Mais avant je vais suivre ton conseil et régénérer des clefs prenant en compte le nom de l’utilisateur et le nom de la machine.
Le sujet est clos! encore merci.

Tu n’as pas besoin de les regénérer, il suffit de les renommer. Il s’agit juste de noms de fichiers, ça ne concerne que nous humains la machine s’en fout. :wink:

d’accord! c’est effectivement plus simple de devoir juste les renommer…
sinon, derniere question au sujet de ce que m’as dit plus haut

[quote]Une fois que tes clés seront fonctionnelles, c’est là que tu iras mettre PasswordAuthentication no dans /etc/sshd_config sur chaque machine, et que tu mettras PreferredAuthentications password,publickey dans chaque ~/.ssh/config pour bien vérifier qu’il n’accepte plus la connexion par mot de passe.
[/quote]
je dois le faire? ca changera quoi?

Pour toi, rien : tu continueras à te connecter avec tes clés.
Pour un attaquant (qui réussirait à arriver sur ton LAN, ou bien si tu configures ton NAT pour pouvoir accéder à SSH depuis l’extérieur) : il ne pourra pas faire de brute-force sur le mot de passe, et un brute-force sur une paire de clés c’est vachement plus difficile…

Exprimé d’une autre manière : quel est l’intérêt de mettre en place des clés pour te connecter plutôt que de laisser une connexion par mot de passe ? Dans les deux cas tu taperas toujours un mot de passe (soit celui de l’utilisateur distant, soit celui pour débloquer ta clé locale) donc l’intérêt c’est pas d’éviter de taper un mot de passe, mais d’accroître la sécurité. Si tu laisses l’option de se connecter avec un mot de passe alors tes clés ne servent à rien face à un éventuel attaquant.

c’est encore moi,
j’ai mis sur les deux machines PasswordAuthentication no dans /etc/sshd_config
et PreferredAuthentications password,publickey dans chaque ~/.ssh/config
et plus de connexion sur aucune des deux machines alors que ca fonctionnait avant

olivier@debian:~$ ssh 'olivier@debian-htpc' Permission denied (publickey).

une idée?

Fais voir ton ~/.ssh/config de la machine debian.
Ça devrait ressembler à ça (ça vient de mon fichier de config, adapté à tes paramètres) :

Host debian-htpc User olivier Hostname debian-htpc Port 22 PreferredAuthentications password,publickey IdentityFile "~/.ssh/olivier@debian"

Et bien entendu sur la machine debian-htpc :

Host debian User olivier Hostname debian Port 22 PreferredAuthentications password,publickey IdentityFile "~/.ssh/olivier@debian-htpc"

Si ça résout pas le problème, redonne ton fichier /etc/sshd_config en entier (mettons celui de debian-htpc), ton fichier ~/.ssh/config en entier (celui de debian) et sur les deux machines :

$ ls -lAd ~/.ssh/ $ ls -lA ~/.ssh/