snipt

Ctrl+h for KB shortcuts

Ruby

ssh port forwarding

#This forwards all localhost:1234 connections to google.com:80 through gimli
ssh -L 1234:google.com:80 gimli.cs.berkeley.edu
https://snipt.net/embed/554defb67545e7a2885fa8560c668925/
/raw/554defb67545e7a2885fa8560c668925/
554defb67545e7a2885fa8560c668925
rb
Ruby
2
2019-08-22T11:37:28
True
False
False
/api/public/snipt/8832/
ssh-port-forwarding
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a><span class="c1">#This forwards all localhost:1234 connections to google.com:80 through gimli</span> </span><span id="L-2"><a name="L-2"></a><span class="n">ssh</span> <span class="o">-</span><span class="n">L</span> <span class="mi">1234</span><span class="ss">:google</span><span class="o">.</span><span class="n">com</span><span class="p">:</span><span class="mi">80</span> <span class="n">gimli</span><span class="o">.</span><span class="n">cs</span><span class="o">.</span><span class="n">berkeley</span><span class="o">.</span><span class="n">edu</span> </span></pre></div> </td></tr></table>
forwarding, mysql, server, shell, ssh

Bash

Generate SSH keypairs

ssh-keygen -t rsa
cat ~/.ssh/id_rsa.pub >> ~/.ssh/authorized_keys
https://snipt.net/embed/23674ab97c9298374947d9484e10ccee/
/raw/23674ab97c9298374947d9484e10ccee/
23674ab97c9298374947d9484e10ccee
bash
Bash
3
2019-08-25T09:23:33
True
False
False
/api/public/snipt/6975/
generate-ssh-keypairs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ssh-keygen -t rsa </span><span id="L-2"><a name="L-2"></a>cat ~/.ssh/id_rsa.pub &gt;&gt; ~/.ssh/authorized_keys </span></pre></div> </td></tr></table>
login, security, shell, ssh

Bash

Restore and Import MySQL dump

mysql -u username -ppassword database_name < dump.sql
https://snipt.net/embed/db660354aadf4edae6b81839c8a29ff4/
/raw/db660354aadf4edae6b81839c8a29ff4/
db660354aadf4edae6b81839c8a29ff4
bash
Bash
1
2019-08-25T09:10:47
True
False
False
/api/public/snipt/6904/
restore-and-import-mysql-dump
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysql -u username -ppassword database_name &lt; dump.sql </span></pre></div> </td></tr></table>
archive, backup, mysql, shell

Bash

Backup ALL MySQL DBs

mysqldump -u username -ppassword –all-databases > dump.sql
https://snipt.net/embed/a427e3c7f3e7597add52df495bb61454/
/raw/a427e3c7f3e7597add52df495bb61454/
a427e3c7f3e7597add52df495bb61454
bash
Bash
1
2019-08-19T12:12:49
True
False
False
/api/public/snipt/6903/
backup-all-mysql-dbs
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysqldump -u username -ppassword –all-databases &gt; dump.sql </span></pre></div> </td></tr></table>
archive, backup, mysql, shell

Bash

SSH Streaming tar

ssh $SERVER tar -czf - $FILEDIR > $LOCALFILE.tgz
https://snipt.net/embed/7586d5131571a483fd351a6ad3d17f4a/
/raw/7586d5131571a483fd351a6ad3d17f4a/
7586d5131571a483fd351a6ad3d17f4a
bash
Bash
1
2019-08-19T12:13:05
True
False
False
/api/public/snipt/6901/
ssh-streaming-tar
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>ssh <span class="nv">$SERVER</span> tar -czf - <span class="nv">$FILEDIR</span> &gt; <span class="nv">$LOCALFILE</span>.tgz </span></pre></div> </td></tr></table>
archive, shell, ssh, tar

Bash

Backup and compress a MySQL DB

mysqldump $DB_NAME -R -q --user=$USER --password=$PASSWORD --lock-tables | gzip > $BACKUPDIR/$BACKUPNAME
https://snipt.net/embed/ded50795e42c5309713131ffdceee243/
/raw/ded50795e42c5309713131ffdceee243/
ded50795e42c5309713131ffdceee243
bash
Bash
2
2019-08-19T12:13:22
True
False
False
/api/public/snipt/6900/
backup-and-compress-a-mysql-db
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>mysqldump <span class="nv">$DB_NAME</span> -R -q --user<span class="o">=</span><span class="nv">$USER</span> --password<span class="o">=</span><span class="nv">$PASSWORD</span> --lock-tables <span class="p">|</span> gzip &gt; <span class="nv">$BACKUPDIR</span>/<span class="nv">$BACKUPNAME</span> </span></pre></div> </td></tr></table>
archive, backup, mysql, shell

Bash

Tar to a pipe, doesnt use diskspace

tar -cf - ./filename | (cd other-directory; tar -xf -)
https://snipt.net/embed/f400281d56a70cd05b1e5f06a2b9b346/
/raw/f400281d56a70cd05b1e5f06a2b9b346/
f400281d56a70cd05b1e5f06a2b9b346
bash
Bash
1
2019-08-22T02:49:30
True
False
False
/api/public/snipt/6899/
tar-to-a-pipe-doesnt-use-diskspace
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar -cf - ./filename <span class="p">|</span> <span class="o">(</span><span class="nb">cd</span> other-directory<span class="p">;</span> tar -xf -<span class="o">)</span> </span></pre></div> </td></tr></table>
compress, shell, ssh, tar

Bash

Gzip-Tar a directory

tar -czvf archive.tgz files/
https://snipt.net/embed/3e7a2c87aa7882170e35a77e8206452e/
/raw/3e7a2c87aa7882170e35a77e8206452e/
3e7a2c87aa7882170e35a77e8206452e
bash
Bash
1
2019-08-20T06:10:00
True
False
False
/api/public/snipt/6898/
gzip-tar-a-directory
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>tar -czvf archive.tgz files/ </span></pre></div> </td></tr></table>
compress, shell, tar