…with an open minded approach

Posts tagged “sudo

setup iptable rules for transmission (torrents)

Without further addo, here it is, a working example how to configure iptables to allow transmission torrents to internet (udp 51413) + transmission remote RPC (tcp 9091, localnetwork only) + ssh (tcp 22, localnetwork only).



Drop a comment if its usefull 🙂


text manipulation: lines to columns and other goodies

Have a look at the power of the “paste” comand – it just solves a bunch of situations with ease, and its litle known… transpose pair a lines into 2 columns, etc…


Have a look to these examples to get an idea of “paste” power…



sudo run as another user – scripting it

To ease your admin scripts….

bash trap and signals (or how to execute something at end of bash script)

In Bash scripts we can use “trap” to define handlers for capturing system-signals.

Apart from capturing system-signals (see a list of them with “kill -l”) bash also attends a non-standard EXIT signal, which is emitted just before the bash program exits.

In overall, being able to define handler for signals may be handy for example to grab “CTRL-C” or to clean temp-files before exiting


Running this twice, one first-time hitting CTRL-C and another time waiting untill it finishes, gives



Light overview of unix signals (indicating most common ones), in tutorialspoint

Bash with signals, from Bash Guide for Beginners

LinuxJournal article explaining that EXIT is not a real system-signal, but is synthesized by bash, with a very good overview of it all

fstab entry for ntfs

A handy line to add an NTFS partition (/sda/sda1) into /etc/fstab file, with general options (user with id 1000 is considered the owner of the mounted device)

Using sudo with proper environment “sudo -u , su – “

Before I forget again: the correct syntax to run a <command> as <user_x>, with the same login-environment as when user_x logs-in (preloading ~/.bashrc, … ) is

In case you want to “switch” to another user (as a login) then the proper way would be to

More info, see “man sudo” and “man su”

Testing a VPS machine

Just rented a Vps machine running ubuntu 12.04 lts 32bits… its virtualized with KVM, promissing 512MB Ram, 10GB HDD and 1TGB bw… for 3€/month with a promo until 6/01/2013 (what a bargain!) I can only think they are setting up the VPS service and need “testers”… the site itself is almost naked… and in less than a day, I’ve already experienced the first network-cuttof… but somehow it rocks for a “hobby” server

Well,  I’m very excited… a lot to play bound only by imagination limits 🙂

I’ll leave here some notes about what I did

Well, I’m overthrilled!!!!

Debian/Ubuntu: add user into group

To add user_x into group_z you can simply:

There is a hacky-method of updating the groups, without logout/relogin, but it only updates the current shell session (and its child processes) – see it explained in this gist

More info:  man adduser

Example in ascii.io:  add user “paulo” into group “admin”

Note: avoid the legacy command “useradd” because its clumsier to use (lots of args needed) and may easily remove user_x from other groups…. yes, dangerous… adduser much better

(X/K/L) Ubuntu install: resizing ntfs partition takes too long (check ntfsresize progress, from console with strace)

I was installing Lubuntu in a friends 2003 laptop, and had to resize the existing ntfs partition – after 2 hours of “resizing”, the linux installer was still in the same screen, and we were waiting hopefully  – the mouse moved, the window moved leaving a “trail”, but it made us wonder if it was progressing or blocked…

So, after switching to a terminal with CTRL+F1, I could see from “top” that the program ntfsresize was running for 2hours and going… it did not use much CPU or RAM dough, so it most certainly was an I/O speed bottleneck of the hardrive where the ntfs partition was being made.

After more than 3 hours, I started to worry: what if in the end, I discover that something went wrong, and we have to restart it? what if we have to shutdown the pc before it finishes and risk destroying his windows data? That would not be a good start with linux, not at all…

So, with these thoughts, I found that there is a way to snoop the stdoud and stderr of a running process – with strace


…And it did it: ntfsresize is progressing, but it sure takes a LOT of time to finish (like 6 or 10 hours!)

Hope it helps

Bash: root-only scripts

Before I forget again, I leave it here

Sometimes you want a script to exit if it’s not run by root.
In those cases, just put a line of code like the one below in the start of the script, so that it exits if the user running is not root:

However notice that:
a) there must be a space after the first curly-brace { (between { and echo) or it will not work
b) the last command inside the {} must have ; at the end

Upd 20120602:
Fixed a bug in the script – the command at the right of && should not be enclosed in parenthesis (), it should be enclosed in curly-braces {}
This is because commands inside () will be executed in a subshell (and so the exit 1 will only exit the subshell and not from the script), while commands enclosed in {} will be executed in the current shell
See the clarification here: http://www.gnu.org/software/bash/manual/bashref.html#Command-Grouping