mercoledì 1 febbraio 2012

Resizing (a lot of) images with a command.

I have to resize few pictures for a website, if you use Ubuntu you can use this command line tool called "mogrify" included in the "imagemagick" package.

To install it:

fem@rodizio:~$ sudo apt-get install imagemagick


Then, resize...

fem@rodizio:~$ cd /path/to/pictures/
fem@rodizio:~$ mogrify -resize 450x338 -format jpg *.jpg


Here I resize all jpg images I have in the folder to the 450x338 resolution, but you can change parameters how you prefer.


Note that this command will overwrite the previous pictures.
That's all

martedì 24 gennaio 2012

UBUNTU 10.04 - Hiding users at grafic login screen

I had a problem since I created some additional users for particular tasks but I didnt want they were shown in the login screen.
Edit this file

fem@rodizio:~$ sudo vi /etc/gdm/custom.conf


adding this lines

[greeter]
Exclude=user1,user2,user3,nobody

where user1, user2 and user3 are users to hide at login screen; nobody must be added otherwise it will be shown.
Then reboot..

lunedì 23 gennaio 2012

SOCKS5 Proxy for secure browsing

If you use to connect from open access internet points and you have a valid account on a SSH server , in my case I can use a simple modified router a Pirelli AGA (mounting linux and a valid SSH server) to do so.

From the shell of the client

fem@rodizio:~$ ssh USER_SERVERSSH@SERVERSSH -p 1022 -D 2100

"-p 1022" since my ssh service listen on this port (the default one is 22)
"-D 2100" tells the SSH client (localhost) to listen at this port to listen our browser requests.

We have only to go on browser settings (ie, opera, firefox ,chrome etc) and indicate that we use a socks5 proxy indicating as ip "localhost" and as port "2100"

that's all

OPENWRT - Reverse tunnel with SSH

I want to reach a router that is connected to the net using like gateway a USB dongle, the problem is that my network provider use a NAT that doesn't allow to reach the dongle with a public ip.
The solution is a "reverse tunnel" (in this case with SSH) that is initiate from the remote host we want to reach (the OpenWRT router) to a SSH server that in my case is an Ubuntu 10.04 box.
OPENWRT use as SSH client dropbear, a lightweight version that is compatible with public key authentication of the standard openSSH.


Generate a valid public key on the OpenWRT router with dropbear in .ssh folder . NO PUBLIC KEY FILES HAVE TO BE INSIDE THIS FOLDER OTHERWISE DROPBEARKEY WILL GENERATE AN ERROR!!

root@OpenWrt:~/.ssh# cd /root/.ssh/
root@OpenWrt:~/.ssh# dropbearkey -t rsa -f id_rsa


The output shold be something like that

root@OpenWrt:~/.ssh# dropbearkey -t rsa -f id_rsa
Will output 1024 bit rsa secret key to 'id_rsa'
Generating key, this may take a while...
Public key portion is:
ssh-rsa AAAAB3NzaC1yc2EAAAADAQABAAAAgwCZfO3SRHCmekstO+tLRS4Yj3a0/8tCeWgXbQLI+3dv+wqZKS1wfOlLviRA9yj124CoAAAAB3NzaC1yc2EAAAADAQABAAAAgwCZfO3SRHCmekstO+tLRS4Yj3a0/8tCeWgXbQLI+3dv+wqZKS1wfOlLviRA9yj124Co
V6GRZbzPmJ+b root@OpenWrt
Fingerprint: md5 ac:a4:aa:f8:a2:a7:e8:ae:b9:ad:aa:2e:a4:eb:a0:a7


Copy the string of the generated public key in authorized_keys in the .ssh folder of the SSH server (ssh-rsa ..... root@OpenWrt) , I used scp command but you can do it in every way , by hand for example.


root@OpenWrt:~/.ssh# cd /root/.ssh/
root@OpenWrt:~/.ssh# scp -P 1022 authorized_keys USER_SERVER@SERVERSSH:/home/USER_SERVER/.ssh/

Now it should be possible to authenticate with the public key and without password

Note that this 2 commands are equivalent with the dropbear client

root@OpenWrt:~/.ssh# dbclient -i ~/.ssh/id_rsa -y -p 1022 USER_SERVER@SERVERSSH #equivalent to
root@OpenWrt:~/.ssh# ssh -i ~/.ssh/id_rsa -y -p 1022 USER_SERVER@SERVERSSH


This is the command to make the tunnel ssh run in background (this is necessary if you want to put it in a script)


/usr/bin/dbclient -f -N -R 1500:localhost:22 -p 1022 USER_SERVER@SERVERSSH -i /root/.ssh/id_rsa -y


Now logging in the SSH server shell with this command we will be able to reach the OpenWRT shell using port 1500 of the SSH server and using the tunnel we have create.


USER_SERVER@SERVERSSH:~/ssh root@localhost -p 1500

SSH automatic authentication without inserting password

We start with 2 ubuntu box's 10.04 , one is the server (SERVER_SSH) the other is the client (CLIENT_SSH).
Both box's have not .ssh folder in their home directory.

On the CLIENT_SSH:
make .ssh folder in the home directory

user@CLIENT_SSH:~$ mkdir ~/.ssh

generating id_rsa.pub public key

user@CLIENT_SSH:~$ cd ~/.ssh
user@CLIENT_SSH:~$ ssh-keygen -t rsa

copying content of id_rsa.pub in the authorized_keys file using cat command (can do it also by hand copying and pasting)

user@CLIENT_SSH:~$ cd ~/.ssh
user@CLIENT_SSH:~$ cat ~/.ssh/id_rsa.pub >> authorized_keys

add the ssh client

user@CLIENT_SSH:~$ssh-add




On the SERVER_SSH:

make sure the /etc/ssh/sshd_config file allow this kind of authentication

otheruser@SERVER_SSH:~$ vi /etc/ssh/sshd_config

the following parameters must be set on 'yes'

RSAAuthentication yes
PubkeyAuthentication yes


make .ssh folder in the home directory

otheruser@SERVER_SSH:~$ mkdir ~/.ssh

copying the client authorized_keys file to the server (-P 1022 its only for me since the ssh service is listening on this port, otherwise put 22 here)

restarting ssh server

otheruser@SERVER_SSH:~$ /etc/init.d/ssh restart

Now, should be possible authentication without inserting password at prompt.

sabato 21 gennaio 2012

Blocking websites on OpenWRT

If you have an openwrt router that is your gateway and you dont want to let users access some websites, you must edit the file dnsmasq.conf:


root@OpenWrt:~# vi /etc/dnsmasq.conf


adding this line:


#### Blocked website internet.tre.it ####
address=/internet.tre.it/127.0.0.1


then restarting dnsmasq service


root@OpenWrt:~# /etc/init.d/dnsmasq restart


that's all.

venerdì 4 novembre 2011

Testare velocità cavo lan con Ubuntu

Se non vi interessa la premessa saltate all' asterisco ***
In questi giorni ho cablato un locale ( ho finito 300m di cavo e non mi è nemmeno bastato !!)
A parte passare il cavo nei corrugati ho anche dovuto imparare a crimpare le 2 estremità del cavo con i classici plug.
Il cavo utilizzato è un cat5e, non di qualità eccelsa, comunque sembra funzionale allo scopo.
Oggi sono andato a testare che i cavi funzionassero e mi è venuta la voglia di misurare anche la velocità massima trasferibile. Ricordo che i cat5e sono già gigabit quindi in teoria potrei raggiungere i 1000mbit/s (wow!).
Purtroppo la velocità reale è un po diversa visto che esistono i router, le schede di rete 100mbit/s e mille altri colli di bottiglia.
Ho pensato, dopo aver messo un router tra i 2 pc che dovevano trasmettersi un file di prova, che quello non era il migliore modo per testare il cavo in se per se.
Perchè ? Perchè il router che avevo io , di qualità media , non mi faceva andare a più di 5,5 mb/s quindi 44mbit/s.... insoddisfacente per la mia gigabit lan.
Allora ho tolto il router facendo un aggiunta al cavo da testare con un cavo crossover per realizzare un link diretto tra i 2 pc.
Per la cronaca un cavo crossover è un cavo lan con ad una estremità un plug crimpato in standard 568a e dall' altra 568b.
E,ancora per la cronaca :ora come ora, con 2 pc non preistorici si puó fare il link diretto con un cavo dritto (568b o 568a su entrambe le estremità) visto che le schede di rete moderne sono "autosensing",
Con il link diretto la velocità è salità a circa 8mb/s circa 64mbit/s.... un pó meglio ma ancora bassa.
Il problema sta nella velocità dei dischi rigidi, di uno dei due portatili (10 anni di vita).
Così tornato a casa ho deciso di testare la velocità di trasferimento tra 2 pc con scheda di rete gigabit e disco rigido sata, risultato 55mb/s quindi 440mbit/s .... cominciamo a ragionare !
Quindi ho capito che ci voleva qualcosa di "più tecnico" per testare questi cavi, visto che i colli di bottiglia sono ovunque trasferendo grezzamente un file tra 2 pc.
***
Cercando su google (cosa di cui sono malato) ho trovato un programmino microscopico da terminale per linux chiamato iperf
sudo apt-get install iperf

da installare su entrambi i pc.
Poi si da su un pc che fungerà da server
iperf -s

e sull' altro
iperf -c 192.168.1.10


Sostituite 192.168.1.10 con l' ip del pc che fa da server.
Il programma fa il test (pochi secondi)e vi da il risultato.
Nel mio caso per i cavi patch sia crossover che dritti di 1.5 metri circa mi da come velocità max 961mbit/s.......ok siamo vicini al gigabit.
Ora non mi resta che testarlo sui cavi che ho realizzato..... vi faró sapere.
Saluti


- Posted using BlogPress from my iPhone