• Willkommen im Linux Club - dem deutschsprachigen Supportforum für GNU/Linux. Registriere dich kostenlos, um alle Inhalte zu sehen und Fragen zu stellen.

Gelöst SSH PreferredAuthentications

Karmaset

Newbie
Hallo,

ich benutze seit langer Zeit ssh um auf meine Systeme zuzugreifen. Dabei benutze ich die ssh config Datei um mir die Arbeit zu erleichtern.

Nun habe ich die PreferredAuthentication Option hinzugefügt um das PublicKey Verfahren zu priorisieren. Leider erhalte ich beim Verbindungsaufbau (zur Verdeutlichung via -o Parameter) immer folgende Fehlermeldung:

ssh system1 -o PreferredAuthentications=publickey
user1@192.168.x.y: Permission denied (publickey,password).
Komischerweise kann ich mich über die Angabe des Keys (-i) oder über die "IdentityFile" in der ssh config ohne Probleme auf das System verbinden.
Bei beiden Systemen Quell und Ziel handelt es sich um Ubuntu Desktop Versionen.

Hat jemand irgendeine Idee was ich falsch machen könnte ?
 
OP
Karmaset

Karmaset

Newbie
Danke für deine Antwort.

Ich würde gerne die PublicKey Authentifizierung der Passwort Auth vorziehen wenn beide Authentifizierungsmethoden aktiv sind. Die reine Nutzung von "Identitiyfiles" hilft mir hier nicht.
 

Sauerland

Ultimate Guru
Dann stell das doch in der ssh_config ein:
Code:
PreferredAuthentications
             Legt die Reihenfolge fest, in der die Clients Authentifizierungsmethoden ausprobieren sollen. Dies erlaubt es Clients, eine bestimmte Methode (z.B. keyboard-interactive) gegenüber anderen
Methoden (z.B. password) zu bevorzugen. Die Vorgabe lautet:

gssapi-with-mic,hostbased,publickey,
keyboard-interactive,password
siehe man ssh_config
 
OP
Karmaset

Karmaset

Newbie
Füge ich die von Dir bzw. der man page beschriebene Zeile ein
PreferredAuthentications gssapi-with-mic,hostbased,publickey,keyboard-interactive,password
Werde ich aufgefordert mein Passwort anstatt der gewünschten Passphrase für den Key einzugeben.
 

Sauerland

Ultimate Guru
Code:
gewünschten Passphrase für den Key einzugeben.
Das hab ich auch nicht, dadurch kann ich mich ohne irgendeine Eingabe verbinden:
z.B.
Code:
ssh laptop
und sofort bin ich auf meinem Laptop.
 
OP
Karmaset

Karmaset

Newbie
Du wirst wahrscheinlich den ssh agent im OS im Hintergrund laufen haben,
deshalb ist die Passphrase auch nicht mehr einzugeben.

Bei mir muss ich explizit das Passwort des Users des Zielrechners eingeben.
 

Sauerland

Ultimate Guru
Ich hab nur nen ssh-Server am laufen.......

Und bei ssh-keygen keine Passphrase eingegeben, einfach Enter gedrückt.
 
OP
Karmaset

Karmaset

Newbie
Gut, wenn du keine Passphrase bei der Erstellung eingegeben hast dann hast du auch keine Passworteingabe.
Kannst du mir nochmal bitte bestätigen, dass du genau diesen Parametern in der ssh config benutzt.
 

Sauerland

Ultimate Guru
Hier mal eine schnelle Einrichtung von ssh:
Server = Kubuntu
Client = openSUSE

Code:
stephan@linux64:~> ssh stephan@192.168.0.130
The authenticity of host '192.168.0.130 (192.168.0.130)' can't be established.
ECDSA key fingerprint is SHA256:gEolriasbb7xTiSVBax9Y+541PdVfnfD/sQ0YRy+26g.
Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
Warning: Permanently added '192.168.0.130' (ECDSA) to the list of known hosts.
stephan@192.168.0.130's password:
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-27-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage

The programs included with the Ubuntu system are free software;
the exact distribution terms for each program are described in the
individual files in /usr/share/doc/*/copyright.

Ubuntu comes with ABSOLUTELY NO WARRANTY, to the extent permitted by
applicable law.

stephan@kubuntu-2204:~$
logout
Connection to 192.168.0.130 closed.
stephan@linux64:~> ssh-keygen
Generating public/private rsa key pair.
Enter file in which to save the key (/home/stephan/.ssh/id_rsa):
/home/stephan/.ssh/id_rsa already exists.
Overwrite (y/n)? n (abgebrochen, da ich meinen key nicht ändern wollte)
stephan@linux64:~> ssh-copy-id stephan@192.168.0.130
/usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/stephan/.ssh/id_rsa.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
stephan@192.168.0.130's password:

Number of key(s) added: 1

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

stephan@linux64:~> ssh stephan@192.168.0.130
Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-27-generic x86_64)

 * Documentation:  https://help.ubuntu.com
 * Management:     https://landscape.canonical.com
 * Support:        https://ubuntu.com/advantage
Last login: Mon Jun  6 11:50:09 2022 from 192.168.0.2
stephan@kubuntu-2204:~$

Jetzt könnte ich die Passwort Authentifizierung ausschalten, hier geschehen:
Code:
grep -i passwordauthentication /etc/ssh/sshd_config
PasswordAuthentication no
 

Sauerland

Ultimate Guru
Und nun mit key und passphrase:
Server = Kubuntu
Client = Debian
Code:
    stephan@qemu-debian11:~$ ssh stephan@192.168.0.130
    The authenticity of host '192.168.0.130 (192.168.0.130)' can't be established.
    ECDSA key fingerprint is SHA256:gEolriasbb7xTiSVBax9Y+541PdVfnfD/sQ0YRy+26g.
    Are you sure you want to continue connecting (yes/no/[fingerprint])? yes
    Warning: Permanently added '192.168.0.130' (ECDSA) to the list of known hosts.
    stephan@192.168.0.130's password:
    Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-27-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    Last login: Mon Jun  6 12:00:17 2022 from 192.168.0.2
    stephan@kubuntu-2204:~$
    logout
    Connection to 192.168.0.130 closed.
    stephan@qemu-debian11:~$ ssh-keygen
    Generating public/private rsa key pair.
    Enter file in which to save the key (/home/stephan/.ssh/id_rsa):
    Enter passphrase (empty for no passphrase):
    Enter same passphrase again:
    Your identification has been saved in /home/stephan/.ssh/id_rsa
    Your public key has been saved in /home/stephan/.ssh/id_rsa.pub
    The key fingerprint is:
    SHA256:TDLnoVMUr9aQLqxBjU4GVC1v9LdzDiv7Z0u1GhtPeRA stephan@qemu-debian11
    The key's randomart image is:
    +---[RSA 3072]----+
    | .o...  o.       |
    |   ..oo. o       |
    |    =++.B .   E  |
    |   = .o@.=.    . |
    |    o.= S...  o  |
    |     o +  + .. + |
    |    .      *+ + .|
    |        . ..+B . |
    |        .+.o+..  |
    +----[SHA256]-----+
    stephan@qemu-debian11:~$ ssh-copy-id stephan@192.168.0.130
    /usr/bin/ssh-copy-id: INFO: Source of key(s) to be installed: "/home/stephan/.ssh/id_rsa.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
    stephan@192.168.0.130's password:
    
    Number of key(s) added: 1
    
    Now try logging into the machine, with:   "ssh 'stephan@192.168.0.130'"
    and check to make sure that only the key(s) you wanted were added.
    
    stephan@qemu-debian11:~$ ssh stephan@192.168.0.130
    Enter passphrase for key '/home/stephan/.ssh/id_rsa':
    Welcome to Ubuntu 22.04 LTS (GNU/Linux 5.15.0-27-generic x86_64)
    
     * Documentation:  https://help.ubuntu.com
     * Management:     https://landscape.canonical.com
     * Support:        https://ubuntu.com/advantage
    Last login: Mon Jun  6 12:26:36 2022 from 192.168.0.220
    stephan@kubuntu-2204:~$

Es wird die bei ssh-keygen benutzte Passphrase abgefragt.
 
OP
Karmaset

Karmaset

Newbie
Ich habe die Lösung gefunden. Es hatte nix mit der PreferredAuthentication zu tun.

Ich habe am Ende der config folgenden Eintrag:

Host *
IdentitiesOnly yes
Die hat zur Fehlermeldung geführt, da zwingend auch dort (also bei Host *) der "IdentityFile" Eintrag liegen muss. Wenn dieser in der Definition des einzelnen Hosts liegt, dann führt er den Fallback auf Passwort durch.
 
Oben