Snipt.net is closing on December 31st, 2016

For more information, please visit this blog post.

snipt

Ctrl+h for KB shortcuts

Text only

Add simple user to sudoers in Debian

echo 'my_user ALL=(ALL:ALL) ALL' >> /etc/sudoers
https://snipt.net/embed/f83ecfd16dc620045692997d4420c372/
https://snipt.net/raw/f83ecfd16dc620045692997d4420c372/
f83ecfd16dc620045692997d4420c372
text
Text only
3
2016-12-07T15:06:53
True
False
False
/api/public/snipt/107957/
give-administrator-privileges-to-simple-user-in-debian
<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>echo &#39;my_user ALL=(ALL:ALL) ALL&#39; &gt;&gt; /etc/sudoers </span></pre></div> </td></tr></table>
Debian, Linux, administrator, root, sudo, sudoers

Text only

sudo inside of VIM

:w ! sudo tee %
https://snipt.net/embed/c2234aa3e2e568a360fe44c2d5ef1b49/
https://snipt.net/raw/c2234aa3e2e568a360fe44c2d5ef1b49/
c2234aa3e2e568a360fe44c2d5ef1b49
text
Text only
1
2016-12-07T07:37:25
True
False
False
/api/public/snipt/84521/
sudo-inside-of-vim
<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>:w ! sudo tee % </span></pre></div> </td></tr></table>
Debian, Linux, Ubuntu, sudo, vim

Bash

How to redirect something using sudo

echo "# whatever" | sudo tee -a /etc/apt/sources.list
https://snipt.net/embed/b18b7f1a9c2aff9317c5c73d99da09ec/
https://snipt.net/raw/b18b7f1a9c2aff9317c5c73d99da09ec/
b18b7f1a9c2aff9317c5c73d99da09ec
bash
Bash
1
2016-12-07T15:47:08
True
False
False
/api/public/snipt/21883/
how-to-redirect-something-using-sudo
<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="nb">echo</span> <span class="s2">&quot;# whatever&quot;</span> <span class="p">|</span> sudo tee -a /etc/apt/sources.list </span></pre></div> </td></tr></table>
bash, sudo

Text only

write with sudo

:w !sudo tee %
https://snipt.net/embed/42c517d13ddca2c9bb2c32cfcf8bfc78/
https://snipt.net/raw/42c517d13ddca2c9bb2c32cfcf8bfc78/
42c517d13ddca2c9bb2c32cfcf8bfc78
text
Text only
1
2016-12-07T15:47:27
True
False
False
/api/public/snipt/20791/
write-with-sudo
<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>:w !sudo tee % </span></pre></div> </td></tr></table>
sudo, vim, write

Text only

How to write a read-only file in vi if you have sudo root

:w !sudo tee %
https://snipt.net/embed/cf4dcae6a97a0d5ea71ea7e97da96353/
https://snipt.net/raw/cf4dcae6a97a0d5ea71ea7e97da96353/
cf4dcae6a97a0d5ea71ea7e97da96353
text
Text only
1
2016-12-04T00:48:30
True
False
False
/api/public/snipt/20057/
how-to-write-a-read-only-file-in-vi-if-you-have-sudo-root
<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>:w !sudo tee % </span></pre></div> </td></tr></table>
root, sudo, vi, vim

Bash

recursive command to perform sudo actions

1
2
3
// linux: recursive command to perform sudo actions

find . -print  | sed -e 's/^/\"/' -e 's/$/\"/' | xargs sudo ...
https://snipt.net/embed/d24229297e9246d48803739366ae914d/
https://snipt.net/raw/d24229297e9246d48803739366ae914d/
d24229297e9246d48803739366ae914d
bash
Bash
4
2016-12-07T14:27:13
True
False
False
/api/public/snipt/9714/
recursive-command-to-perform-sudo-actions
<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></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a>// linux: recursive <span class="nb">command</span> to perform sudo actions </span><span id="L-2"><a name="L-2"></a> </span><span id="L-3"><a name="L-3"></a>find . -print <span class="p">|</span> sed -e <span class="s1">&#39;s/^/\&quot;/&#39;</span> -e <span class="s1">&#39;s/$/\&quot;/&#39;</span> <span class="p">|</span> xargs sudo ... </span></pre></div> </td></tr></table>
cmd, find, linux, sudo

Text only

passwordless PostgreSQL dumps

1
2
3
4
5
6
# /etc/sudoers
username machine = (postgres) NOPASSWD: /usr/bin/pg_dump
# Make sure no following rules override the above one.
# Now you can:
# [email protected] $ sudo -u postgres pg_dump mydb
# without needing to enter your password.
https://snipt.net/embed/b3eaa5687c0f900d5a349ba3e688ac2e/
https://snipt.net/raw/b3eaa5687c0f900d5a349ba3e688ac2e/
b3eaa5687c0f900d5a349ba3e688ac2e
text
Text only
6
2016-12-06T13:45:16
True
False
False
/api/public/snipt/4455/
passwordless-postgresql-dumps
<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> <a href="#L-6">6</a></pre></div></td><td class="code"><div class="highlight"><pre><span></span><span id="L-1"><a name="L-1"></a># /etc/sudoers </span><span id="L-2"><a name="L-2"></a>username machine = (postgres) NOPASSWD: /usr/bin/pg_dump </span><span id="L-3"><a name="L-3"></a># Make sure no following rules override the above one. </span><span id="L-4"><a name="L-4"></a># Now you can: </span><span id="L-5"><a name="L-5"></a># [email protected] $ sudo -u postgres pg_dump mydb </span><span id="L-6"><a name="L-6"></a># without needing to enter your password. </span></pre></div> </td></tr></table>
database, pg_dump, postgresql, sudo

Bash

copy PostgreSQL database from remote machine

[email protected] $ sudo -u postgres dropdb mydb
[email protected] $ ssh remote sudo -u postgres pg_dump -C mydb | sudo -u postgres psql
https://snipt.net/embed/24ccfb7bbc25089656f0665e6fca6aef/
https://snipt.net/raw/24ccfb7bbc25089656f0665e6fca6aef/
24ccfb7bbc25089656f0665e6fca6aef
bash
Bash
2
2016-12-06T13:45:32
True
False
False
/api/public/snipt/4454/
copy-postgresql-database-from-remote-machine
<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>[email protected] $ sudo -u postgres dropdb mydb </span><span id="L-2"><a name="L-2"></a>[email protected] $ ssh remote sudo -u postgres pg_dump -C mydb <span class="p">|</span> sudo -u postgres psql </span></pre></div> </td></tr></table>
copy, database, postgresql, ssh, sudo
Copyrighted, illegal, or inappropriate content? Email [email protected].