Friday, October 17, 2008

Setup OpenVPN in Ubuntu

To get my work on time schedule, I must bring it as my homework. It is software development. For this purpose, I have to connect my office computer to home computer with VPN.
1st - ISP's Modem
Open firewall or port triggering: 1194 UDP
ThenVirtual Server, forward incoming connection 1194 port to my office computer's IP address.
2dn - Install OpenVPN
Office / Server: Ubuntu 8.04 (Hardy Heron) Server
Home / Client: Ubuntu 8.04 Desktop
Install openvpn in both computers:
sudo apt-get install openvpn
3rd - Configure the server: (see HOWTO for more)
cd /etc/openvpncp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/ ./easy-rsa/cd easy-rsa
(optionals)
nano ./vars
Change the values:
export KEY_COUNTRY=ID
export KEY_PROVINCE=KEPRIexport KEY_CITY=BATAMexport KEY_ORG="OpenVPN-TEST"
export KEY_EMAIL="eshabe@gimail.com"
(then):
source ./vars
./clean-all
./build-ca
Pay attention in “Common Name”. Example answer: "myfirstvpn"
./build-key-server server
Pay attention in...
“Common Name” - my answer is “server”
“Sign the certificate? [y/n]” - answer “y”
“1 out of 1 certificate requests certified, commit? [y/n]” - answer “y”
./build-key client1
./build-key client2
./build-key client3
./build-dh
Copy key files:
cd /etc/openvpn
cp easy-rsa/keys/server.crt .
cp easy-rsa/keys/server.key .
cp easy-rsa/keys/ca.crt .
cp easy-rsa/keys/dh1024.pem .
Copy example config file:
gunzip /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz
4th - Configure the client
Copy key files:
cd /etc/openvpn
scp eshabe@125.x.x.x:/etc/openvpn/easy-rsa/keys/client1.crt client.crt
scp eshabe@125.x.x.x:/etc/openvpn/easy-rsa/keys/client1.key client.key
scp eshabe@125.x.x.x:/etc/openvpn/easy-rsa/keys/ca.crt ca.crt
Copy example config file:
cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf .
Edit config file:
nano client.conf
Change remote value:
remote 125.1.2.3 1194
5th - Try and activate
Try:
(server)
openvpn server.conf
(client)
openvpn client.conf
Yes!! openvpn is ready….
/etc/init.d/openvpn start

Sunday, October 5, 2008

HowTo: No waiting time in Ubuntu's GRUB

By default, Ubuntu display a GRUB menu and give us ten (10) seconds waiting time for user interaction. If you feel this waiting time is disturbing, you can remove the waiting time by edit the GRUB menu. Set 'timeout' value to 0 (zero).

From Terminal, type:

sudo nano /boot/grub/menu.lst

Change timeout value.

And, do not forget to activate hiddenmenu option. Why? By activating the option, although the timeout is 0 second, we can enter to the GRUB menu by pressing ESC key.

Save the file!

Create 'tar' file from a list

Creating a 'tar' file is simple, but creating a 'tar' file from some files have different paths/directories is another case.

Example, when I want to create a tar file from path /home/eshabe/mydocs, I can use command: tar cvf mydoc.tar /home/eshabe/mydocs

But when I want to create a tar file from files:
/home/eshabe/mydocs/howto-create-tar-file-from-a-list
/etc/apache2/site-enables/000-default
/home/eshabe/mydocs/yes/i/am
/home/eshabe/.gnome2
...
?

I can create a tar file from command line: tar cvf mydoc.tar /home/eshabe/...

Another way is create a shell (sh) script to read a list file then create a tar file:

#!/bin/sh
# Create a 'tar' file from a list


n_program=`basename $0`
v_program=1.0.0d1
p_program=eshabe

t_program='2003.08.12'


RUNNAME='./shb-tarlist-run'

info_program ()
{
cat <<>
$n_program v$v_program
by: $p_program - $t_program
----------------------------------------------------------------------------
Function : create a tar file from a list file
Command : $nama_program LIST_FILE FILE.tar

LIST_FILE = a file contains list of files or directories
FILE.tar = result

pesan_program

}

if [ $# != 2 ]
then
info_program
exit
fi

printf "tar cvf $2 " > $RUNNAME
awk '{
printf "%s ", $0
}' $1 >> $RUNNAME

chmod a+x $RUNNAME
$RUNNAME
rm $RUNNAME

echo Done.