Tunneling Apps in SSH

July 4th, 2009

Yesterday I found a very handy functionality in Putty: tunneling apps in SSH.

Not that I did not know that this technique exist ;) but for the first time I tried it and worked out of the box.

The idea is to enable tunneling of insecure applications inside an established and authenticated SSH encrypted session, using Putty as a client.

Scenario in my case is that I have few web based appliances at home acting as a media center, a NAS, etc… each of them being manageable by a web based interface on various ports.

I could certainly open destination PAT on my router, but it would increase the risk… and I don’t trust level of security implemented in such systems.

Therefore I’ve done something represented in picture below

ssh tunnel

How to configure it in Putty? Well, when you launch the session to connect to SSHD Server, check in SSH options – Tunnels.

There you find the chance to add the port forwarding parameters to be set as follows:

putty-tunnels

Enjoy!

Enabling SPDIF sound on Ubuntu with Dell Docking station

April 13th, 2009

Should you come across the same need, I just found a working solution, even if quite odd.

The trick to get it working is to go into sound settings and enable IEC958 Playback AC97-SPSA, checking that volume is set to… 0.

Magically sound will begin to flow out of the SPDIF interface.

Bulk File Rename

March 24th, 2009

Situation:

I have multiple files with extension .sh.modified and I need to rename them all into .sh extension.

Solution:

for file in *.sh.modified; do mv ${file} ${file%sh.modified}.sh; done

How to check for new files in a directory

March 21st, 2009

Made this small script for this purpose…

#!/bin/bash
#
# Script to check a directory and write in file the new files
# since last check.
#
# Written by RoarinPenguin (
roarinpenguin@rottigni.net) on
#
21 march 2009
# Released under GPL License
#
# You need to create a file called lastcheck.time in same
# directory of this script
#

ADMIN="change to administrator email address"
DIR2MON=/var/www/dir-clienti

> ./newfiles.list
echo "Last check for new files, done on "`date` >> ./newfiles.list
find $DIR2MON -maxdepth 5 -newer ./lastcheck.time >> ./newfiles.list
touch ./lastcheck.time

Using variables in sed

March 10th, 2009

In a world of Perl, sed seems to be an archaic method of doing things reserved to the real brave geeks!

But sometimes sed does perfectly fantastic job, like it did for me few minutes ago… with some caveats.

My goal was to replace $i with the value of the variable, determined by the first part of the script:

for i in `seq 1 50`;

the problem was that I made rest of the cycle as follows:

do cat newtest.xml|sed –e ‘s/variable/$i/’ >> multifirewallimport.xml; done

and the result was that through all my file the word variable was replaced with the word $i.

What was wrong? Well… Googling for it I discovered the issue was in usage of single quote instead of double quote.

The correct form is:

for i in `seq 1 50`; do cat newtest.xml|sed -e "s/variable/$i/" >> multifirewallimport.xml; done

Enabling root access to vsftpd

March 6th, 2009

It took me a while to figure out due to misleading information over the vast Internet suggesting to search for non existing /etc/vsftpd.users or something like this.

Thing you have to do is to edit /etc/ftpusers and remove root from there.

How to check if LDAPS is really running on a server?

February 9th, 2009

Sometimes this is necessary since the server “appears” to be running (netstat -an|grep 636 returns port in LISTEN state, but the daemon behind is not operative because (for instance) the certificate has not been installed.

If this is the case, grab an openssl client and issue the following command:

openssl s_client host <address of the target host> –port 636 (this is LDAPS standard port)

If server does have valid certificate you should get answer like:

If it does not, you’ll get something like this:

image

Assigning privileges to a user on MySQL DB

February 3rd, 2009

Quick and dirty commands from commandline:

mysql -u <user> -p<password>
mysql> CREATE DATABASE wordpress;
mysql> GRANT ALL PRIVILEGES ON wordpress.* TO ‘wpuser’@'localhost’ IDENTIFIED BY ‘dbpassword’;
mysql> SET PASSWORD FOR ‘wpuser’@'localhost’ = OLD_PASSWORD(‘dbpassword’);
mysql> FLUSH PRIVILEGES;
mysql> quit;

Scripting elegance: reading filenames containing spaces

February 3rd, 2009

You might need to do something with a list of files contained in a file… and maybe these file names include spaces, therefore using a standard

for i in `cat filename`
do
echo $i
done

does not work since it will consider every word as a single variable.

This second script does the job:

IFS=\$    ==> this sets the line separator as EOL
while read i    ==> this read variables separated by EOL and stores value in $i
do
echo $i    ==> this echoes the value of $i. Replace echo command with whatever you want to do with filenames
done < file-containing-the-list    ==> this ends the while do cycle and takes input from file where filenames are stored

I don’t want that NIC to be probed

January 20th, 2009

Suppose you are on a Linux box with multiple NICs.

It happens that there is one of them that loads with a driver disturbing test/activity you’re doing and you want to exclude it from modprobe.

You should edit file /etc/modprobe/blacklist and add there the driver name used by the card you want to get rid of, as follows:

/etc/modprobe.conf

[snip]
blacklist 8139cp
blacklist 8139too
[snip]

The example above (no, you don’t have to add snips, it is just to show that this is part of a bigger file…) will avoid Linux to probe for Realtek based NICs.