Benutzer-Werkzeuge

Webseiten-Werkzeuge


en:howtos:ssh

Unterschiede

Hier werden die Unterschiede zwischen zwei Versionen angezeigt.

Link zu dieser Vergleichsansicht

Beide Seiten der vorigen RevisionVorhergehende Überarbeitung
Nächste Überarbeitung
Vorhergehende Überarbeitung
en:howtos:ssh [2022/02/18 08:31] – [Schritt 2: geht das auch ohne Passwort] morquaien:howtos:ssh [2022/02/18 08:40] (aktuell) – [Fazit: Beispiel einer .ssh/config] morquai
Zeile 74: Zeile 74:
       IdentityFile ~/.ssh/rsakey       IdentityFile ~/.ssh/rsakey
 We have deactivated the server's password query and now have to enter the passphrase of the SSH key. Unfortunately, we have only replaced one password query with another. We have deactivated the server's password query and now have to enter the passphrase of the SSH key. Unfortunately, we have only replaced one password query with another.
-==== Schritt 3: Eine Passwortabfrage pro Tag ==== +==== Step 3: One password request per day ==== 
-Die openssh Entwickler sind anscheinend ziemlich faule GesellenIm Paket openssh befindet sich auch ein Agent, der die Aufgabe hat sich die SSH Keys im RAM zu merken und bei Bedarf zur Verfügung zu stellenDie Ablage im RAM erfolgt natürlich nach allen Regeln der SicherheitUnter Linux (auch Cygwin) wird der Agent folgendermaßen benutzt+The openssh developers are apparently pretty lazy fellowsThe openssh package also contains an agent that has the task of remembering the SSH keys in RAM and making them available when neededOf course, the storage in RAM follows all the rules of securityUnder Linux (also Cygwin) the agent is used as follows
-  ssh-agent+  ssh agent
     SSH_AUTH_SOCK=/tmp/ssh-YYMhp1JPZkWu/agent.25166028; export SSH_AUTH_SOCK;     SSH_AUTH_SOCK=/tmp/ssh-YYMhp1JPZkWu/agent.25166028; export SSH_AUTH_SOCK;
     SSH_AGENT_PID=10682402; export SSH_AGENT_PID;     SSH_AGENT_PID=10682402; export SSH_AGENT_PID;
     echo Agent pid 10682402;     echo Agent pid 10682402;
-Damit ist der Agent gestartet und die Befehle, die eine Benutzung ermöglichen, werden ausgegebenDer Agent bleibt bis zum nächsten Reboot aktivalso können wir die Befehle in eine Datei schreiben und dann in der aktuellen Shell ausführenNennen wir die Datei ~/ssh-agent-vars.sh und füllen sie mit InhaltAnschliessend führen wir sie in der aktuellen Shell aus.+The agent is now started and the commands that enable use are issuedThe agent stays active until the next rebootso we can write the commands to a file and then run them in the current shellLet's name the file ~/ssh-agent-vars.sh and fill it with contentThen we run it in the current shell.
   SSH_AUTH_SOCK=/tmp/ssh-YYMhp1JPZkWu/agent.25166028; export SSH_AUTH_SOCK;   SSH_AUTH_SOCK=/tmp/ssh-YYMhp1JPZkWu/agent.25166028; export SSH_AUTH_SOCK;
   SSH_AGENT_PID=10682402; export SSH_AGENT_PID;   SSH_AGENT_PID=10682402; export SSH_AGENT_PID;
   echo Agent pid 10682402;   echo Agent pid 10682402;
-Und nun die Ausführungder Punkt am Anfang signalisiert, das das Script in der aktuellen Shell ausgeführt wird:+And now the executionthe dot at the beginning signals that the script is executed in the current shell:
   . ~/ssh-agent-vars.sh   . ~/ssh-agent-vars.sh
-Nachdem der Agent gestartet wurde und die Benutzung eingerichtet istmüssen wir nun dem Agenten den Private Key zur Verfügung stellen+After the agent has been started and the use has been set upwe now have to provide the agent with the private key
   ssh-add ~/.ssh/rsakey   ssh-add ~/.ssh/rsakey
-Der Agent fordert uns auf die Passphrase einzugeben und kann nun die Aufgabe, den Private Key bei Bedarf zur Verfügung zu stellen, übernehmenDie 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 requiredThe registration can now be made without any password query.
   ssh server.example.com   ssh server.example.com
-Geschafftdie Passworteingabe ist ab nun nicht mehr erforderlichWir müssen nur nach einen Reboot daran denken den Agenten erneut zu starten und die ausgegebenen Befehle in die Datei ~/ssh-agent-vars.sh zu schreibenAuch der Private Key muss einmalig wieder geladen werden. \\ +Made itfrom now on it is no longer necessary to enter a passwordWe only have to remember to start the agent again after a reboot and write the issued commands to the ~/ssh-agent-vars.sh fileThe private key must also be reloaded once. \\ 
-Wenn wir eine neue Shell starten muss natürlich auch hier die ~/ssh-agent-vars.sh in der aktuellen Shell ausgeführt werdenMan kann dies in der ~/.bashrc hinterlegen.+Of course, if we start a new shell, ~/ssh-agent-vars.sh must also be executed in the current shellYou can store this in ~/.bashrc.
  
-**Hinweiswer PuTTY und openssh unter Cygwin parallel benutzt sollte sich die Benutzung von PAGEANT (PuTTY) und die Zusammenarbeit mit ssh-pageant (openssh unter Cygwin) anschauen. [[https://mplx.eu/tech/ssh-key-agents-linux-windows-cygwin|Hier ein Link zum Einstieg]] **+**Noteif you use PuTTY and openssh under Cygwin in parallel, you should look at using PAGEANT (PuTTY) and working with ssh-pageant (openssh under Cygwin). [[https://mplx.eu/tech/ssh-key-agents-linux-windows-cygwin|Here is a link to get started]] ** 
 +==== 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 landscape on which you can registerOnce you have deposited the public part of the SSH key on all serversyou can log on to any server from the client without an additional passwordBut if you now want to jump from one server to the otheryou will be asked for the password againbecause the agent only runs on our clientIt is now an unforgivable sin to copy the private key to the servers in the example.com domain. \\ 
- +**A private key must NEVER leave the client.**\\ 
-Oft findet man eine ganze Serverlandschaftauf der man sich anmelden kannWenn man erst einmal den öffentlichen Teil des SSH Keys auf allen Servern hinterlegt hatkann man sich vom Client aus auf jedem Server ohne weiteres Passwort anmelden. Wenn man nun aber von einem zum anderen Server springen will, wird man wieder nach dem Passwort gefragt, denn der Agent läuft ja nur auf unserem ClientEine unverzeihliche Sünde ist es nun den Private Key auf die Server in der Domain example.com zu kopieren. \\ +Of course, openssh has a solution herebecause the ssh-agent can do even moreThe private key can be used in a whole chain of consecutive SSH sessionsThe "-A" switch ensures that the private key is passed on through all ssh instances:
-**Ein Private Key darf den Client NIEMALS verlassen.**\\ +
-Natürlich hat openssh hier eine Lösung paratdenn der ssh-agent kann noch mehrDer Private Key kann in einer ganze Kette aufeinander folgende SSH Sessions benutzt werdenDer Schalter "-A" sorgt dafür, das der Private Key durch alle ssh Instanzen weiter gereicht wird:+
   client: ssh -A server.example.com   client: ssh -A server.example.com
   server.example.com: ssh server2.example.com   server.example.com: ssh server2.example.com
-Auch der auf "server.example.com" abgesetzte ssh Befehl erforder kein Passwortder ssh-agent befriedigt die Anfrage des Private Keys problemlossofern mittels "ssh-copy-id" der öffentliche Schlüssel auf server2.example.com bereitgestellt wurdeDie Entsprechung in der .ssh/config lautet+The ssh command sent to "server.example.com" also does not require a passwordthe ssh-agent satisfies the request for the private key without any problemsprovided the public key was provided on server2.example.com using "ssh-copy-id"The equivalent in the .ssh/config is
   host *   host *
     ForwardAgent yes     ForwardAgent yes
-Und wieder etwas gelerntman kann für die Definitionen in der .ssh/config Wildcards ("*" und "?"verwendenAber AchtungEs werden alle Definitionen in allen Gruppen angewendet, auf die die Wildcards zutreffen. +And learned something againyou can use wildcards ("*" and "?"for the definitions in the .ssh/config. But be carefulAll definitions in all groups to which the wildcards apply are used
-   +==== Step 5: Use non-public services locally ==== 
-==== Schritt 5: nicht öffentliche Services lokal nutzen ==== +What do you mean with thatA web server runs on server.example.com, which cannot be reached from the Internet, but which we want to address on our clientA web server is addressed on port 80 (unencryptedor 443 (encrypted). However, this port is blocked by a firewallThe solution isport forwardingwhich is not a problem with openssh.
-Was ist damit gemeintAuf server.example.com läuft ein WebServerder aus dem Internet nicht erreichbar istden wir aber auf unserem Client ansprechen wollenEin WebServer wird auf Port 80 (unverschlüsseltoder 443 (verschlüsseltangesprochenDieser Port wird aber von einer Firewall geblocktDie Lösung lautetPort Forwardingwas mit openssh kein Problem ist+
   ssh -L 1234:localhost:443 server.example.com   ssh -L 1234:localhost:443 server.example.com
-Was will uns der Dichter damit sagenDie 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 ("localhost", aus dessen SichtweiterzuleitenIm Browser reicht nun die Eingabe von +What is the poet trying to tell usThe 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 ("localhost", from his point of view). Entering in the browser is now sufficient
   https://localhost:1234   https://localhost:1234
-um den Webserver zu erreichen. \\+to reach the web server. \\
  
-Der Eintrag in der .ssh/config lautet +The entry in the .ssh/config is 
-  LocalForward    1234 localhost:443+  LocalForward 1234 localhost:443
  
-VerwirrendDas liegt an der Doppelnutzung von "localhost"Dieser Rechnername "localhost" bezieht sich immer auf den Rechner, auf dem er interpretiert wird. In dem SSH Command wird "localhost" aus Sicht von "server.example.com" interpretiertim Browserder ja auf dem Client läuftwird es natürlich als "Clientinterpretiert. \\ +ConfusingThis is due to the dual use of "localhost"This computer name "localhost" always refers to the computer on which it is interpreted. In the SSH command, "localhost" is interpreted from the point of view of "server.example.com", in the browserwhich runs on the clientit is of course interpreted as "client". \\ 
-Aber in der Serverlandschaft hinter server.example.com laufen mehrere WebServerfür jeden einzelnen ein Port Forwarding einzurichten ist wohl ein wenig aufwendigAber natürlich hat openssh alles zur HandWir richten uns einfach einen Socks Proxy einden wir im Browser eintragen und schon stehen alle WebServer mit einem einzigen Eintrag im SSH Command zur Verfügung.+But in the server landscape behind server.example.com there are several web servers runningand setting up port forwarding for each one is probably a bit time-consumingBut of course openssh has everything at handWe simply set up a socks proxywhich we enter in the browser and all web servers are available with a single entry in the SSH command.
   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 Webserverdie server.example.com erreichen kann, stehen zur VerfügungUnschön ist das Verhalten, wenn man Namen statt IP-Adressen benutztNormalerweise sprechen wir Webseiten nach dem Schema <hostname>.<domain> (z.B. www.google.de) anDer DNS nimmt uns die Arbeit ab, die Namen in IP Adressen zu übersetzenDa das DNS Protokoll auf UDP basiert, ssh aber nur TCP zur Verfügung stelltmüssen die Namen entweder im öffentlichen DNS auflösbar sein oder in der lokalen Hosts Datei gepflegt sein. \\ +As alwaysthat's it. Just set the proxy settings in the browser and all web servers that can reach server.example.com are availableThe behavior is unpleasant if you use names instead of IP addressesNormally we address websites according to the scheme <hostname>.<domain> (e.g. www.google.de). The DNS does the work for us to translate names into IP addressesSince the DNS protocol is based on UDP, but ssh only provides TCP, the names must either be resolvable in public DNS or maintained in the local hosts file. \\ 
-Ach jawie sieht denn der Eintrag in der .ssh/config aus+Oh yeswhat does the entry in .ssh/config look like
-  DynamicForward  3128+  DynamicForward 3128 
 +==== Conclusion: Example of a .ssh/config ====
  
- +  First of all the settings that should apply to all computers 
-==== Fazit: Beispiel einer .ssh/config ==== +  hosting 
- +    # ssh-agent should provide the private keys
-  Ersteinmal die Einstellungen, die für alle Rechner gelten sollen +
-  Host +
-    # ssh-agent soll die private Keys zur Verfügung stellen+
     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, hier diejenigen+    # We want to carry the value of some variables with ushere 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    ~/.ssh/rsakey +    IdentityFile ~/.ssh/rsakey 
-  # Nun zu Server.example.com +  # Now to Server.example.com 
-  # Da die für alle Hosts geltenden Einstellungen hier ebenfalls gültig sindbrauchen wir nur  +  # Since the settings that apply to all hosts are also valid herewe 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 Socks 5 Proxy +    # our nice Socks 5 proxy 
-    DynamicForward  3128 +    DynamicForward 3128 
-    # Der lokale Forward um den Webserver auf server.example.com zu erreichen +    # The local forward to reach the web server on server.example.com 
-    # ist ja eigentlich unnötigdenn wir haben ja einen Dynamic Forward +    # is actually unnecessarybecause we have a dynamic forward 
-    LocalForward    1234 localhost:443 +    LocalForward 1234 localhost:443 
-  # 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 beantwortetWeitergehende HowTo'zu SSH folgen.... +The basics have been laid and most questions have been answeredFurther HowTo'for SSH will follow....
-         +
en/howtos/ssh.1645173103.txt.gz · Zuletzt geändert: 2022/02/18 08:31 von morquai