Problem mit SSH + PubKey Auth

Hi,

ich weiss nicht was ich verstellt habe, jedenfalls geht meine PubKey Authentication nicht mehr ...

Hier sie Server Settings:
Code:
# Package generated configuration file
# See the sshd(8) 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 0.0.0.0
Protocol 2
# HostKeys for protocol version 2
HostKey /etc/ssh/ssh_host_rsa_key
HostKey /etc/ssh/ssh_host_dsa_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 yes
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

UsePAM yes

Mein pub key ist richtig installiert auf dem Server:

Code:
mathias@mini:~$ ls .ssh/
id_rsa  id_rsa.pub  known_hosts
mathias@mini:~$ cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAssGjYzETS+7sBOFjz+WMys7iZ46m8ojVMWaSTTBWaCo0CQXu3lwzXWhJNH1s4/WMyV2RGanAuEC3wUrxVxeZthtVcRG6njgUARO2p0qen5tzkJHLEoab4mEq3jptOMNDJxYO0o6XUzodk+/g0bHtHr2XwYcH3r7DO022SD/mYGZ+9pn0j86EfSt2BtGUh8F+TRbIlbmy4Mn6xQ7yrfaY/+4aa9DlNPtOtibY4+Lufl22CHyTGfUZM9X7vkqMfdFG8uTWsLKtdveUh/9DyQHj8rAegRnQzeZ9eOAKsNfeR5/plP35VuzDs2xwYKId+bu/xAL/B+CwaMZw4waIvPwEFQ== mathias@mini
mathias@mini:~$ ssh mathias@ironman cat .ssh/authorized_keys
mathias@ironman's password: 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAssGjYzETS+7sBOFjz+WMys7iZ46m8ojVMWaSTTBWaCo0CQXu3lwzXWhJNH1s4/WMyV2RGanAuEC3wUrxVxeZthtVcRG6njgUARO2p0qen5tzkJHLEoab4mEq3jptOMNDJxYO0o6XUzodk+/g0bHtHr2XwYcH3r7DO022SD/mYGZ+9pn0j86EfSt2BtGUh8F+TRbIlbmy4Mn6xQ7yrfaY/+4aa9DlNPtOtibY4+Lufl22CHyTGfUZM9X7vkqMfdFG8uTWsLKtdveUh/9DyQHj8rAegRnQzeZ9eOAKsNfeR5/plP35VuzDs2xwYKId+bu/xAL/B+CwaMZw4waIvPwEFQ== mathias@mini
mathias@mini:~$

Und das passiert wenn ich per SSH verbinde

Code:
OpenSSH_5.1p1 Debian-6ubuntu2, OpenSSL 0.9.8g 19 Oct 2007
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: Applying options for *
debug2: ssh_connect: needpriv 0
debug1: Connecting to ironman [10.0.1.10] port 22.
debug1: Connection established.
debug1: identity file /home/mathias/.ssh/identity type -1
debug3: Not a RSA1 key file /home/mathias/.ssh/id_rsa.
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
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 /home/mathias/.ssh/id_rsa type 1
debug1: Checking blacklist file /usr/share/ssh/blacklist.RSA-2048
debug1: Checking blacklist file /etc/ssh/blacklist.RSA-2048
debug1: identity file /home/mathias/.ssh/id_dsa type -1
debug1: Remote protocol version 2.0, remote software version OpenSSH_5.1p1 Debian-5
debug1: match: OpenSSH_5.1p1 Debian-5 pat OpenSSH*
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_5.1p1 Debian-6ubuntu2
debug2: fd 3 setting O_NONBLOCK
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
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-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
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-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
debug2: kex_parse_kexinit: aes128-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour128,arcfour256,arcfour,aes192-cbc,aes256-cbc,rijndael-cbc@lysator.liu.se,aes128-ctr,aes192-ctr,aes256-ctr
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-cbc hmac-md5 none
debug2: mac_setup: found hmac-md5
debug1: kex: client->server aes128-cbc 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: 146/256
debug2: bits set: 519/1024
debug1: SSH2_MSG_KEX_DH_GEX_INIT sent
debug1: expecting SSH2_MSG_KEX_DH_GEX_REPLY
debug3: check_host_in_hostfile: filename /home/mathias/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 1
debug3: check_host_in_hostfile: filename /home/mathias/.ssh/known_hosts
debug3: check_host_in_hostfile: match line 2
debug1: Host 'ironman' is known and matches the RSA host key.
debug1: Found key in /home/mathias/.ssh/known_hosts:1
debug2: bits set: 524/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: SSH2_MSG_SERVICE_REQUEST sent
debug2: service_accept: ssh-userauth
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug2: key: /home/mathias/.ssh/id_rsa (0x2129fa00)
debug2: key: /home/mathias/.ssh/identity ((nil))
debug2: key: /home/mathias/.ssh/id_dsa ((nil))
debug1: Authentications that can continue: publickey,password
debug3: start over, passed a different list publickey,password
debug3: preferred gssapi-keyex,gssapi-with-mic,gssapi,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: Offering public key: /home/mathias/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/mathias/.ssh/identity
debug3: no such identity: /home/mathias/.ssh/identity
debug1: Trying private key: /home/mathias/.ssh/id_dsa
debug3: no such identity: /home/mathias/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug3: authmethod_lookup password
debug3: remaining preferred: ,password
debug3: authmethod_is_enabled password
debug1: Next authentication method: password

Er sagt ja "debug1: Offering public key: /home/mathias/.ssh/id_rsa" Was ja auch richtig so ist, aber dann passiert irgendwie nichts mehr und er macht weiter ...

Hat jemand ne Idee?

cu
serow
 
Code:
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/mathias/.ssh/identity
debug3: no such identity: /home/mathias/.ssh/identity
debug1: Trying private key: /home/mathias/.ssh/id_dsa
debug3: no such identity: /home/mathias/.ssh/id_dsa
debug2: we did not send a packet, disable method
Wo ist der private key, wo ist der publickey? Du brauchst beides auf dem Client und den publickey auf dem Server.

So wie es ausschaut sendet er nicht den publickey sondern den private key:

Code:
debug1: Offering public key: /home/mathias/.ssh/id_rsa

Und das geht natürlich in die Hose. Hast du etwas in .ssh/config zu stehen?

Und Achtung: RSA != DSA (vgl. id_rsa v. id_dsa). Nicht diese beiden Methoden vermischen. Ein RSA-Pubkey kann schlecht mit einem DSA-Privatekey zusammenarbeiten oder umgekehrt.
 
Zuletzt bearbeitet:
Hi,

also so siehts auf meinem Client aus bzgl des Ortes und des Inhalts des Public Keys.

Code:
mathias@mini:~$ ls -l .ssh
total 12
-rw------- 1 mathias mathias 1743 2010-03-19 09:42 id_rsa
-rw-r--r-- 1 mathias mathias  394 2010-03-19 09:42 id_rsa.pub
-rw-r--r-- 1 mathias mathias 1768 2010-03-19 11:42 known_hosts
mathias@mini:~$ cat .ssh/id_rsa.pub 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAssGjYzETS+7sBOFjz+WMys7iZ46m8ojVMWaSTTBWaCo0CQXu3lwzXWhJNH1s4/WMyV2RGanAuEC3wUrxVxeZthtVcRG6njgUARO2p0qen5tzkJHLEoab4mEq3jptOMNDJxYO0o6XUzodk+/g0bHtHr2XwYcH3r7DO022SD/mYGZ+9pn0j86EfSt2BtGUh8F+TRbIlbmy4Mn6xQ7yrfaY/+4aa9DlNPtOtibY4+Lufl22CHyTGfUZM9X7vkqMfdFG8uTWsLKtdveUh/9DyQHj8rAegRnQzeZ9eOAKsNfeR5/plP35VuzDs2xwYKId+bu/xAL/B+CwaMZw4waIvPwEFQ== mathias@mini
mathias@mini:~$

Eine eigene client config habe ich nicht, aber ich kann dir mal die globale posten:
Code:
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-cbc,3des-cbc,blowfish-cbc,cast128-cbc,arcfour,aes192-cbc,aes256-cbc
#   MACs hmac-md5,hmac-sha1,umac-64@openssh.com,hmac-ripemd160
#   EscapeChar ~
#   Tunnel no
#   TunnelDevice any:any
#   PermitLocalCommand no
    SendEnv LANG LC_*
    HashKnownHosts yes
    GSSAPIAuthentication yes
    GSSAPIDelegateCredentials no

Ist aber die standard config.

Auf dem Server ist der public key installiert:

Code:
mathias@ironman:~$ cat .ssh/authorized_keys 
ssh-rsa AAAAB3NzaC1yc2EAAAABIwAAAQEAssGjYzETS+7sBOFjz+WMys7iZ46m8ojVMWaSTTBWaCo0CQXu3lwzXWhJNH1s4/WMyV2RGanAuEC3wUrxVxeZthtVcRG6njgUARO2p0qen5tzkJHLEoab4mEq3jptOMNDJxYO0o6XUzodk+/g0bHtHr2XwYcH3r7DO022SD/mYGZ+9pn0j86EfSt2BtGUh8F+TRbIlbmy4Mn6xQ7yrfaY/+4aa9DlNPtOtibY4+Lufl22CHyTGfUZM9X7vkqMfdFG8uTWsLKtdveUh/9DyQHj8rAegRnQzeZ9eOAKsNfeR5/plP35VuzDs2xwYKId+bu/xAL/B+CwaMZw4waIvPwEFQ== mathias@mini
mathias@ironman:~$

cu
serow
 
Wie oder mit welchem Kommando hast du die Keys erstellt? Was verbindet sich zu wem (distributionstechnisch)?
 
Hi,

einfach "ssh-keygen" ohne weitere Parameter. Es verbindet sich ubuntu karmic zu debian lenny.

Kann man irgendwie zuverlässig prüfen ob die beiden Keys zusammenpassen? Nicht dass da irgendwas schief gelaufen ist.

cu
serow
 
Bitte mal das Syslog auf dem Server prüfen (besonders auth und daemon).

Eventuell sollte man auch einen Link von authorized_keys auf authorized_keys2 versuchen (Debian könnte eventuell so anal sein).

Der Publickey passt anscheinend nicht zum Privatekey, jedenfalls lässt das der Output vermuten. SSH sendet einen Publickey
Code:
debug1: Offering public key: /home/mathias/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply

... und bekommt darauf keine Antwort und probiert dann weitere Möglichkeiten (identity (SSHv1) und id_dsa) aus. Normalerweise müsste der Output ungefähr so aussehen:
Code:
debug1: Offering public key: /Users/moe/.ssh/id_rsa
debug3: send_pubkey_test
debug2: we sent a publickey packet, wait for reply
debug1: Server accepts key: pkalg ssh-rsa blen 277

Falls nichts im Syslog auftaucht würde ich die Keys nochmal komplett neu generieren und dabei darauf achten, dass wirklich die richtigen Keys zueinander passen und kopiert werden.
 
Hi,

ich hab der auth.log was gefunden:

Code:
Mar 19 13:13:37 ironman sshd[3862]: Authentication refused: bad ownership or modes for directory /home/mathias

Die Permissions waren auf mathias:mathias 771 weil ich wollte, dass man das Verzeichnis nicht listen kann, aber Files deren Pfad man kennt rausziehen kann. Ich habs nun auf 755 geändert und schon gehts wieder.

Kann man das nicht miteinander verheiraten??

cu
serow
 
SSH beschwert sich dabei nicht über das fehlende Read-Bit oder Write-Bit für ALL sondern über die vorhandenen Read-, Write- und -Exec-Bits bei GROUP. Hast du es mal mit 0751 probiert?

Außerdem: Die Bitmasken für ~/.ssh und ~/.ssh/authorized_keys(2) sollten immer auf 0700 bzw. 0600 sitzen.
 
SSH beschwert sich dabei nicht über das fehlende Read-Bit oder Write-Bit für ALL sondern über die vorhandenen Read-, Write- und -Exec-Bits bei GROUP. Hast du es mal mit 0751 probiert?

Wie soll man das den erraten? :D

Außerdem: Die Bitmasken für ~/.ssh und ~/.ssh/authorized_keys(2) sollten immer auf 0700 bzw. 0600 sitzen.

Gibts nen anderen Grund außer um den Private Key zu schützen? Dafür würden ja entsprechende Permissions auf dem File genügen.

cu
serow
 
Wie soll man das den erraten?

Steht in der Dokumentation.

Gibts nen anderen Grund außer um den Private Key zu schützen? Dafür würden ja entsprechende Permissions auf dem File genügen.
Security through obscurity zum Beispiel. Wenn niemand herausfinden, ob es einen Private-Key gibt, dann will ihn auch keiner haben.

Darüber hinaus lassen sich in .ssh/config und .ssh/known_hosts sehr gute Angriffsflächen ausmachen. Bei mir steht z.B. drin, an welchen Ports bei welchen Hosts die SSH-Daemons laufen.
 
Zurück
Oben