|
|
|
@@ -42,7 +42,7 @@
|
|
|
|
|
<section data-transition="slide" data-background="#4d7e65" data-background-transition="zoom">
|
|
|
|
|
<h1>LINUX</h1>
|
|
|
|
|
<h3>Das universelle Betriebssystem</h3>
|
|
|
|
|
<p>Eine Einführung - Teil 10
|
|
|
|
|
<p>Eine Einführung - Teil 11
|
|
|
|
|
<p> <small>Deutsche Angestellten Akademie</small> </p>
|
|
|
|
|
<aside class="notes">
|
|
|
|
|
Frage: Fragen zur letzten Stunde?
|
|
|
|
@@ -112,18 +112,17 @@
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<h4>Verwendung mit ssh-Keys</h4>
|
|
|
|
|
<ol>
|
|
|
|
|
<li class="fragment ">Schlüsselpaar generieren:<br> <code>ssh-keygen -b 4096</code></li>
|
|
|
|
|
<li class="fragment ">öffentlichen Schlüssel zum Server kopieren:<br> <code>scp neuer-super-key.pub user@server.de</code></li>
|
|
|
|
|
<ol style="font-size: .8em">
|
|
|
|
|
<li class="fragment ">Schlüsselpaar generieren:<br> <pre><code>ssh-keygen -b 4096</code></pre></li>
|
|
|
|
|
<li class="fragment ">öffentlichen Schlüssel zum Server kopieren:<br> <pre><code>scp neuer-super-key.pub user@server.de</code></pre></li>
|
|
|
|
|
<li class="fragment ">Beim Server anmelden: <code>ssh user@server.de</code></li>
|
|
|
|
|
<li class="fragment "><pre><code class="bash">
|
|
|
|
|
$ mkdir ~/.ssh
|
|
|
|
|
<li class="fragment "><pre><code class="bash">$ mkdir ~/.ssh
|
|
|
|
|
$ cat ~/neuer-super-key.pub >> ~/.ssh/authorized_keys
|
|
|
|
|
$ rm ~/neuer-super-key.pub
|
|
|
|
|
$ chmod 600 ~/.ssh/authorized_keys</code></pre></li>
|
|
|
|
|
$ chmod 600 ~/.ssh/authorized_keys</code></pre><p class="fragment">Oder mit <code>ssh-copy-id</code></li>
|
|
|
|
|
<li class="fragment">nun ist Anmeldung mit Key möglich.
|
|
|
|
|
</ol>
|
|
|
|
|
|
|
|
|
|
<p>nun ist Anmeldung mit Key möglich.
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
@@ -154,25 +153,119 @@ $ chmod 600 ~/.ssh/authorized_keys</code></pre></li>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
|
|
|
|
|
</section>
|
|
|
|
|
<h4>ssh_config</h4>
|
|
|
|
|
<pre><code class="bash">Host gitlab.com
|
|
|
|
|
HostName gitlab.com
|
|
|
|
|
PreferredAuthentications=publickey
|
|
|
|
|
#PreferredAuthentications=password
|
|
|
|
|
IdentityFile ~/.ssh/gitlab-com
|
|
|
|
|
IdentitiesOnly yes
|
|
|
|
|
User git
|
|
|
|
|
|
|
|
|
|
Host *
|
|
|
|
|
user root
|
|
|
|
|
|
|
|
|
|
ServerAliveInterval 120
|
|
|
|
|
ServerAliveCountMax 15
|
|
|
|
|
</code></pre>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<h4>Nutzungsbeispiele</h4>
|
|
|
|
|
<pre class="fragment "><code class="bash">~$ ssh root@server 'cd /etc; \
|
|
|
|
|
tar czvf - network/' | cat > etc_network_backup.tar.gz </code></pre>
|
|
|
|
|
<pre class="fragment "><code>~$ scp -r root@server:/etc/apache2 . </code></pre>
|
|
|
|
|
<pre class="fragment "><code>~$ scp omikron-net.conf \
|
|
|
|
|
root@server:/etc/apache2/sites-available/ . </code></pre>
|
|
|
|
|
<pre class="fragment "><code class="bash">~$ rsync -e ssh lk.schubertdaniel.de:/home/dany/backups/* \
|
|
|
|
|
/local/backup/dir/ >> backup.log 2>&1
|
|
|
|
|
</code></pre>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<h3>rsync vs. scp</h3>
|
|
|
|
|
<ul>
|
|
|
|
|
<li class="fragment ">scp -> funktioniert wie cp; geeignet um schnell mal einzelne Dateien zu kopieren</li>
|
|
|
|
|
<li class="fragment ">rsync -> für „richtige“ Backups; vergleicht lokales u. remote Verz., kopiert nur Unterschiede</li>
|
|
|
|
|
</ul>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section style="font-size: .8em">
|
|
|
|
|
<span style="color: orange">Aufgabe:</span>
|
|
|
|
|
<div>
|
|
|
|
|
<ul>
|
|
|
|
|
<li>erstellt einen ssh-key ohne Passwort; verwendet diesen key für Folgendes.</li>
|
|
|
|
|
<li>Erstellt ein script, welches Serverseitig alle Ordner in /usr/share/nginx/html ausser denen die„mich-*” heissen, in ein tar.gz Archiv verpacken. ( zb per Array im script, oder mit einer text-datei als input</li>
|
|
|
|
|
<li>Erstellt ein script, welches diese Backups mit <strong>rsync</strong> herunterlädt.</li>
|
|
|
|
|
<li>Das Backup soll die Datei Attribute unverändert belassen<br> ( Datum, Rechte etc ).</li>
|
|
|
|
|
<li>Erstellt einen Cron-Job, der das wöchentlich macht.</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<p>Hinweise:
|
|
|
|
|
<ul>
|
|
|
|
|
<li>cron muss vollständige Pfade angegeben bekommen.<br>
|
|
|
|
|
<li><code>rsync</code> mit spezifischem key:
|
|
|
|
|
<pre><code class="bash">/usr/bin/rsync -e 'ssh -i /home/$USERNAME/.ssh/key-ohne-pw' </code></pre>
|
|
|
|
|
</ul>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
<section>
|
|
|
|
|
<h4>Lösungs Vorschlag</h4>
|
|
|
|
|
<p><a href="https://git.scytec.de/danthefan/linuxkurs/blob/master/beispiele/11/file-backup.sh">remote backup script</a>
|
|
|
|
|
<p><a href="https://git.scytec.de/danthefan/linuxkurs/blob/master/beispiele/11/rsync-backup.sh">local rsync script</a>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<h4>Beschränkung von ssh auf best. Komandos</h4>
|
|
|
|
|
<pre><code class="bash"># Datei ~/.ssh/authorized_keys
|
|
|
|
|
# führt bei Anmeldung ls aus; lässt keine anderen Kommandos zu
|
|
|
|
|
command="/bin/ls -la ~" ssh-rsa AAAAB3.......
|
|
|
|
|
# oder
|
|
|
|
|
command="/bin/echo You invoked: $SSH_ORIGINAL_COMMAND" ssh-rsa AAAAB..</code></pre>
|
|
|
|
|
<div class="fragment">
|
|
|
|
|
<p>Um rsync zu verwenden ist ein wrapper script nötig:
|
|
|
|
|
|
|
|
|
|
<pre><code class="bash"># Datei ~/.ssh/authorized_keys
|
|
|
|
|
command="/absoluter/pfad/rsync-check.sh" ssh-rsa AAAAB3.......</code></pre>
|
|
|
|
|
|
|
|
|
|
<pre><code class="bash">#!/bin/bash
|
|
|
|
|
#
|
|
|
|
|
# rsync-check.sh
|
|
|
|
|
|
|
|
|
|
set -- $SSH_ORIGINAL_COMMAND
|
|
|
|
|
cmd="$1"; shift
|
|
|
|
|
case "$cmd" in
|
|
|
|
|
scp|rsync) exec "$cmd" "$@" ;;
|
|
|
|
|
*) echo "ERROR: request not permitted" ;;
|
|
|
|
|
esac</code></pre>
|
|
|
|
|
</div>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
<section><h4>Windows Programme für ssh</h4>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li class="fragment ">winscp</li>
|
|
|
|
|
<li class="fragment ">putty</li>
|
|
|
|
|
<li class="fragment ">swish</li>
|
|
|
|
|
</ul></section>
|
|
|
|
|
|
|
|
|
|
<section>
|
|
|
|
|
<h4>Linux Helferlein</h4>
|
|
|
|
|
|
|
|
|
|
<ul>
|
|
|
|
|
<li> erstellt ein script, welches Serverseitig ein Datenbank und File Backup erstellt</li>
|
|
|
|
|
<li> erstellt ein script, welches Serverseitig ein Datenbank und File Backup erstellt</li>
|
|
|
|
|
|
|
|
|
|
<li>Erstellt ein script, welches diese Backups mit rsync herunterlädt</li>
|
|
|
|
|
<li>Erstellt einen Cron-Job der das wöchentlich macht</li>
|
|
|
|
|
<li>screen</li>
|
|
|
|
|
<li>byobu</li>
|
|
|
|
|
<li>tmux</li>
|
|
|
|
|
<li>terimator</li>
|
|
|
|
|
<li>tmate</li>
|
|
|
|
|
</ul>
|
|
|
|
|
|
|
|
|
|
<p>Hinweise:
|
|
|
|
|
|
|
|
|
|
<aside class="notes">
|
|
|
|
|
screen isntallieren
|
|
|
|
|
</aside>
|
|
|
|
|
</section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<section><h4>screen</h4></section>
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
</div>
|
|
|
|
|