snipt

Ctrl+h for KB shortcuts

Bash

Change SSH port on OS X

1
2
3
4
5
# Add a service on an unused port in:
sudo vim /etc/services

# Change the string "ssh" below "SockServiceName" to whatever name used in the above file
sudo vim /System/Library/LaunchDaemons/ssh.plist
https://snipt.net/embed/7d7273436601ba72fdfd858fa8e2c103/
/raw/7d7273436601ba72fdfd858fa8e2c103/
7d7273436601ba72fdfd858fa8e2c103
bash
Bash
5
2019-07-30T12:49:39
True
False
False
/api/public/snipt/7733/
change-ssh-port-on-os-x
<table class="highlighttable"><tr><td class="linenos"><div class="linenodiv"><pre><a href="#L-1">1</a> <a href="#L-2">2</a> <a href="#L-3">3</a> <a href="#L-4">4</a> <a href="#L-5">5</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"># Add a service on an unused port in:</span> </span><span id="L-2"><a name="L-2"></a>sudo vim /etc/services </span><span id="L-3"><a name="L-3"></a> </span><span id="L-4"><a name="L-4"></a><span class="c1"># Change the string &quot;ssh&quot; below &quot;SockServiceName&quot; to whatever name used in the above file</span> </span><span id="L-5"><a name="L-5"></a>sudo vim /System/Library/LaunchDaemons/ssh.plist </span></pre></div> </td></tr></table>
osx, security, ssh

Bash

ssh local mount

sshfs [email protected]:/remote/dir /local/dir
https://snipt.net/embed/c8e2e84ad459d7e0d0263720617f8912/
/raw/c8e2e84ad459d7e0d0263720617f8912/
c8e2e84ad459d7e0d0263720617f8912
bash
Bash
1
2019-08-13T03:14:59
True
False
False
/api/public/snipt/7529/
ssh-local-mount
<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>sshfs [email protected]:/remote/dir /local/dir </span></pre></div> </td></tr></table>
ssh, sysadmin

Text only

Locally backup remote files via ssh

ssh [email protected] "cd /; tar -cvf - / | gzip -c" > backup.tar.gz
https://snipt.net/embed/297989ab56fd9e9a35943e45b09b5172/
/raw/297989ab56fd9e9a35943e45b09b5172/
297989ab56fd9e9a35943e45b09b5172
text
Text only
1
2019-08-15T17:35:03
True
False
False
/api/public/snipt/7473/
locally-backup-remote-files-via-ssh
<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 [email protected] &quot;cd /; tar -cvf - / | gzip -c&quot; &gt; backup.tar.gz </span></pre></div> </td></tr></table>
backup, gzip, ssh, tar, tarball

Text only

Mount remote directory locally via sshfs

sshfs [email protected]:/remote/dir /local/dir
https://snipt.net/embed/dd8c96088840a8971724ddf5f8a0e7e4/
/raw/dd8c96088840a8971724ddf5f8a0e7e4/
dd8c96088840a8971724ddf5f8a0e7e4
text
Text only
1
2019-08-09T12:38:45
True
False
False
/api/public/snipt/7472/
mount-remote-directory-locally-via-sshfs
<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>sshfs [email protected]:/remote/dir /local/dir </span></pre></div> </td></tr></table>
ssh, sshfs

Bash

one line add key to authorized_keys

ssh [email protected] "cat >> ~/.ssh/authorized_keys" < ~/.ssh/id_rsa.pub
https://snipt.net/embed/3dc117fa8d367eeff4157d39b41132cb/
/raw/3dc117fa8d367eeff4157d39b41132cb/
3dc117fa8d367eeff4157d39b41132cb
bash
Bash
1
2019-06-25T12:08:38
True
False
True
Jun 06, 2012 at 03:17 AM
/api/public/snipt/7418/
one-line-add-key-to-authorized_keys
<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 [email protected] <span class="s2">&quot;cat &gt;&gt; ~/.ssh/authorized_keys&quot;</span> &lt; ~/.ssh/id_rsa.pub </span></pre></div> </td></tr></table>
key, 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-13T17:42:46
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

SSH Streaming tar

ssh $SERVER tar -czf - $FILEDIR > $LOCALFILE.tgz
https://snipt.net/embed/7586d5131571a483fd351a6ad3d17f4a/
/raw/7586d5131571a483fd351a6ad3d17f4a/
7586d5131571a483fd351a6ad3d17f4a
bash
Bash
1
2019-08-17T09:02:19
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

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-17T18:32:17
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

Set startup messages in a ssh session

$> su
$> echo "Welcome my server" >> /etc/motd
https://snipt.net/embed/fde5943cc35c419086cfad3505876fb7/
/raw/fde5943cc35c419086cfad3505876fb7/
fde5943cc35c419086cfad3505876fb7
bash
Bash
2
2019-08-14T09:46:38
True
False
False
/api/public/snipt/6362/
set-startup-messages-in-a-ssh-session
<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>$&gt; su </span><span id="L-2"><a name="L-2"></a>$&gt; <span class="nb">echo</span> <span class="s2">&quot;Welcome my server&quot;</span> &gt;&gt; /etc/motd </span></pre></div> </td></tr></table>
linux, ssh

CSS

Kills and recreates SSH keys

cd ../; rm -rf .ssh; mkdir .ssh; cd .ssh; ssh-keygen -t rsa; cat id_rsa.pub
https://snipt.net/embed/41af33a77d889929cd4cccc6c230891e/
/raw/41af33a77d889929cd4cccc6c230891e/
41af33a77d889929cd4cccc6c230891e
css
CSS
1
2019-08-17T03:04:57
True
False
False
/api/public/snipt/6304/
kills-and-recreates-ssh-keys
<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><span class="nt">cd</span> <span class="o">../;</span> <span class="nt">rm</span> <span class="nt">-rf</span> <span class="nc">.ssh</span><span class="o">;</span> <span class="nt">mkdir</span> <span class="nc">.ssh</span><span class="o">;</span> <span class="nt">cd</span> <span class="nc">.ssh</span><span class="o">;</span> <span class="nt">ssh-keygen</span> <span class="nt">-t</span> <span class="nt">rsa</span><span class="o">;</span> <span class="nt">cat</span> <span class="nt">id_rsa</span><span class="nc">.pub</span> </span></pre></div> </td></tr></table>
bash, ssh