Nowe posty

Autor Wątek: Logowanie poprzez SSH  (Przeczytany 3627 razy)

dizel1988

  • Gość
Logowanie poprzez SSH
« dnia: 2015-06-18, 13:53:26 »
Witajcie.
Problem zapewne dla większości z Was dość banalny ale nie radzę sobie i chciałbym Was prosić o pomoc. Może powiem co chcę osiągnąć i co już do tej pory zrobiłem. Chcę się logować z jednego serwera linuxowego na drugi bez użycia hasła (poprzez SSH). W tym celu na serwerze wygenerowałem parę kluczy, prywatny i publiczny. Na kliencie w katalogu do którego chcę mieć dostęp, utworzyłem katalog .ssh z prawami 700 a w nim plik authorized_keys z prawami 600. Do tego pliku dodałem zawartość pliku z kluczem publiczny, oczywiście poprzez dopisanie.  Wszystko przebiegło poprawnie. Niestety, chcąc skopiować sobie pewien pliczek z serwera na klienta poleceniem: scp /tmp/nazwa_pliku uzytkownik@ip_klienta: /home/katalog_uzytkownika/podkatalog cały czas prosi mnie o podanie hasła. Na pewno gdzieś zrobiłem jakiś błąd. Będę ogromnie wdzięczny za wszelką pomoc.

Pozdrawiam.

Offline Paweł Kraszewski

  • Administrator
  • Guru
  • *****
  • Wiadomości: 3056
  • Lenistwo jest matką potrzeby = babcią wynalazku
    • Zobacz profil
Logowanie poprzez SSH
« Odpowiedź #1 dnia: 2015-06-18, 15:13:48 »
Katalog .ssh z plikiem authorized_keys ma być w katalogu domowym użytkownika, na którego się logujesz. Dostęp jest per konto nie per katalog.
Paweł Kraszewski
~Arch/Void/Gentoo/FreeBSD/OpenBSD/Specjalizowane customy

dizel1988

  • Gość
Logowanie poprzez SSH
« Odpowiedź #2 dnia: 2015-06-18, 15:17:30 »
I dokładnie tak jest. Mam katalog /home a w nim kilku userów i w głównym katalogu użytkownika czyli poziom głębiej utworzony jest katalog .ssh a w nim siedzi authorized_keys

A co robimy z kluczem prywatnym? Czy gdzieś go umieszczamy w jakimś konkretnym miejsce? Ponieważ u mnie on siedzi w katalogu /tmp czyli tam gdzie zapisałem wygenerowaną parę kluczy.

Offline Paweł Kraszewski

  • Administrator
  • Guru
  • *****
  • Wiadomości: 3056
  • Lenistwo jest matką potrzeby = babcią wynalazku
    • Zobacz profil
Logowanie poprzez SSH
« Odpowiedź #3 dnia: 2015-06-18, 17:03:09 »
Klucz prywatny może być gdziekolwiek, o ile ścieżkę do niego podasz w parametrze -i przy wywołaniu ssh.  jeżeli nie chcesz podawać ścieżki, to zapisz go jako id_rsa (czy id_jakitypklucza jeżeli nie jest RSA)  w katalogu .ssh użytkownika z którego się łączysz. I to klucz prywatny musi mieć uprawnienia 600 a nie publiczny.
Paweł Kraszewski
~Arch/Void/Gentoo/FreeBSD/OpenBSD/Specjalizowane customy

dizel1988

  • Gość
Logowanie poprzez SSH
« Odpowiedź #4 dnia: 2015-06-22, 13:42:17 »
Hej.
Mam zrobione dokładnie tak jak napisałeś. Klucz prywatny w katalogu .ssh pod nazwą id_rsa. Nadałem prywatnemu uprawnienie 600 i niestety dalej nic. Gdy wykonuję ssh -v nazwa_uzytkownika@IP_serwera prosi mnie o hasło. Już mi brakuje pomysłów co może być. Linux z którego się łączę to redhat natomiast klient to windows server ale postawiony jest na nim cygwin. Aczkolwiek nie sądzę aby to jakoś przeszkadzało. Pomóżcie co jeszcze może być bo sprawa banalna i nigdy nie miałem z tym problemów, robię to nie po raz pierwszy a po raz pierwszy napotykam na takie trudności i takiej głupocie.

Xax79

  • Gość
Logowanie poprzez SSH
« Odpowiedź #5 dnia: 2015-06-22, 15:36:31 »
Zrób
ssh -vvv login@host
podając rzecz jasna właściwy login i hasło i wstaw wszystko co zostanie wyplute do prośby o podanie hasła.

Warto też sprawdziź logi samego ssh po stronie maszyny do której się łączysz.

dizel1988

  • Gość
Logowanie poprzez SSH
« Odpowiedź #6 dnia: 2015-06-22, 16:30:55 »
Tak wygląda log:

OpenSSH_5.3p1, OpenSSL 1.0.1e-fips 11 Feb 2013
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to adres_IP [adres_IP] port 22.
debug1: Connection established.
debug1: identity file /uzytkownik/.ssh/identity type -1
debug1: identity file /uzytkownik/.ssh/identity-cert type -1
debug3: Not a RSA1 key file /uzytkownik/.ssh/id_rsa.
debug2: key_type_from_name: unknown key type '-----BEGIN'
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
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
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 /uzytkownik/.ssh/id_rsa type 1
debug1: identity file /uzytkownik/.ssh/id_rsa-cert type -1
debug1: identity file /uzytkownik/.ssh/id_dsa type -1
debug1: identity file /uzytkownik/.ssh/id_dsa-cert type -1
debug1: identity file /uzytkownik/.ssh/id_ecdsa type -1
debug1: identity file /uzytkownik/.ssh/id_ecdsa-cert type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_6.7
debug1: match: OpenSSH_6.7 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.3
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug3: Wrote 960 bytes for a total of 981
debug1: SSH2_MSG_KEXINIT received
debug2: kex_parse_kexinit: diffie-hellman-group-exchange-sha256,diffie-hellman-g                                                                                        roup-exchange-sha1,diffie-hellman-group14-sha1,diffie-hellman-group1-sha1
debug2: kex_parse_kexinit: ssh-rsa-cert-v01@openssh.com,ssh-dss-cert-v01@openssh                                                                                        .com,ssh-rsa-cert-v00@openssh.com,ssh-dss-cert-v00@openssh.com,ssh-rsa,ssh-dss
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12                                                                                        8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij                                                                                        ndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,arcfour256,arcfour12                                                                                        8,aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,aes192-cbc,aes256-cbc,arcfour,rij                                                                                        ndael-cbc@lysator.liu.se
debug2: kex_parse_kexinit: hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-sha2-256,                                                                                        hmac-sha2-512,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-sha2-256,                                                                                        hmac-sha2-512,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: curve25519-sha256@libssh.org,ecdh-sha2-nistp256,ecdh-                                                                                        sha2-nistp384,ecdh-sha2-nistp521,diffie-hellman-group-exchange-sha256,diffie-hel                                                                                        lman-group14-sha1
debug2: kex_parse_kexinit: ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ssh-ed25519
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.c                                                                                        om,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
debug2: kex_parse_kexinit: aes128-ctr,aes192-ctr,aes256-ctr,aes128-gcm@openssh.c                                                                                        om,aes256-gcm@openssh.com,chacha20-poly1305@openssh.com
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac                                                                                        -sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.co                                                                                        m,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
debug2: kex_parse_kexinit: umac-64-etm@openssh.com,umac-128-etm@openssh.com,hmac                                                                                        -sha2-256-etm@openssh.com,hmac-sha2-512-etm@openssh.com,hmac-sha1-etm@openssh.co                                                                                        m,umac-64@openssh.com,umac-128@openssh.com,hmac-sha2-256,hmac-sha2-512,hmac-sha1
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-sha1
debug1: kex: server->client aes128-ctr hmac-sha1 none
debug2: mac_setup: found hmac-sha1
debug1: kex: client->server aes128-ctr hmac-sha1 none
debug1: SSH2_MSG_KEX_DH_GEX_REQUEST(1024<2048<8192) sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_GROUP
debug3: Wrote 24 bytes for a total of 1005
debug2: dh_gen_key: priv key bits set: 171/320
debug2: bits set: 1009/2048
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: Wrote 272 bytes for a total of 1277
debug3: check_host_in_hostfile: host adres_IP filename /uzytkownik/.ssh                                                                                        /known_hosts
debug3: check_host_in_hostfile: host adres_IP filename /uzytkownik/.ssh                                                                                        /known_hosts
debug3: check_host_in_hostfile: match line 2
debug1: Host 'adres_IP' is known and matches the RSA host key.
debug1: Found key in /uzytkownik/.ssh/known_hosts:2
debug2: bits set: 1008/2048
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
debug3: Wrote 16 bytes for a total of 1293
debug2: set_newkeys: mode 0
debug1: SSH2_MSG_NEWKEYS received
debug1: SSH2_MSG_SERVICE_REQUEST sent
debug3: Wrote 52 bytes for a total of 1345
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /uzytkownik/.ssh/identity ((nil))
debug2: key: /uzytkownik/.ssh/id_rsa (0x7fe839f11740)
debug2: key: /uzytkownik/.ssh/id_dsa ((nil))
debug2: key: /uzytkownik/.ssh/id_ecdsa ((nil))
debug3: Wrote 84 bytes for a total of 1429
debug1: Authentications that can continue: publickey,password,keyboard-interacti                                                                                        ve
debug3: start over, passed a different list publickey,password,keyboard-interact                                                                                        ive
debug3: preferred gssapi-keyex,gssapi-with-mic,publickey,keyboard-interactive,pa                                                                                        ssword
debug3: authmethod_lookup publickey
debug3: remaining preferred: keyboard-interactive,password
debug3: authmethod_is_enabled publickey
debug1: Next authentication method: publickey
debug1: Trying private key: /uzytkownik/.ssh/identity
debug3: no such identity: /uzytkownik/.ssh/identity
debug1: Offering public key: /uzytkownik/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug3: Wrote 372 bytes for a total of 1801
debug1: Authentications that can continue: publickey,password,keyboard-interacti                                                                                        ve
debug1: Trying private key: /uzytkownik/.ssh/id_dsa
debug3: no such identity: /uzytkownik/.ssh/id_dsa
debug1: Trying private key: /uzytkownik/.ssh/id_ecdsa
debug3: no such identity: /uzytkownik/.ssh/id_ecdsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup keyboard-interactive
debug3: remaining preferred: password
debug3: authmethod_is_enabled keyboard-interactive
debug1: Next authentication method: keyboard-interactive
debug2: userauth_kbdint
debug2: we sent a keyboard-interactive packet, wait for reply
debug3: Wrote 100 bytes for a total of 1901
debug1: Authentications that can continue: publickey,password,keyboard-interacti                                                                                        ve
debug3: userauth_kbdint: disable: no info_req_seen
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred:
debug3: authmethod_is_enabled password
debug1: Next authentication method: password
cyg_server@adres_IP's password:

Offline Paweł Kraszewski

  • Administrator
  • Guru
  • *****
  • Wiadomości: 3056
  • Lenistwo jest matką potrzeby = babcią wynalazku
    • Zobacz profil
Logowanie poprzez SSH
« Odpowiedź #7 dnia: 2015-06-22, 21:49:46 »
Łomatko. Format kucza używanego przez SSH i generowanego przez OpenSSL to dwie różne sprawy. Masz w logu jak wół "key_type_from_name: unknown key type '-----BEGIN'"

Klucze do SSH generujesz poleceniem ssh_gen_key.
Paweł Kraszewski
~Arch/Void/Gentoo/FreeBSD/OpenBSD/Specjalizowane customy

dizel1988

  • Gość
Logowanie poprzez SSH
« Odpowiedź #8 dnia: 2015-06-23, 19:26:15 »
Ale ja kolego właśnie w taki sposób wygenerowałem parę tych kluczy dlatego nie bardzo rozumiem czemu coś takiego się dzieje. Do wygenerowania kluczy użyłem dokładnie polecenie:
ssh-keygen -t rsa
Tylko nigdy nie podawałem tej frazy zabezpieczającej klucz ale nie wiem czy to może mieć coś wspólnego z problemem który mam.

Xax79

  • Gość
Logowanie poprzez SSH
« Odpowiedź #9 dnia: 2015-06-25, 08:49:12 »
A patrzyłeś w logi serwera co się dzieje po jego stronie przy próbie nawiązania połączenia? Do zdiagnozowania problemu potrzebne są komunikaty po obu stronach.