Jan 18

In this post I will cover the usage of a terminal-based text editor, such as vim or nano, to modify text files.

NANO

Nano is one of the basic text editors in GNU/Linux. It is available on most of the distributions by default because it’s easy to use and one of the best choices for basic operations with text files.

In order to open a file for editing you just type:

nano mytextfile

This will open the file for editing. It’s best to use the -w option when editing configuration files, this option turns off word wrapping.

nano -w /etc/fstab

Unlike vim, nano is a “mode-less” text editor, meaning that once you opened a file, you may just type to edit it. The available commands can be seen on the bottom of the screen:

In order to save any change you’ve made, press CTRL + O – (the “^” sigh represents the CTRL key).

If you want to exit the editor, type CTRL + X.

You may also cut a single line by using CTRL +K and then paste it anywhere you want (just navigate with the arrow keys wherever you want) and then press CTRL +U.

Finally another useful shortcut is the shortcut for the search function, which is CTRL + W. Enter the string to search and press enter. The cursor will go to the first match found. In order to go to the next match, press ALT + W.

These are the basic functions of the nano text editor. For more advanced functions and usage, feel free to visit the Nano Project webpage.

VIM (which stands for VI Improved)

It’s an an advanced text editor that can do a lot of wonderful stuff. Fortunately just for RHCE/RHCSA exam you will only need to know the basics.

There are six different vim modes, but we are only interested in the Normal, Command Line and Insert modes.

In order to enter vim just type:

vim sometextfile

At first you go into the Normal mode. Here you may select the insert mode (by pressing i).

In insert mode you are able to edit the file, you can type and move with the arrow keys. In simple vi (not vim) you have to go back to Normal mode in order to “move around” using h,j,k,l keys.

To go back to Normal mode press ESC key.

In order to go to command line, you have to type the colon sign (:). This can be done only from the Normal mode. So if you are in Insert mode, go back to Normal mode by pressing ESC key.

In command line mode you way quit (press :q), write changes to file (:wq), force quit without saving any changes (:q!)

If you want to search for something in the file, go to Normal mode and type /somethingyouwanttosearchfor

So here is the sum up:

Create or edit file:

vim filename

Quit vim (:q)

Move cursor: Use the arrow keys or j, k, h, l (down, up, left, right)

Insert mode (:i)

Save file (:w)

Save and quit (:wq)

Abort and quit (:q!)

written by Cristian

Nov 17

Since I’ve met a lot of people having issues redirecting www to non-www, using 301 redirect to avoid duplicate content on google, I decided it would be a nice thing to post the best methods used for some of the most used http servers.

1. Apache

Apache is one of the most used http servers, has a lot of features and can be customized in so many ways. Actually, for this web server, there basically 2 ways you can do this, using httpd.conf directives or using a .htaccess file. Some people prefer using .htaccess files, because these reside in the website’s directory and can be modified by the website owner, which is not the case for the daemon configuration file (httpd.conf). So I will present both methods:

How to permanent redirect (301 redirect) NON WWW to WWW using apache server configuration directives:


    ServerName yourdomain.tld
    RedirectMatch permanent ^/(.*) http://www.yourdomain.tld/$1

    DocumentRoot /path/to/your/site
    ServerName www.yourdomain.tld

How to permanent redirect (301 redirect) WWW to NON WWW using apache server configuration directives:


    ServerName www.yourdomain.tld
    RedirectMatch permanent ^/(.*) http://yourdomain.tld/$1

    DocumentRoot /path/to/your/site
    ServerName yourdomain.tld

How to permanent redirect (301 redirect) NON WWW to WWW using .htaccess directives:
Create a file named .htaccess and append the following content: Continue reading »

written by Cristian \\ tags: , , , , , , , , , , ,

Aug 31

A couple of days ago I had to install a Point-to-Point Tunneling Protocol (PPTP) Server on a Centos 5.6 distribution (was a favor for a friend). In this case it is used to create a simple Virtual Private Network (VPN) to tunnel all the traffic through the server’s internet connection.

1. Make sure that you have a kernel greater than 2.6.15 and that you have ppp-compress module installed.  Otherwise you will have to install a MPPE module.

[root@server ~]# uname -r
2.6.18-238.12.1.el5
[root@server ~]# modprobe ppp-compress-18
[root@server ~]#

2. Install ppp package:

yum -y install ppp

3. Download the PPTP daemon package and install it:

wget http://poptop.sourceforge.net/yum/stable/packages/pptpd-1.3.4-2.rhel5.x86_64.rpm
rpm -ivh pptpd-1.3.4-2.rhel5.x86_64.rpm

4.  Make sure that you add the following lines to /etc/ppp/options.pptpd if these do not exist already (if you follow the exact steps in this tutorial, these should be already there):

[root@server ~]# cat /etc/ppp/options.pptpd |grep -v ^$ |grep -v ^#
name pptpd
refuse-pap
refuse-chap
refuse-mschap
require-mschap-v2
require-mppe-128
proxyarp
lock
nobsdcomp
novj
novjccomp
nologfd
[root@server ~]#

5. Now, you must take care of the /etc/pptpd.conf file. Here you define the IP address class used by the tunnel (this has nothing to do with your public IP address!)

[root@server ~]# cat /etc/pptpd.conf |grep -v ^$ |grep -v ^#
option /etc/ppp/options.pptpd
logwtmp
localip 192.168.86.254
remoteip 192.168.86.1-10
[root@server ~]#

6. It is time to add the credentials for the people using the Virtual Private Network in /etc/ppp/chap-secrets under the following format:

# client          server         secret          IP addresses
cristian          pptpd         mypassword            *

7. You must now make sure that you have packet forwarding enabled.

In /etc/sysctl.conf change the 0 to 1

net.ipv4.ip_forward = 0

will become

net.ipv4.ip_forward = 1

Now enable the changes using

sysctl -p

8. We want to tunnel all the traffic to the server’s Internet connection so we add the appropriate iptables firewall rule:

iptables -t nat -A POSTROUTING -o eth0 -j MASQUERADE

9. Configure the PPTP Server to run at startup

chkconfig --level 35 pptpd on

10. And finally start it!

service pptpd start

Congratulations! I hope you now have a working PPTP Virtual Private Network.

written by Cristian \\ tags: , , , , ,

Aug 11

Today I’m going to show you a nice way to sync only specific files from user directories to a “fast speed download” server.

Basically, all my users upload resources (maps, sounds, models, etc) for a Counter Strike 1.6 Server through FTP. The issue was the fact that all these files had to be copied to a webserver, in order to be served using “sv_downloadurl “http://fast.howtodoityourself.org/cs” option from Counter Strike server.

And, of course, most of the users upload also crap on FTP in their directories and most of the times in different locations. So I used the option from PURE FTP server to use an upload script that is ran each time a user uploads a file/directory.

So, I created a script that checks for .res, .bsp, .wav, .mdl, .wad files and copies them on the high speed upload server at the correct location, meaning that any .bsp file will go to /var/www/cs/maps/ directory, any .wav file will end up in /var/www/cs/sound directory and so on.

Below, I provide you the full script, you may use it any way you want, of course I do not take any kind of responsibility for any loss you or your “victim” may suffer :)

By the way, for this you will need to have installed lftp client!

#! /bin/bash
INPUT=$1
LOG="/var/log/upload-script.log"
echo "Script BEGIN" >> $LOG
echo $INPUT >> $LOG
FULLPATH=${INPUT%/*}
echo "The path to the filename is $FULLPATH" >> $LOG
FILENAME=${INPUT##*/}
echo "The complete filename is $FILENAME" >> $LOG
BASENAME=${FILENAME%%.*}
echo "The name of the file (without the extension) is $BASENAME" >> $LOG
EXT=${FILENAME#*.}
echo "The actual extension is $EXT" >> $LOG

#We now truncate the extension to lowercase
EXT=`echo $EXT | tr '[A-Z]' '[a-z]'`
echo "The extension in lowercase is $EXT" >> $LOG

SWITCH="yes"
	if [[ $EXT = "bsp" ]]; then
		WAY=cs/maps
		echo "This is a map file" >> $LOG
		echo "The path to map files is $WAY" >> $LOG
	elif [[ $EXT = "wav" ]];then
		WAY=cs/sound
		echo "This is a sound file" >> $LOG
		echo "The path to sound files is $WAY" >> $LOG
	elif [[ $EXT = "spr" ]];then
		WAY=cs/sprites
		echo "This is a sprite file" >> $LOG
		echo "The path to sprite files is $WAY" >> $LOG
	elif [[ $EXT = "res" ]];then
		WAY=cs/resource
		echo "This is a resource file" >> $LOG
		echo "The path to resource files is $WAY" >> $LOG
        elif [[ $EXT = "mdl" ]];then
                WAY=cs/models
                echo "This is a model file" >> $LOG
                echo "The path to model files is $WAY" >> $LOG
	elif [[ $EXT = "wad" ]];then
		WAY=cs
		echo "This is a wad file" >> $LOG
		echo "The path to wad files is $WAY" >> $LOG
	else
	        echo "FUCK the dumb user" >> $LOG
		echo "The uploaded file has no reason to be on fast download server" >> $LOG
		SWITCH="no"
	        exit 1
	fi

HOST='howtodoityourself.org'
USER='myuser'
PASS='mypassword'
TDIR='/var/www'

if [ "$SWITCH" = "yes" ];then
TDIR="${TDIR}/${WAY}"
SDIR="/tmp/for_sync"

if [ -d $SDIR ];then
	echo "Sourcedirectory already exists" >> $LOG
else
	echo "Creating source directory $SDIR" >> $LOG
	mkdir $SDIR
fi
cp $INPUT $SDIR;

lftp -f "
open $HOST
user $USER $PASS
mirror --reverse --only-missing --Remove-source-files $SDIR $TDIR
bye
"
echo "UPLOAD SUCCESSFUL!" >> $LOG
fi

echo "Script END" >> $LOG
echo >> $LOG
echo >> $LOG

Of course, if there is anything that you do not understand, please post your question using the comments form.

written by Cristian \\ tags: , , , , , ,

Aug 01

This post will be related to the use of grep, sed, and awk to process text streams and files.

GREP

Is a command searches a file for lines containing a match to the given strings and prints the matching lines.
It is mainly used in the following combinations:

grep 'some string'  given_file
cat given_file | grep 'some string'
command | grep 'some string'

Continue reading »

written by Cristian \\ tags: , , , , ,

Nov 15

In order to proceed with this “how to” you will need a functional RedHat or RedHat based distribution.

To do this, please follow How To Install Red Hat in 50 easy steps tutorial, or visit CentOS website for a free alternative to RedHat.

Note: CentOS does not provide commercial support!

“CentOS is an Enterprise-class Linux Distribution derived from sources freely provided to the public by a prominent North American Enterprise Linux vendor.  CentOS conforms fully with the upstream vendors redistribution policy and aims to be 100% binary compatible. (CentOS mainly changes packages to remove upstream vendor branding and artwork.)  CentOS is free.”

The above description is taken from the official CentOS website.

written by Cristian \\ tags: ,

Nov 01

How to Install Red Hat in 50 Easy Steps!

1 Star2 Stars3 Stars4 Stars5 Stars (3 votes, average: 4.33 out of 5)
Loading ... Loading ...

The first thing you need to do is to visit RedHat Store and buy your licence.

Once you have your installation CDs you may proceed with the installation.

1. Insert the 1st CD in the CD-ROM unit. Select as the first boot device the CD-ROM (see How To boot from CD).

This is the first screen that you will see:

RedHat_001

Just press ENTER to install in the Operating System in graphical mode.

2. The installation will start: Continue reading »

written by Cristian \\ tags: , , ,

Apr 23

How to install Ubuntu 9.04 in 20 Easy Steps

1 Star2 Stars3 Stars4 Stars5 Stars (5 votes, average: 4.20 out of 5)
Loading ... Loading ...

1. Go to Ubuntu official website, download the disk image and burn it on a cd. Insert the CD in your CD-ROM device and choose to boot from cd. This is the first screen you will see:

2. After choosing your language, wait for the system to load.

Continue reading »

written by Cristian

Jul 27

GNU/Linux Introduction

1 Star2 Stars3 Stars4 Stars5 Stars (6 votes, average: 4.83 out of 5)
Loading ... Loading ...

Many people these days, try to migrate from a non-free Operating System (OS) (like Windows/MAC OS) to a free solution, a free OS like GNU/Linux. Yes, it’s called GNU/Linux not simply Linux acording to the GNU Project.

In the middle of the 80′s GNU Project was created to develop a free UNIX-like OS (The GNU system), unfortunately the GNU kernel was never finished, so the GNU Project adopted the Linux kernel developed by Linus Torvalds. So you can see GNU/Linux as GNU over Linux, GNU OS over the Linux kernel.

GNU/Linux can be found in many flavours called Distributions developed and maintained by different communities. Here you can see an image describing the evolution of different distros. You may also like to take “the test” to find the most suitable one for your personal needs.

written by Cristian