79 Stimmen

Wie ssh zu localhost ohne Passwort?

EDIT: Genaue Angabe, was gemacht wurde

Ich muss SSH localhost ohne Passwort, die übliche Art und Weise zu tun (mit öffentlichen Schlüsseln) nicht funktionieren.

user@PC:~$ rm -rf .ssh/*
user@PC:~$ ssh-keygen -t rsa > /dev/null 
Enter file in which to save the key (/home/user/.ssh/id_rsa): 
Enter passphrase (empty for no passphrase): 
Enter same passphrase again: 
user@PC:~$ ls .ssh/
id_rsa  id_rsa.pub
user@PC:~$ ssh-copy-id -i localhost 
The authenticity of host 'localhost (::1)' can't be established.
RSA key fingerprint is f7:87:b5:4e:31:a1:72:11:8e:5f:d2:61:bd:b3:40:1a.
Are you sure you want to continue connecting (yes/no)? yes
Warning: Permanently added 'localhost' (RSA) to the list of known hosts.
user@localhost's password: 
Now try logging into the machine, with "ssh 'localhost'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

user@PC:~$ ssh-agent $SHELL
user@PC:~$ ssh-add -L
The agent has no identities.
user@PC:~$ ssh-add 
Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
user@PC:~$ ssh-add -L
ssh-rsa ...MY KEY HERE

user@PC:~$ ssh-copy-id -i localhost 
user@localhost's password: 
Now try logging into the machine, with "ssh 'localhost'", and check in:

  .ssh/authorized_keys

to make sure we haven't added extra keys that you weren't expecting.

user@PC:~$ ssh localhost echo 'testing'
user@localhost's password: 

user@PC:~$ 

Wie Sie im letzten Befehl sehen können, wird immer noch das Passwort abgefragt! Wie kann ich das beheben? Ubuntu-10.04, OpenSSH_5.3p1

EDIT2:

Hinzufügen einiger Informationen über den sshd

user@PC:~$ cat /etc/ssh/sshd_config | grep Authentication
# Authentication:
RSAAuthentication yes
PubkeyAuthentication yes
RhostsRSAAuthentication no
HostbasedAuthentication no
# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
ChallengeResponseAuthentication no
# PasswordAuthentication yes

EDIT3: Hinzufügen des Ergebnisses von $ssh -vv localhost

$ssh -vv localhost
...
debug1: Authentications that can continue: publickey,password
debug1: Next authentication method: publickey
debug1: Trying private key: /home/user/.ssh/identity
debug1: Offering public key: /home/user/.ssh/id_rsa
debug2: we sent a publickey packet, wait for reply
debug1: Authentications that can continue: publickey,password
debug1: Trying private key: /home/user/.ssh/id_dsa
debug2: we did not send a packet, disable method
debug1: Next authentication method: password
user@localhost's password:

1voto

田小小 Punkte 26

Ich stieß auf das gleiche Problem beim Ausführen von Unit-Tests auf Docker-Container (golang:1.13-alpine).

Nach sshd -Dd y ssh -vv root@localhost Debugging habe ich den Grund gefunden:

Benutzer Root nicht erlaubt, weil Konto gesperrt ist

Wir sollten also das Konto freischalten durch passwd -u oder ein Passwort festlegen.

1voto

Chris Lindseth Punkte 631

Eine Sache, die Sie überprüfen sollten, wenn Sie eine bekannt gute Konfiguration für ssh haben, ist, dass Ihre /etc/hosts.allow einen Verweis auf localhost enthält, da die Quell-IP für eine localhost-Verbindung von 127.0.0.1 kommen würde und nicht von Ihrer Netzwerk-IP. Ich war eine Zeit lang ratlos, aber nachdem ich das Folgende zu /etc/hosts.allow hinzugefügt hatte, funktionierte meine Konfiguration sofort.

ALL: 127.0.0.1/32

Ich dachte, ich würde dies hinzufügen, da keine der anderen Antworten es erwähnt und dies war der Top-Treffer von meiner Suche nach dem gleichen Fehler.

0voto

Rafael Leonhardt Punkte 394

Ich habe mein Problem behoben, indem ich die AllowUsers in der Datei sshd_config gesetzt habe.

Ausführen des Servers mit Debugging:

$sshd -Dd

Ich habe festgestellt, dass mein Benutzer dies nicht darf

$sudo vi /etc/ssh/sshd_config

Fügen Sie eine Zeile mit nach #Authentifizierung hinzu:

AllowUsers meinBenutzer

0voto

mzycki Punkte 1

RHEL8

In meinem Fall hat es nach erfolgreicher Schlüsselkonfiguration immer noch nicht funktioniert. Ich fand folgenden Fehler in /var/log/secure:

pam_access(sshd:account): access denied for user `username' from `::1'

Also musste ich sie bearbeiten:

/etc/security/access.conf

Und fügen Sie dort '::1' zu den erlaubten Hosts hinzu, indem Sie eine Zeile hinzufügen:

+:<username>:LOCAL ::1

Es begann sofort zu funktionieren, auch ohne Neustart von sshd Dienstleistung.

CodeJaeger.com

CodeJaeger ist eine Gemeinschaft für Programmierer, die täglich Hilfe erhalten..
Wir haben viele Inhalte, und Sie können auch Ihre eigenen Fragen stellen oder die Fragen anderer Leute lösen.

Powered by:

X