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/02/2012, à 22:28

arnaud_d

[Résolu] Problème connexion SSH clé dsa

Bonjour,

Je rencontre un problème bizarre avec ssh.

J'ai créé une paire de clés avec

  $ ssh-keygen -t dsa

j'ai donc dans ~/.ssh mes deux clés : id_dsa et id_dsa.pub

Sur mon serveur ssh, sur lequel j'ai accès en mot de passe, j'ai envoyé la clé publique en faisant :

  $ scp ~/.ssh/id_dsa.pub login@??.??.??.??:/home/login/.ssh/authorized_keys

Tout s'est bien passé. Je me suis connecté en login/mot de passe sur le serveur, j'ai vérifié que le fichier authorized_keys contenait bien ma clé publique.

Ensuite j'ai éditer le fichier /etc/ssh/sshd_config pour dé-commenter la ligne

# PasswordAuthentication no

Maintenant impossible de me connecter au serveur, ni en login/mot de passe, ni avec ma clé privée.

Voici ce que me donne

  $ ssh -vvv login@??.??.??.??

(je remplace l'ip de mon serveur par ??.??.??.??)

OpenSSH_5.8p1 Debian-7ubuntu1, OpenSSL 1.0.0e 6 Sep 2011
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ??.??.??.?? [??.??.??.??] port 22.
debug1: Connection established.
debug1: identity file /home/arnaud/.ssh/id_rsa type -1
debug1: identity file /home/arnaud/.ssh/id_rsa-cert type -1
debug3: Incorrect RSA1 identifier
debug3: Could not load "/home/arnaud/.ssh/id_dsa" as a RSA1 public key
debug2: key_type_from_name: unknown key type '-----BEGIN'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'Proc-Type:'
debug3: key_read: missing keytype
debug2: key_type_from_name: unknown key type 'DEK-Info:'
debug3: key_read: missing keytype
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug3: key_read: missing whitespace
debug2: key_type_from_name: unknown key type '-----END'
debug3: key_read: missing keytype
debug1: identity file /home/arnaud/.ssh/id_dsa type 2
debug1: Checking blacklist file /usr/share/ssh/blacklist.DSA-1024
debug1: Checking blacklist file /etc/ssh/blacklist.DSA-1024
debug1: identity file /home/arnaud/.ssh/id_dsa-cert type -1
debug1: identity file /home/arnaud/.ssh/id_ecdsa type -1
debug1: identity file /home/arnaud/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.3p1 Debian-3ubuntu7
debug1: match: OpenSSH_5.3p1 Debian-3ubuntu7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.8p1 Debian-7ubuntu1
debug2: fd 3 setting O_NONBLOCK
debug3: load_hostkeys: loading entries for host "??.??.??.??" from file "/home/arnaud/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/arnaud/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug3: order_hostkeyalgs: prefer hostkeyalgs: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: ecdh-sha2-nistp256,ecdh-sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-rsa-cert-v00@openssh.com,ssh-rsa,ecdsa-sha2-nistp256-cert-v01@openssh.com,ecdsa-sha2-nistp384-cert-v01@openssh.com,ecdsa-sha2-nistp521-cert-v01@openssh.com,ssh-dss-cert-v01@openssh.com,ssh-dss-cert-v00@openssh.com,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: none,zlib@openssh.com,zlib
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-group-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rijndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160,hmac-ripemd160@openssh.com,hmac-sha1-96,hmac-md5-96
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: none,zlib@openssh.com
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: 
debug2: kex_parse_kexinit: first_kex_follows 0 
debug2: kex_parse_kexinit: reserved 0 
debug2: mac_setup: found hmac-md5
debug1: kex: server->client aes128-ctr hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-ctr hmac-md5 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<1024<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug2: dh_gen_key: priv key bits set: 139/256
debug2: bits set: 500/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug1: Server host key: RSA 0c:f9:b0:02:3f:ea:68:3b:bc:a2:39:72:28:d4:10:2f
debug3: load_hostkeys: loading entries for host "??.??.??.??" from file "/home/arnaud/.ssh/known_hosts"
debug3: load_hostkeys: found key type RSA in file /home/arnaud/.ssh/known_hosts:2
debug3: load_hostkeys: loaded 1 keys
debug1: Host '??.??.??.??' is known and matches the RSA host key.
debug1: Found key in /home/arnaud/.ssh/known_hosts:2
debug2: bits set: 492/1024
debug1: ssh_rsa_verify: signature correct
debug2: kex_derive_keys
debug2: set_newkeys: mode 1
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: Roaming not allowed by server
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/arnaud/.ssh/id_rsa ((nil))
debug2: key: /home/arnaud/.ssh/id_dsa (0x21f7de50)
debug2: key: /home/arnaud/.ssh/id_ecdsa ((nil))
debug1: Authentications that can continue: publickey
debug3: start over, passed a different list publickey
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,password
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /home/arnaud/.ssh/id_rsa
debug3: no such identity: /home/arnaud/.ssh/id_rsa
debug1: Offering DSA public key: /home/arnaud/.ssh/id_dsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey
debug1: Trying private key: /home/arnaud/.ssh/id_ecdsa
debug3: no such identity: /home/arnaud/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug1: No more authentication methods to try.
Permission denied (publickey).

Passez-moi l'expression, mais j'ai l'impression que c'est le bordel smile

  1. Il cherche une clé RSA mais c'est une clé DSA

  2. il essaie d'envoyer le fichier ~/.ssh/id_dsa comme clé publique mais c'est ma clé privée (c'est id_dsa.pub la clé publique).

  3. Il parle des fichier /home/arnaud/.ssh/id_rsa, /home/arnaud/.ssh/id_rsa-cert, /home/arnaud/.ssh/id_dsa-cert, /home/arnaud/.ssh/id_ecdsa... alors qu'ils n'existent pas.

Ou alors je comprend rien de ce qu'il dit et votre aide va m'être précieuse.

J'ai fait EXACTEMENT la même manip chez moi pour tester en local avec deux PC et ça avait très bien marché !

Voici le fichier /etc/ssh/ssh_config (je sais pas à quoi sert ce fichier) du PC client.

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
#   Port 22
#   Protocol 2,1
#   Cipher 3des
#   Ciphers aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour128,aes128-cbc,3des-cbc
#   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
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no

Merci d'avance pour vos lumières.

[EDIT 13/02/12]
Pour être précis, j'ai créé le couple de clé sur un autre PC et j'ai copié les fichiers id_dsa et id_dsa.pub sur le PC client.
Je me demande si le problème ne pourrais pas venir de là.
A quoi sert la commande ssh-add sachant que j'ai testé sans succès :
ssh login@??.??.??.?? -i ~/.ssh/id_dsa
[/EDIT]

Dernière modification par arnaud_d (Le 16/02/2012, à 20:16)

Hors ligne

#2 Le 16/02/2012, à 20:15

arnaud_d

Re : [Résolu] Problème connexion SSH clé dsa

Bon bha j'ai fini par trouver (la réponse était dans la doc mais c'est pas facile de savoir que le problème venait de là). Quelqu'un qui a accès à l'ordinateur a pu modifier le fichier /etc/ssh/sshd_config pour authoriser à nouveau la connexion par mot de passe.

J'ai regardé les logs du serveur en faisant

$ cat /var/log/auth.log | grep ssh

et j'ai alors vu qu'il y avait un problème avec les droits du dossier /home/nom_utilisateur.

J'ai donc fait un

$ chmod g-w /home/nom_utilisateur

ai redémarré ssh par un

sudo service ssh restart

et me suis déconnecté.

En me reconnectant il m'a demandé le mot de passe de ma clé privée. Bingo !

En conclusion je voudrais donc donner quelques règles :

  1. Copier la clé publique dans ~/.ssh/authorized_keys du serveur

  2. chmod 600 ~/.ssh/authorized_keys

  3. chmod 700 ~/.ssh

  4. chmod g-w /home/login

  5. Ne désactiver le connection par mot de passe qu'à partir d'une connexion par clé ! (si les deux coexistent, la connexion par clé semble prio)

Dernière modification par arnaud_d (Le 16/02/2012, à 20:19)

Hors ligne