EDIT: Putting genau das, was getan wurde.
Ich muss SSH auf localhost
ohne Passwort ausführen, die übliche Vorgehensweise (mit öffentlichen Schlüsseln) funktioniert nicht.
[email protected]:~$ rm -rf .ssh/*
[email protected]:~$ 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:
[email protected]:~$ ls .ssh/
id_rsa id_rsa.pub
[email protected]:~$ 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.
[email protected]'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.
[email protected]:~$ ssh-agent $Shell
[email protected]:~$ ssh-add -L
The agent has no identities.
[email protected]:~$ ssh-add
Identity added: /home/user/.ssh/id_rsa (/home/user/.ssh/id_rsa)
[email protected]:~$ ssh-add -L
ssh-rsa ...MY KEY HERE
[email protected]:~$ ssh-copy-id -i localhost
[email protected]'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.
[email protected]:~$ ssh localhost echo 'testing'
[email protected]'s password:
[email protected]:~$
Wie Sie im letzten Befehl sehen können, werden Sie immer noch nach dem Passwort gefragt !!! Wie kann ich das beheben? Ubuntu-10.04, OpenSSH_5.3p1
EDIT2:
Hinzufügen von Informationen zum sshd
[email protected]:~$ 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
#KerberosAuthentication no
#GSSAPIAuthentication no
# be allowed through the ChallengeResponseAuthentication and
# PasswordAuthentication. Depending on your PAM configuration,
# PAM authentication via ChallengeResponseAuthentication may bypass
# PAM authentication, then enable this but set PasswordAuthentication
# and ChallengeResponseAuthentication to 'no'.
EDIT3: Ading-Ergebnis 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
[email protected]'s password:
EDIT4:
Ich überprüfe nur, ob die Dateien identisch sind und die MD5-Summe übereinstimmt
Habe das Problem entdeckt.
Server mit Debugging ausführen:
$sshd -Dd
Ich fand, dass es nicht in der Lage war, den auth_key zu lesen
$chmod 750 $HOME
Behoben.
Zunächst sollten Sie verstehen, was Sie tun:
[email protected]:~$ cat .ssh/id_rsa.pub | ssh localhost 'cat >> .ssh/authorized_keys'
Sie kopieren den öffentlichen Schlüssel .ssh/id_rsa.pub
über ssh auf denselben Host (das ist localhost, derselbe Host). Wenn Sie localhost
durch einen anderen Host ersetzen, ist dies sinnvoller (aber wenn Sie dies versuchen, um zu lernen, wie es geht, ist das in Ordnung).
Sobald Sie eine Kopie Ihres öffentlichen Schlüssels auf dem Remote-Host haben (oder auf dem gleichen, in dem Sie sich befinden), müssen Sie sicherstellen, dass Sie ihn für die Authentifizierung in Ihrem tatsächlichen Host verwenden und ssh-agent
/ssh-add
aufrufen:
$ eval `ssh-agent`
$ ssh-add
Wenn Sie dann eine Passphrase eingegeben haben, werden Sie aufgefordert, diese nach ssh-add
einzugeben. Wenn Sie einen privaten Schlüssel ohne Passphrase generiert haben, ist das alles.
Führen Sie die folgenden Schritte aus
ssh-keygen -t rsa -C "[email protected]"
# Creates a new ssh key, using the provided email as a label
# Generating public/private rsa key pair.
Standarddatei und leere Passphrase verwenden (in den nächsten 2 Schritten einfach die Eingabetaste drücken)
# start the ssh-agent in the background
eval "$(ssh-agent -s)"
# Agent pid 59566
ssh-add
Kopieren Sie den Inhalt von ~/.ssh/id_rsa.pub nach ~/.ssh/authorized_keys
Stellen Sie sicher, dass die folgenden Berechtigungen vorhanden sind
ls -l .ssh/
total 20
-rw-r--r--. 1 swati swati 399 May 5 14:53 authorized_keys
-rw-r--r--. 1 swati swati 761 Jan 12 15:59 config
-rw-------. 1 swati swati 1671 Jan 12 15:44 id_rsa
-rw-r--r--. 1 swati swati 399 Jan 12 15:44 id_rsa.pub
-rw-r--r--. 1 swati swati 410 Jan 12 15:46 known_hosts
Stellen Sie außerdem sicher, dass die Berechtigungen für das Verzeichnis .ssh vorliegen. Das ist auch wichtig
drwx------. 2 swati swati 4096 May 5 14:56 .ssh
Möglicherweise müssen Sie die kennwortbasierte Authentifizierung deaktivieren. Dies ist eine sshd_config, die ich benutze
Port 22
Protocol 2
PermitRootLogin no
StrictModes yes
PasswordAuthentication no
ChallengeResponseAuthentication no
MaxStartups 2
AllowUsers peter paul mary
LogLevel VERBOSE
Probieren Sie zuerst etwas Minimales aus und ergänzen Sie es dann, wenn Sie zusätzliche Funktionen benötigen.
Aktualisieren:
In EDIT3 wird angezeigt, dass die Authentifizierung mit öffentlichem Schlüssel fehlschlägt, bevor der Client eine kennwortbasierte Authentifizierung versucht. Das Syslog Ihres Servers kann einige Nachrichten von sshd enthalten, die etwas Licht in diese Richtung bringen.
Denken Sie daran, sshd
zu signalisieren, um alle Konfigurationsänderungen neu zu laden. Z.B. kill -HUP $(cat /etc/sshd.pid)
Für mich war es so einfach wie
cat id_rsa.pub >> authorized_keys
Ich hatte das gleiche Problem, ich habe die folgenden 3 Schritte ausgeführt, um das Passwort abzüglich der Anmeldung zu erstellen, und es funktioniert einwandfrei
1. ssh-keygen -t rsa
Press enter for each line
2. cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
3. chmod og-wx ~/.ssh/authorized_keys
Eine andere Lösung für die SELinux-Funktion von Red Hat Enterprise Linux 6.5, die verhindert, dass sshd $ HOME/.ssh liest, ist die Verwendung von restorecon. Den Antwortenden finden Sie hier https://superuser.com/a/764020/213743 .
In Bezug auf den obigen Beitrag habe ich die Zeile geändert, obwohl ich das gleiche Problem hatte
PasswordAuthentication no
in der Datei/etc/ssh/sshd_config und es hat funktioniert.
Darüber hinaus ist es vielleicht besser zu verwenden
dienst sshd Neustart
sshd Konfigurationsänderungen neu zu laden.