<?xml version="1.0" encoding="utf-8" standalone="yes"?><rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom"><channel><title>Ssh on besserentwickeln.de</title><link>https://besserentwickeln.de/tags/ssh/</link><description>Recent content in Ssh on besserentwickeln.de</description><generator>Hugo -- gohugo.io</generator><language>de</language><copyright>Philipp Tuchardt</copyright><lastBuildDate>Tue, 11 Mar 2025 00:00:00 +0000</lastBuildDate><atom:link href="https://besserentwickeln.de/tags/ssh/index.xml" rel="self" type="application/rss+xml"/><item><title>Deployment einer statischen Seite</title><link>https://besserentwickeln.de/p/deployment-einer-statischen-seite/</link><pubDate>Tue, 11 Mar 2025 00:00:00 +0000</pubDate><guid>https://besserentwickeln.de/p/deployment-einer-statischen-seite/</guid><description>&lt;p>In diesem Blogpost schauen wir uns an, wie wir eine einfache statische Seite
via &lt;a class="link" href="https://gitlab.com" target="_blank" rel="noopener"
>gitlab.com&lt;/a> deployt.&lt;/p>
&lt;hr>
&lt;h2 id="vorraussetzungen">Vorraussetzungen
&lt;/h2>&lt;ul>
&lt;li>Account bei &lt;a class="link" href="https://gitlab.com" target="_blank" rel="noopener"
>gitlab.com&lt;/a>&lt;/li>
&lt;li>Ein Repository in welchem man Administrator ist&lt;/li>
&lt;li>Git-Bash oder ein anderes Linux-Terminal, wenn auf Windows&lt;/li>
&lt;/ul>
&lt;h2 id="ssh-keys">SSH-Keys
&lt;/h2>&lt;h3 id="erstellen-eines-ssh-keys">Erstellen eines SSH-Keys
&lt;/h3>&lt;p>Um später den Gitlab-Runner zu berrechtigen, dass dieser per SSH auf den Ziel-Server zugreifen darf,
erstellen wir ein neues Key-Pair, welches ausschließlich dafür verwendet wird.&lt;/p>
&lt;p>Dieses Keypair erstellen ich nach dem vom &lt;a class="link" href="https://martin.leyrer.priv.at/" target="_blank" rel="noopener"
>Martin Leyrer&lt;/a>
empfohlenen Aufbau aus seinem Talk &lt;a class="link" href="https://www.youtube.com/watch?v=qvdlLTyUJ5I" target="_blank" rel="noopener"
>&amp;ldquo;Besser Leben mit SSH&amp;rdquo;&lt;/a>.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">ssh-keygen -t ed25519 -a &lt;span class="m">420&lt;/span> -f ~/your/own/path/id_ed25519 -C &lt;span class="s2">&amp;#34;foo@ba.de&amp;#34;&lt;/span>
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Bitte nicht vergessen den Pfad &lt;code>~/your/own/path/...&lt;/code> zu ersetzen, da ihr ansonsten, unter Umständenen
euren bereits vorhanden SSH-Key durch den Deployment-Key ersetzt. Die Dummy-Mail &lt;code>foo@ba.de&lt;/code> sollte
ebenso durch eine passende von euch getauscht werden. Beispielsweise: &lt;code>deployment@euredomain.com&lt;/code> oder &lt;code>noreply@euredomain.com&lt;/code>.&lt;/p>
&lt;h3 id="hinterlegen-des-ssh-keys">Hinterlegen des SSH-Keys
&lt;/h3>&lt;p>Nachdem das Keypair erzeugt wurde, kann der Public-Key auf eurem Zielserver hinterlegt werden.
Je nach Hoster kann dies über GUI oder per SSH/FTP geschehen.&lt;/p>
&lt;p>Um euch den Public-Key auszugeben, könnt ihr im Terminal den &lt;code>cat&lt;/code>-Befehl nutzen.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">cat ~/path/to/your/key/id_ed25519.pub
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;p>Anschließend diesen bei eurem Hoster hinterlegen. Sollte das per SSH oder FTP geschehen, dann müsst ihr euren Public-Key
in die &lt;code>authorized_keys&lt;/code> kopieren, die findet ihr meist unter &lt;code>~/.ssh/&lt;/code>.&lt;/p>
&lt;h2 id="repository-auf-dem-server-auschecken">Repository auf dem Server auschecken
&lt;/h2>&lt;p>Mittels eines Deploy-Tokens werden wir unseren Ziel-Server berechtigen auf das Gitlab-Repository zuzugreifen.&lt;/p>
&lt;h3 id="deploy-token-erstellen">Deploy Token erstellen
&lt;/h3>&lt;p>Um ein Token zu erstellen navigieren wir in Gitlab wie zu &lt;em>Settings &amp;gt; Repository &amp;gt; Deploy Token&lt;/em>.
Dort klicken wir auf &lt;em>Add token&lt;/em> und erhalten die Ansicht aus dem Screenshot.&lt;/p>
&lt;p>In dieser Ansicht vergeben wir einen Namen und Usernamen für das Token, sowie alle Leserechte. Schreibrechte werden in
Regel nicht benötigt.&lt;/p>
&lt;p>&lt;img src="https://besserentwickeln.de/p/deployment-einer-statischen-seite/deploy-token.png"
width="1153"
height="817"
srcset="https://besserentwickeln.de/p/deployment-einer-statischen-seite/deploy-token_hu_c8ca2d5c97547d16.png 480w, https://besserentwickeln.de/p/deployment-einer-statischen-seite/deploy-token_hu_c1e1425848cc44de.png 1024w"
loading="lazy"
alt="image"
class="gallery-image"
data-flex-grow="141"
data-flex-basis="338px"
>&lt;/p>
&lt;p>Nach Klick auf &lt;em>Create Deploy Token&lt;/em> bekommen wir unseren gewählten Usernamen sowie ein zufälliges Passwort ausgegeben.&lt;/p>
&lt;h3 id="git-clone-ausführen">Git clone ausführen
&lt;/h3>&lt;p>Nun nachdem wir das Deploy-Token haben, können wir unser Repository auf dem Server auschecken. Dazu verbinden wir uns
per SSH mit dem Server und klonen am gewünschten Ort unser Repository.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt">1
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-bash" data-lang="bash">&lt;span class="line">&lt;span class="cl">git clone https://tokenName:tokenPassword@gitlab.com/repo.git
&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div>&lt;h3 id="gitlab-ciyml-anlegen">gitlab-ci.yml anlegen
&lt;/h3>&lt;p>Nun legen wir die &lt;code>gitlab-ci.yml&lt;/code> an und hinterlegen die notigen Variablen in Gitlab.&lt;/p>
&lt;p>Nachfolgend habe ich ein Template vorbereitet, welches die Variablen &lt;code>SSH_PRIVATE_KEY&lt;/code> und &lt;code>SSH_CONNECTION&lt;/code> erwartet.
Diese Variablen müssen in Gitlab in eurem Repository unter Settings &amp;gt; CI/CD &amp;gt; Variables hinterlegt werden.&lt;/p>
&lt;p>&lt;img src="https://besserentwickeln.de/p/deployment-einer-statischen-seite/gitlab-ci-cd.png"
width="1301"
height="507"
srcset="https://besserentwickeln.de/p/deployment-einer-statischen-seite/gitlab-ci-cd_hu_81e01dc743b81d21.png 480w, https://besserentwickeln.de/p/deployment-einer-statischen-seite/gitlab-ci-cd_hu_df68a4100cb95cb2.png 1024w"
loading="lazy"
alt="image"
class="gallery-image"
data-flex-grow="256"
data-flex-basis="615px"
>&lt;/p>
&lt;p>Wenn diese Variablen hinterlegt sind, könnt ihr anschließende &lt;code>gitlab-ci.yml&lt;/code> zu eurem Projekt hinzufügen.
Diese ist so vorkonfiguriet, dass sie beim Merge nach &lt;code>dev&lt;/code> auf euer DEV-System deployt und mittels &lt;code>release-...&lt;/code> Tag auf &lt;code>live&lt;/code>
deployt.&lt;/p>
&lt;div class="highlight">&lt;div class="chroma">
&lt;table class="lntable">&lt;tr>&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code>&lt;span class="lnt"> 1
&lt;/span>&lt;span class="lnt"> 2
&lt;/span>&lt;span class="lnt"> 3
&lt;/span>&lt;span class="lnt"> 4
&lt;/span>&lt;span class="lnt"> 5
&lt;/span>&lt;span class="lnt"> 6
&lt;/span>&lt;span class="lnt"> 7
&lt;/span>&lt;span class="lnt"> 8
&lt;/span>&lt;span class="lnt"> 9
&lt;/span>&lt;span class="lnt">10
&lt;/span>&lt;span class="lnt">11
&lt;/span>&lt;span class="lnt">12
&lt;/span>&lt;span class="lnt">13
&lt;/span>&lt;span class="lnt">14
&lt;/span>&lt;span class="lnt">15
&lt;/span>&lt;span class="lnt">16
&lt;/span>&lt;span class="lnt">17
&lt;/span>&lt;span class="lnt">18
&lt;/span>&lt;span class="lnt">19
&lt;/span>&lt;span class="lnt">20
&lt;/span>&lt;span class="lnt">21
&lt;/span>&lt;span class="lnt">22
&lt;/span>&lt;span class="lnt">23
&lt;/span>&lt;span class="lnt">24
&lt;/span>&lt;span class="lnt">25
&lt;/span>&lt;span class="lnt">26
&lt;/span>&lt;span class="lnt">27
&lt;/span>&lt;span class="lnt">28
&lt;/span>&lt;/code>&lt;/pre>&lt;/td>
&lt;td class="lntd">
&lt;pre tabindex="0" class="chroma">&lt;code class="language-yaml" data-lang="yaml">&lt;span class="line">&lt;span class="cl">&lt;span class="nt">stages&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">Deploy&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">deploy-dev&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">stage&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Deploy&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">rules&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">if&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;$CI_COMMIT_REF_NAME == &amp;#34;dev&amp;#34;&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;edbizarro/gitlab-ci-pipeline-php:8.3&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">before_script&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">eval $(ssh-agent -s)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">echo &amp;#34;$SSH_PRIVATE_KEY&amp;#34; | tr -d &amp;#39;\r&amp;#39; | ssh-add -&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">mkdir -p ~/.ssh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">chmod 700 ~/.ssh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">script&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">ssh -o StrictHostKeyChecking=no &amp;#34;$SSH_CONNECTION&amp;#34; &amp;#34;cd /root-project-dir-dev/ &amp;amp;&amp;amp; git fetch &amp;amp;&amp;amp; git checkout dev &amp;amp;&amp;amp; git pull&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w">&lt;/span>&lt;span class="nt">deploy-live&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">stage&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="l">Deploy&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">rules&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="nt">if&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s1">&amp;#39;$CI_COMMIT_TAG =~ /release-.*/&amp;#39;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">image&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w"> &lt;/span>&lt;span class="s2">&amp;#34;edbizarro/gitlab-ci-pipeline-php:8.3&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">before_script&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">eval $(ssh-agent -s)&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">echo &amp;#34;$SSH_PRIVATE_KEY&amp;#34; | tr -d &amp;#39;\r&amp;#39; | ssh-add -&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">mkdir -p ~/.ssh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">chmod 700 ~/.ssh&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>&lt;span class="nt">script&lt;/span>&lt;span class="p">:&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;span class="line">&lt;span class="cl">&lt;span class="w"> &lt;/span>- &lt;span class="l">ssh -o StrictHostKeyChecking=no &amp;#34;$SSH_CONNECTION&amp;#34; &amp;#34;cd /root-project-dir-live/ &amp;amp;&amp;amp; git fetch &amp;amp;&amp;amp; git checkout $CI_COMMIT_TAG&amp;#34;&lt;/span>&lt;span class="w">
&lt;/span>&lt;/span>&lt;/span>&lt;/code>&lt;/pre>&lt;/td>&lt;/tr>&lt;/table>
&lt;/div>
&lt;/div></description></item><item><title>SSH Key</title><link>https://besserentwickeln.de/n/ssh-key/</link><pubDate>Wed, 08 Jun 2022 00:00:00 +0000</pubDate><guid>https://besserentwickeln.de/n/ssh-key/</guid><description>&lt;p>Dank des &lt;a class="link" href="https://www.youtube.com/watch?v=qvdlLTyUJ5I" target="_blank" rel="noopener"
>Talks&lt;/a> von &lt;a class="link" href="https://martin.leyrer.priv.at/" target="_blank" rel="noopener"
>Martin Leyrer&lt;/a> werden meine SSH-Keys jetzt so generiert:&lt;/p>
&lt;p>&lt;code>ssh-keygen -t ed25519 -a 420 -f ~/.ssh/id_ed25519 -C &amp;quot;foo@ba.de&amp;quot;&lt;/code>&lt;/p></description></item></channel></rss>