Hier werden die Unterschiede zwischen zwei Versionen angezeigt.
Beide Seiten der vorigen RevisionVorhergehende ÜberarbeitungNächste Überarbeitung | Vorhergehende Überarbeitung | ||
en:howtos:ssh [2022/02/18 08:31] – [Schritt 1: Die Anmeldung an einem Server] morquai | en:howtos:ssh [2022/02/18 08:40] (aktuell) – [Fazit: Beispiel einer .ssh/config] morquai | ||
---|---|---|---|
Zeile 28: | Zeile 28: | ||
ssh server.example.com | ssh server.example.com | ||
you will be promptly asked for your password. | you will be promptly asked for your password. | ||
- | ==== Schritt | + | ==== Step 2: this can also be done without a password |
- | Natürlich muss der Benutzer sich ausweisen, dafür ist aber nicht unbedingt ein Passwort erforderlich. Ein SSH Key (eine Art Ausweis) reicht auch aus, muss aber erstmal angelegt werden. Ich empfehle DRINGEND den Schlüssel mit einem Passwort | + | Of course, the user has to identify himself, but this does not necessarily require a password. An SSH key (a kind of ID) is also sufficient, but must first be created. I STRONGLY recommend protecting the key with a password |
- | ssh-keygen -t rsa -b 2048 -f <dateiname> | + | ssh-keygen -t rsa -b 2048 -f <filename> |
- | Lässt man "-f <dateiname>" | + | If you omit "-f <filename>", |
ssh-keygen -t rsa -b 2048 -f /tmp/rsakey | ssh-keygen -t rsa -b 2048 -f /tmp/rsakey | ||
Generating public/ | Generating public/ | ||
Zeile 40: | Zeile 40: | ||
The key fingerprint is: | The key fingerprint is: | ||
SHA256: | SHA256: | ||
- | The key' | + | The key' |
+---[RSA 2048]----+ | +---[RSA 2048]----+ | ||
| . ..o+.+o .o*+.E| | | . ..o+.+o .o*+.E| | ||
- | | o .o + ... Bo | | + | | o .o + ... Bo | |
- | | | + | | . + o Xo.o| |
- | | . o.o.o= =+.| | + | | . o.o.o= =".| |
- | | | + | | . . S+++ o o.| |
- | | o o o= | + | | o o o= . .| |
- | | | + | | o . .. | |
- | | .o | + | | .o | |
- | | | + | | .o.. | |
+----[SHA256]-----+ | +----[SHA256]-----+ | ||
- | Zur Sicherheit besteht der Schlüssel aus zwie Teilen, einem öffentlichen, der zur Verschlüsselung dient, und einem privaten Teil, der der Entschlüsselung dient. Der obige Befehl hat zwei Dateien angelegt, "/ | + | For security, the key consists of two parts, a public part that is used for encryption and a private part that is used for decryption. The above command created two files, "/ |
- | Um sich zu authentifizieren muss auf dem Server der Public Key und auf dem Client der Private Key "eingetragen" | + | In order to authenticate yourself, the public key must be "entered" |
mv / | mv / | ||
ls -ld / /home/ /home/user/ / | ls -ld / /home/ /home/user/ / | ||
- | drwxr-xr-x | + | drwxr-xr-x 32 root system 4096 Jul 17 15:49 / |
- | drwxr-xr-x | + | drwxr-xr-x 261 am 16384 am Sep 11 00:55 /home |
- | drwxr-xr-x | + | drwxr-xr-x 14 user group 4096 Sep 18 14:23 / |
- | drwx------ | + | drwx------ 3 user group 4096 Sep 08 12:23 / |
- | -rw------- | + | -rw------- 1 user group 1679 Aug 30 2016 / |
- | -rw-r--r-- | + | -rw-r--r-- 1 user group 1679 Aug 30 2016 / |
- | Damit haben wir auf der Client Seite erstmal alles erledigt und können nun der Public Key auf den Server packen. Die einfachste Methde ist der folgende | + | We have now done everything on the client side and can now pack the public key on the server. The simplest method is the following |
ssh-copy-id -i / | ssh-copy-id -i / | ||
- | Dabei wird, letztmalig, das Passwort des Benutzers | + | The password of the user " |
- | | + | |
- | HostName | + | HostName server1.example.com |
- | Port 921 | + | Port 921 |
- | User username | + | User username |
- | DynamicForward | + | DynamicForward 3129 |
- | LocalForward | + | LocalForward 1234 server2: |
- | LocalForward | + | LocalForward 3210 server: |
- | IdentityFile | + | IdentityFile ~/ |
- | Damit haben wir die Passwort Abrage des Servers deaktiviert und müssen nun die Passphrase des SSH Keys eingeben. Damit haben wir aber leider nur die eine Passwortabfrage durch eine andere ersetzt. | + | We have deactivated the server' |
- | ==== Schritt | + | ==== Step 3: One password request per day ==== |
- | Die openssh | + | The openssh |
- | ssh-agent | + | ssh agent |
SSH_AUTH_SOCK=/ | SSH_AUTH_SOCK=/ | ||
SSH_AGENT_PID=10682402; | SSH_AGENT_PID=10682402; | ||
echo Agent pid 10682402; | echo Agent pid 10682402; | ||
- | Damit ist der Agent gestartet und die Befehle, die eine Benutzung ermöglichen, | + | The agent is now started and the commands that enable use are issued. The agent stays active until the next reboot, so we can write the commands to a file and then run them in the current shell. Let's name the file ~/ |
SSH_AUTH_SOCK=/ | SSH_AUTH_SOCK=/ | ||
SSH_AGENT_PID=10682402; | SSH_AGENT_PID=10682402; | ||
echo Agent pid 10682402; | echo Agent pid 10682402; | ||
- | Und nun die Ausführung, der Punkt am Anfang signalisiert, | + | And now the execution, the dot at the beginning signals that the script is executed |
. ~/ | . ~/ | ||
- | Nachdem der Agent gestartet wurde und die Benutzung eingerichtet ist, müssen wir nun dem Agenten den Private Key zur Verfügung stellen | + | After the agent has been started and the use has been set up, we now have to provide the agent with the private key |
ssh-add ~/ | ssh-add ~/ | ||
- | Der Agent fordert uns auf die Passphrase einzugeben und kann nun die Aufgabe, den Private Key bei Bedarf zur Verfügung zu stellen, übernehmen. Die Anmeldung kann nun ohne jede Passwort Abfrage gemacht werden. | + | The agent asks us to enter the passphrase and can now take over the task of providing the private key if required. The registration can now be made without any password query. |
ssh server.example.com | ssh server.example.com | ||
- | Geschafft. die Passworteingabe ist ab nun nicht mehr erforderlich. Wir müssen nur nach einen Reboot daran denken den Agenten erneut zu starten und die ausgegebenen Befehle in die Datei ~/ | + | Made it. from now on it is no longer necessary to enter a password. We only have to remember to start the agent again after a reboot and write the issued commands to the ~/ |
- | Wenn wir eine neue Shell starten muss natürlich auch hier die ~/ | + | Of course, if we start a new shell, |
- | **Hinweis: wer PuTTY und openssh | + | **Note: if you use PuTTY and openssh |
+ | ==== Step 4: Use the SSH key also from server.example.com ==== | ||
- | ==== Schritt 4: Den SSH Key auch von server.example.com aus benutzen ==== | + | Often you will find a whole server |
- | + | **A private key must NEVER leave the client.**\\ | |
- | Oft findet man eine ganze Serverlandschaft, auf der man sich anmelden kann. Wenn man erst einmal den öffentlichen Teil des SSH Keys auf allen Servern hinterlegt hat, kann man sich vom Client aus auf jedem Server ohne weiteres Passwort anmelden. Wenn man nun aber von einem zum anderen Server springen | + | Of course, |
- | **Ein Private Key darf den Client NIEMALS verlassen.**\\ | + | |
- | Natürlich hat openssh | + | |
client: ssh -A server.example.com | client: ssh -A server.example.com | ||
server.example.com: | server.example.com: | ||
- | Auch der auf " | + | The ssh command sent to " |
host * | host * | ||
ForwardAgent yes | ForwardAgent yes | ||
- | Und wieder etwas gelernt, man kann für die Definitionen in der .ssh/config Wildcards | + | And learned something again, you can use wildcards |
- | | + | ==== Step 5: Use non-public services locally |
- | ==== Schritt | + | What do you mean with that? A web server runs on server.example.com, |
- | Was ist damit gemeint? Auf server.example.com | + | |
ssh -L 1234: | ssh -L 1234: | ||
- | Was will uns der Dichter damit sagen? Die SSH Session wird überredet, auf dem Client den Port 1234 zu öffnen und jeglichen Traffic auf diesem Port an den Port 443 auf server.example.com (" | + | What is the poet trying to tell us? The SSH session is persuaded to open port 1234 on the client and forward all traffic on that port to port 443 on server.example.com (" |
https:// | https:// | ||
- | um den Webserver zu erreichen. \\ | + | to reach the web server. \\ |
- | Der Eintrag | + | The entry in the .ssh/ |
- | LocalForward | + | LocalForward 1234 localhost: |
- | Verwirrend? Das liegt an der Doppelnutzung von " | + | Confusing? This is due to the dual use of " |
- | Aber in der Serverlandschaft hinter | + | But in the server landscape behind |
ssh -D 3128 server.example.com | ssh -D 3128 server.example.com | ||
- | Wie immer was es das schon. Nur noch im Browse die Proxy Einstellungen einstellen und die alle Webserver, die server.example.com | + | As always, that's it. Just set the proxy settings in the browser and all web servers that can reach server.example.com |
- | Ach ja, wie sieht denn der Eintrag | + | Oh yes, what does the entry in .ssh/ |
- | DynamicForward | + | DynamicForward 3128 |
+ | ==== Conclusion: Example of a .ssh/config ==== | ||
- | + | | |
- | ==== Fazit: Beispiel einer .ssh/config ==== | + | |
- | + | # ssh-agent | |
- | | + | |
- | | + | |
- | # ssh-agent | + | |
ForwardAgent yes | ForwardAgent yes | ||
- | # Bei Ungereimtheiten mit Host Keys wollen wir gefragt werden | + | # If there are any inconsistencies with host keys, we want to be asked |
StrictHostKeyChecking ask | StrictHostKeyChecking ask | ||
- | # den Wert mancher Variablen wollen wir mitschleppen, | + | # We want to carry the value of some variables with us, here those |
- | # die sich auf die Sprachumgebung beziehen | + | # related to the locale |
SendEnv LANG LC_* | SendEnv LANG LC_* | ||
- | # Wo steht nochmal unser Private Key? | + | # Where is our private key again? |
- | IdentityFile | + | IdentityFile ~/ |
- | # Nun zu Server.example.com | + | # Now to Server.example.com |
- | # Da die für alle Hosts geltenden Einstellungen hier ebenfalls gültig sind, brauchen wir nur | + | # Since the settings that apply to all hosts are also valid here, we only need |
- | # anzugeben, was sich ändert oder was hinzukommt | + | # indicate what changes or what is added |
Host Server.example.com | Host Server.example.com | ||
- | # wie lautet unser Benutzename | + | # what is our username |
User user | User user | ||
- | # unser netter | + | # our nice Socks 5 proxy |
- | DynamicForward | + | DynamicForward 3128 |
- | # Der lokale Forward um den Webserver auf server.example.com | + | # The local forward to reach the web server on server.example.com |
- | # ist ja eigentlich unnötig, denn wir haben ja einen Dynamic Forward | + | # is actually unnecessary, because we have a dynamic forward |
- | LocalForward | + | LocalForward 1234 localhost: |
- | # Hier mal ein Beispiel für mehrere Server | + | # Here is an example for multiple servers |
Host *.example.com | Host *.example.com | ||
User user | User user | ||
- | Die Grundlagen sind gelegt und die meisten Fragen beantwortet. Weitergehende | + | The basics have been laid and most questions have been answered. Further |
- | + |