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

Jan 17

If you own any Notebook for longer than one year then there comes a time when the cooling fan starts to run constantly and the device starts to get hot even in everyday tasks. My U550 is now 1 and a half years old and has started to use the fan all the time so I decided it was time for some maintenance, so cleaning the fan.

After searching the internet high and low I wasn’t able to find any guide on how to open the actual case of the U550. I actually got some results about how to repair a tractor but that’s a different story.

So I decided to do it myself, and after 2 hours here are the results.
Continue reading »

written by Andrei \\ tags: , , , , , ,

Jan 12

How to lose weight – Day 9

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

It has been an awful day, did not manage to go to the gym, some car issues that needed to be fixed quite urgent. My buddy wasn’t able to make it either.

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 13

How to confuse an idiot

1 Star2 Stars3 Stars4 Stars5 Stars (No Ratings Yet)
Loading ... Loading ...

Browsing the web, I found this funny new video ;)

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: , , , , , ,

Jun 01

How to pass RHCE/RHCT exam! – part 3

1 Star2 Stars3 Stars4 Stars5 Stars (1 votes, average: 5.00 out of 5)
Loading ... Loading ...
General Comments Off

Today we’re going to focus on how to use standard command line tools (e.g. ls, cp, mv, rm, tail, cat, etc.) to create, remove, view, and investigate files and directories.

If you are a beginner, the first thing I suggest is to check the current directory to avoid messing up things. This is simply done with pwd (print working directory):

[root@server ~]# pwd
/root
[root@server ~]#

Another basic command is ls. This just lists the files and directories inside the path given as an argument. If no path is specified, it will list all the files and directories from the current location:

[root@server ~/exam]# ls
directory1  file1
[root@server ~/exam]#
[root@server ~/exam]# ls /etc/httpd/
conf  conf.d  logs  modules  run
[root@server ~/exam]#

There are also hidden files and directories in GNU/Linux. These start with a dot “.” and can be seen by using the -a option for ls. To list the contents of a directory as a column, you may use the -l parameter. And to have the file sizes in a human readable form, just use -h.

[root@server ~/exam]# ls -a
.  ..  directory1  file1  .hidden
[root@server ~/exam]# ls -l
total 4
drwxr-xr-x 2 root root 4096 May  1 23:07 directory1
-rw-r--r-- 1 root root    0 May  1 23:06 file1
[root@server ~/exam]# ls -alh
total 20K
drwxr-xr-x  4 root root 4.0K May  1 23:12 .
drwxr-x--- 16 root root 4.0K May  1 23:06 ..
drwxr-xr-x  2 root root 4.0K May  1 23:07 directory1
-rw-r--r--  1 root root    0 May  1 23:06 file1
drwxr-xr-x  2 root root 4.0K May  1 23:12 .hidden
[root@server ~/exam]#

The basic tool to copy files or directories is named cp. To copy a whole directory you must use the -r option for recursive:

[root@server ~/exam]# ls
directory1  file1
[root@server ~/exam]#
[root@server ~/exam]# cp file1 file2
[root@server ~/exam]#
[root@server ~/exam]# ls
directory1  file1  file2
[root@server ~/exam]#

To copy a directory:

[root@server ~/exam]# ls
directory1  file1  file2
[root@server ~/exam]# cp -r directory1/ directory2
[root@server ~/exam]# ls
directory1  directory2  file1  file2
[root@server ~/exam]#

For more options, you may check the manual page for cp using

man cp

There is also a tool available for renaming/moving files or directories. It’s called mv and may be used like this:
-to rename a file

[root@server ~/exam]# ls
directory1  directory2  file1  file2
[root@server ~/exam]# mv file1 file1-renamed
[root@server ~/exam]# ls
directory1  directory2  file1-renamed  file2
[root@server ~/exam]#

-to rename a directory

[root@server ~/exam]# ls
directory1  directory2  file1-renamed  file2
[root@server ~/exam]# mv directory2/ directory2-renamed
[root@server ~/exam]# ls
directory1  directory2-renamed  file1-renamed  file2
[root@server ~/exam]#

-to move a file/directory to another location just specify the full/relative path

[root@server ~/exam]# mv directory2-renamed/ directory1/directory2/
[root@server ~/exam]# ls
directory1  file1-renamed  file2
[root@server ~/exam]# ls directory1/
directory2
[root@server ~/exam]#

Another basic but important tool is rm which is used to remove files or directories. Like in the case of cp, in order to remove a directory the -r (recursive) option must be specified:


[root@server ~/exam]# ls
directory1  file1-renamed  file2
[root@server ~/exam]# rm file2
rm: remove regular empty file `file2'? y
[root@server ~/exam]# rm -r directory1/directory2/
rm: remove directory `directory1/directory2/'? y
[root@server ~/exam]# ls
directory1  file1-renamed
[root@server ~/exam]# ls directory1/
[root@server ~/exam]#

To avoid being asked for confirmation use the -f (force) option, or use the full path for rm command, because rm is actually an alias to /bin/rm -i (interactive):

[root@server ~/exam]# which rm
alias rm='rm -i'
        /bin/rm
[root@server ~/exam]#

cat is the tool that will display the contents of a file for you. For example to see the contents of a file named example.txt you can use:

[root@server ~/exam]# cat example.txt

1
2
a - This is a letter
This is a test line
3 - And this is a number

[root@server ~/exam]#

If you want to search for a certain string, you send the output from a given command to a tool named grep:

[root@server ~/exam]# cat example.txt |grep test

This is a test line
[root@server ~/exam]#

This will print out all the lines containing the string test. In our case there was just 1 line.

written by Cristian

Dec 01

PPPoE Server – How To Do It Yourself

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

Today I noticed that one of my neighbors is using my wireless connection. One way to forbid him from using my really low bandwidth internet connection would be to encrypt the wireless connection, but that will also affect the transfer speed between the computers connected to the LAN and my cheap router will fail at some point (This did happen before…).

Another way was to use MAC address based access control to the wireless device, but since the MAC address can be easily spoofed I decided that it is a bad idea also.

The only thing remaining was to implement a user/password based authentication and I remembered that I did install a PPPoE server a few years ago. So this is how it works:

On the Linux box that splits the internet connection I have 2 network cards (eth0 – WAN, eth1 – LAN).

You will need ppp and rp-pppoe server from Roaring Penguin.

1. Make sure you have an active internet connection. If not, set it up by using your favorite text editor (I use vim):

vim /etc/network/interfaces 
auto lo
iface lo inet loopback

iface eth0 inet static
address 89.xxx.yyy.zzz     #Your public IP address
netmask 255.255.255.240  #Your subnet mask
gateway 89.xxx.xxx.xxx    #Your gateway

iface eth1 inet static
address 192.168.1.254
netmask 255.255.255.0

Set up one or more nameservers (I use the free ones provided by Google):

echo "nameserver 8.8.8.8" > /etc/resolv.conf
echo "nameserver 8.8.4.4" >> /etc/resolv.conf

Ping some website to make sure your internet connection is working:

cristian@desktop:~$ ping google.com
PING google.com (209.85.229.147) 56(84) bytes of data.
64 bytes from ww-in-f147.1e100.net (209.85.229.147): icmp_req=1 ttl=52 time=83.0 ms

2. Install ppp daemon:

sudo apt-get install ppp

3. Now get rp-pppoe from here.

wget http://www.roaringpenguin.com/files/download/rp-pppoe-3.10.tar.gz

And extract it

 tar -zxvf  rp-pppoe-3.10.tar.gz

Now compile it

cd rp-pppoe-3.10/src/
./configure
make && make install

4. Now, we shall edit the PPPoE server options:

vim /etc/ppp/pppoe-server-options
require-chap
login
lcp-echo-interval 10
lcp-echo-failure 2
ms-dns 8.8.8.8
ms-dns 8.8.4.4
netmask 255.255.255.0
defaultroute
noipdefault
usepeerdns

5. Add usernames and passwords:

vim /etc/ppp/chap-secrets
# Secrets for authentication using CHAP
# client server secret IP addresses

#USERNAME       SERVER              PASSWORD                            CLIENT IP ADDRESS
"cristanhuza"          *               "My_s3cret_pa$$w0rd"                     192.168.1.1
"friend1"                *               "My_friend's_s3cret_pa$sW0rd"         192.168.1.2

6. Set up the IP addresses pool:

echo "192.168.1.1-20" > /etc/ppp/allip

This will assign the future clients one IP address from the 192.168.1.1 until 192.168.1.20 range.

7. Start the PPPoE server:

pppoe-server -C isp -L 192.168.1.254 -p /etc/ppp/allip -I eth1

8. Enable packet forwarding between network interfaces:

echo 1 > /proc/sys/net/ipv4/ip_forward

9. Set up NAT in order to provide internet access to the LAN computers:

iptables -t nat -A POSTROUTING -s 192.168.1.0/24 -o eth0 -j MASQUERADE

Congratulations! You have just set up a PPPoE server and you can be worry free now that nobody else will be able to use your internet connection without permission.

written by Cristian

Nov 19

Quick guide to Microsoft Windows 7 versions

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

The Christmas season is fast approaching and a lot of people are thinking about buying or upgrading their PCs. But most people seem to forget that they also need an OS on their new system and looking at the Microsoft Windows 7 versions list it can get very confusing sometimes.

So, I decided to make a post specially dedicated to the people who don’t really know what the best Windows version for their needs is.

Some of you might say that the choice is very simple, just buy the one with the most features, but you see, that has it’s drawbacks. Most of the features you, as a normal everyday user, will probably never use and have also probably never heard about them or know what they do.  

You also need to consider the fact that all those extra features add extra services to the OS witch have to be started every time you use your system and that of course eats up a lot of resources witch you could use elsewhere.
Continue reading »

written by Andrei \\ tags: , , , , ,