Archive for the 'General' Category

How to block a specific IP Address from accessing your Website

If you have annoying visitors, site scrapers, or spammers, you may find it useful to block these users from accessing your website content. You can block bad visitors by IP Address (or blocks of IP Addresses) using a .htaccess file. Below are some useful examples.

In the following example, all IP Addresses and domains are accepted, except for xxx.xxx.xxx.xxx and bad-site-example.com.

# allow all except those indicated here
<Files *>
order allow,deny
allow from all
deny from xxx.xxx.xxx.xxx
deny from .*bad-site-example\.com.*
</Files> 

In the following example, all IP addresses are denied access except for xxx.xxx.xxx.xxx and good-site-example.com.

# Deny access to everyone, except those listed here:
<Files *>
order deny,allow
deny from all
allow from xxx.xxx.xxx.xxx
allow from .*good-site-example\.com.*
</Files> 

Understanding basic vi (visual editor)

Vim is a text editor that is upwards compatible to Vi. It can be used to edit all kinds of plain text. It is especially useful for editing programs.

Vim behaves differently, depending on the name of the command (the executable may still be the same file).

vim The “normal” way, everything is default.

ex Start in Ex mode. Go to Normal mode with the “:vi” command. Can also be done with the “-e” argument.

This first line is just to simply open a file with vi:

vi file-name

The following command is used to recover a file that was being edited when the system crashed:

vi -r file-name

The next command will open a file as read-only:

vi ew file-name

To move around in the editor

type h to type move the cursor to the left
type l to move it to the right
type k to move up
type j to move down

To search within VI

To search for text in vi you can use the “/” key followed by your search term. This example uses buddy:

/buddy

To quit and not save changes you can use:

:q!

If you want to quit and save changes you can use the following command:

:x!

Reference : man vi command line

SBDavid

Finding your current IP Address

Finding your current IP Address

There are several free websites that offer you the ability to find your current IP Address. The following is a short list of websites that will provide you this information:

http://whatismyIP.com
http://IPChicken.com
http://tracemyip.org

Every device connected to the public Internet is assigned a unique number known as an Internet Protocol (IP) address. IP addresses consist of four numbers separated by periods, e.g. 127.0.0.1. Knowing the current IP Address of your home computer can be helpful when troubleshooting an issue.

SBDavid

Search and substitute

Search and substitute

You can easily search for data in the buffer using the vim search command. To enter a search string, press the forward slash (/) key.

The substitute command allows you to quickly replace (substitute) one word for another in the text. To get to the substitute command you must be in command line mode.

The format for the substitute command is:

:s/old/new/

There are a few modifications you can make to the substitute command to substitute more than one occurrence of the text:

:s/old/new/g to replace all occurrences of old in a line
:#,#s/old/new/g to replace all occurrences of old between two line numbers

:%s/old/new/g to replace all occurrences of old in the entire file
:%s/old/new/gc to replace all occurrences of old in the entire file, but prompt for each occurrence.

SBDavid

Sharing Files

Linux assigns the file permissions of the new file using your default UID and GID. To allow others access to the file, you need to either change the security permissions for the everyone security group or assign the file a different default group that contains other users.

This can be a pain in a large environment if you want to create and share documents among several people. Fortunately, there’s a simple solution for how to solve this problem.

There are three additional bits of information that Linux stores for each file and directory.

The set user id (SUID): When a file is executed by a user, the program runs under the permissions of the file owner.

The set group id (SGID): For a file, the program runs under the permissions of the file group. For a directory, new files created in the directory use the directory group as the default group.

The sticky bit: The file remains (sticks) in memory after the process ends.

The SGID bit is important for sharing files. By enabling the SGID bit, you can force all new files created in a shared directory to be owned by the directory’s group and now the individual user’s group.

The SGID is set using the chmod command. It’s added to the beginning of the standard three digit octal value (making a four-digit octal value), or you can use the symbol s in symbolic mode.

« Prev - Next »