Hilfe: SSH-Auto-Login mit Zertifikaten

Alles rund um sicherheitsrelevante Fragen und Probleme.
Antworten
RUDITERROR
Beiträge: 12
Registriert: 18.10.2019 10:51:21

Hilfe: SSH-Auto-Login mit Zertifikaten

Beitrag von RUDITERROR » 18.10.2019 11:07:00

Hallo,

ich möchte für meine Backup-Scripts ein ssh-login auf ein remote-system durchführen (Distribution: Raspbian). Hierfür habe ich auf System A Zertifikate angelegt und auf System B übertragen:

Code: Alles auswählen

pi@mapi:~/.ssh $ ssh-keygen -t rsa
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa): /home/pi/.ssh/mapi
Enter passphrase (empty for no passphrase):<nix angegeben>
Enter same passphrase again:<nix angegeben>
Your identification has been saved in /home/pi/.ssh/mapi.
Your public key has been saved in /home/pi/.ssh/mapi.pub.
The key fingerprint is:
SHA256:DhLXvEWIl9PQQdS/0u4ZRCBzV/4COGzU7DlPYi8hOZo pi@mapi
The key's randomart image is:
+---[RSA 2048]----+
|       ..OO=o ...|
|      .o=+o=+o . |
|    . ..o.*o.o. .|
|     o   ++.Boo .|
|    . . So + Oo..|
|     . oE   o.=. |
|        .    +.  |
|              .o |
|             .o  |
+----[SHA256]-----+
pi@mapi:~/.ssh $ ssh-copy-id -i ~/.ssh/mapi.pub pi@192.168.0.10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/pi/.ssh/mapi.pub"
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already installed
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the new keys
Password:
Verification code:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'pi@192.168.0.10'"
and check to make sure that only the key(s) you wanted were added.
So weit so gut, das Problem ist nun, dass wenn ich ein Login versuche, eine Passwort-Angabe verlangt wird:

Code: Alles auswählen

pi@mapi:~/.ssh $ ssh pi@192.168.0.10
Password:

Code: Alles auswählen

root@mapi:/home/pi # ssh -v pi@192.168.0.10
OpenSSH_7.4p1 Raspbian-10+deb9u7, OpenSSL 1.0.2t  10 Sep 2019
debug1: Reading configuration data /etc/ssh/ssh_config
debug1: /etc/ssh/ssh_config line 19: Applying options for *
debug1: Connecting to 192.168.0.10 [192.168.0.10] port 22.
debug1: Connection established.
debug1: permanently_set_uid: 0/0
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_rsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_dsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ecdsa-cert type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519 type -1
debug1: key_load_public: No such file or directory
debug1: identity file /root/.ssh/id_ed25519-cert type -1
debug1: Enabling compatibility mode for protocol 2.0
debug1: Local version string SSH-2.0-OpenSSH_7.4p1 Raspbian-10+deb9u7
debug1: Remote protocol version 2.0, remote software version OpenSSH_7.4p1 Raspbian-10+deb9u7
debug1: match: OpenSSH_7.4p1 Raspbian-10+deb9u7 pat OpenSSH* compat 0x04000000
debug1: Authenticating to 192.168.0.10:22 as 'pi'
debug1: SSH2_MSG_KEXINIT sent
debug1: SSH2_MSG_KEXINIT received
debug1: kex: algorithm: curve25519-sha256
debug1: kex: host key algorithm: ecdsa-sha2-nistp256
debug1: kex: server->client cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: kex: client->server cipher: chacha20-poly1305@openssh.com MAC: <implicit> compression: none
debug1: expecting SSH2_MSG_KEX_ECDH_REPLY
debug1: Server host key: ecdsa-sha2-nistp256 SHA256:RC8K9QuFkC7VKti1BRPMcz7x5IWNoTZwsFt6sLOLc0I
debug1: Host '192.168.0.10' is known and matches the ECDSA host key.
debug1: Found key in /root/.ssh/known_hosts:1
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_NEWKEYS sent
debug1: expecting SSH2_MSG_NEWKEYS
debug1: SSH2_MSG_NEWKEYS received
debug1: rekey after 134217728 blocks
debug1: SSH2_MSG_EXT_INFO received
debug1: kex_input_ext_info: server-sig-algs=<ssh-ed25519,ssh-rsa,ssh-dss,ecdsa-sha2-nistp256,ecdsa-sha2-nistp384,ecdsa-sha2-nistp521>
debug1: SSH2_MSG_SERVICE_ACCEPT received
debug1: Authentications that can continue: publickey,password,keyboard-interactive
debug1: Next authentication method: publickey
debug1: Trying private key: /root/.ssh/id_rsa
debug1: Trying private key: /root/.ssh/id_dsa
debug1: Trying private key: /root/.ssh/id_ecdsa
debug1: Trying private key: /root/.ssh/id_ed25519
debug1: Next authentication method: keyboard-interactive
Password:

Um die Anmelde-Sicherheit zu erhöhen habe ich auf meinen Systemen eine 2-Faktor-Authentifizierung nach folgender Anleitung aktiviert:
https://strobelstefan.org/?p=4886

Inhalt der Datei /etc/ssh/sshd_config

Code: Alles auswählen

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

PubkeyAuthentication yes

# Expect .ssh/authorized_keys2 to be disregarded by default in future.
#AuthorizedKeysFile     .ssh/authorized_keys .ssh/authorized_keys2

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

# To disable tunneled clear text passwords, change to no here!
#PasswordAuthentication no
#PermitEmptyPasswords no
# Change to yes to enable challenge-response passwords (beware issues with
# some PAM modules and threads)
ChallengeResponseAuthentication yes

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

# GSSAPI options
#GSSAPIAuthentication no
#GSSAPICleanupCredentials yes
#GSSAPIStrictAcceptorCheck yes
#GSSAPIKeyExchange no

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

# no default banner path
#Banner none

# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# override default of no subsystems
Subsystem       sftp    /usr/lib/openssh/sftp-server

# Example of overriding settings on a per-user basis
#Match User anoncvs
#       X11Forwarding no
#       AllowTcpForwarding no
#       PermitTTY no
#       ForceCommand cvs server
Ich versuche schon seit einiger Zeit die SSH-Anmeldung mittels Zertifikaten zum laufen zu bringen. Leider erhalte ich jedoch immer eine Passwort-Aufforderung. Hat jemand von euch einen Tipp für mich, wie ich den Fehler beheben kann?

Vielen Dank!

Grüße, Rudi

Benutzeravatar
jph
Beiträge: 1050
Registriert: 06.12.2015 15:06:07
Lizenz eigener Beiträge: MIT Lizenz
Wohnort: Greven/Westf.

Re: Hilfe: SSH-Auto-Login mit Zertifikaten

Beitrag von jph » 18.10.2019 15:17:39

Du hast die falsche Syntax verwendet:

Code: Alles auswählen

ssh-copy-id 192.168.0.10
ist richtig.

Mit der Option -i gibst du die Quelle an! Lies die Manpage.

Warum benennst die die Keydateien um?

RUDITERROR
Beiträge: 12
Registriert: 18.10.2019 10:51:21

Re: Hilfe: SSH-Auto-Login mit Zertifikaten

Beitrag von RUDITERROR » 18.10.2019 16:33:35

Hallo und vielen Dank!

Ich denke, das Problem lag an der Umbennung des Zertifikats:

Code: Alles auswählen

pi@mapi:~ $ ssh-copy-id pi@192.168.0.10

/usr/bin/ssh-copy-id: ERROR: failed to open ID file '/home/pi/.pub': No such file
        (to install the contents of '/home/pi/.pub' anyway, look at the -f option)

Code: Alles auswählen

pi@mapi:~ $ rm -r ./.ssh/

Code: Alles auswählen

pi@mapi:~ $ ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/pi/.ssh/id_rsa):
Created directory '/home/pi/.ssh'.
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /home/pi/.ssh/id_rsa.
Your public key has been saved in /home/pi/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:hFsStyYKYhXCxQr/N57JgZujkTKDdwsTHN0kO/zsM+g pi@mapi
The key's randomart image is:
+---[RSA 2048]----+
|..o+o o .        |
|..o+ = + .       |
|oo+ = = =        |
|.+.o = B         |
|  o...+ S        |
|.  ooo+          |
|= * o*+=         |
| = *+.=o         |
|  ..E.           |
+----[SHA256]-----+

Code: Alles auswählen

pi@mapi:~ $ ssh-copy-id pi@192.168.0.10
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/pi/.ssh/id_rsa.pub"
The authenticity of host '192.168.0.10 (192.168.0.10)' can't be established.
ECDSA key fingerprint is SHA256:RC8K9QuFkC7VKti1BRPMcz7x5IWNoTZwsFt6sLOLc0I.
Are you sure you want to continue connecting (yes/no)? yes
/usr/bin/ssh-copy-id: INFO: attempting to log in with the new key(s), to filter out any that are already inst
/usr/bin/ssh-copy-id: INFO: 1 key(s) remain to be installed -- if you are prompted now it is to install the n
Password:
Verification code:

Number of key(s) added: 1

Now try logging into the machine, with:   "ssh 'pi@192.168.0.10'"
and check to make sure that only the key(s) you wanted were added.

pi@mapi:~ $ ssh 'pi@192.168.0.10'
Linux Repi 4.19.42-v7+ #1219 SMP Tue May 14 21:20:58 BST 2019 armv7l

######  ####### ######  ###
#     # #       #     #  #
#     # #       #     #  #
######  #####   ######   #
#   #   #       #        #
#    #  #       #        #
#     # ####### #       ###
Last login: Thu Oct 17 07:47:31 2019 from 2a03:567:1::13
pi@Repi:~ $

DeletedUserReAsG

Re: Hilfe: SSH-Auto-Login mit Zertifikaten

Beitrag von DeletedUserReAsG » 18.10.2019 18:37:48

Zertifikate und Schlüssel sind verschiedene Dinge. Dein Threadtitel ist entsprechend falsch.

Antworten