Linux Microsoft VMware

Wednesday, September 5, 2012

Shell Script To Encrypt Any Given Text File


In cryptography, encryption is the process of transforming information (referred to as plaintext) using an algorithm (called cipher) to make it unreadable to anyone except those possessing special knowledge, usually referred to as a key.
Mcrypt is a simple crypting program, a replacement for the old unix crypt. When encrypting or decrypting a file, a new file is created with the extension .nc and mode 0600. The new file keeps the modification date of the original. The original file may be deleted by specifying the -u parameter. If no files are specified, the standard input is encrypted to the standard output.

Shell Script List All Top IP Address Accessing Apache Web Server


********************************
#!/bin/bash
# Shell Script To List All Top Hitting IP Address to your webserver.
# This may be useful to catch spammers and scrappers.

# where to store final report?
DEST=/var/www/reports/ips

Basic of Shell Script


What Is a Shell?


Ø       The shell is a user program or it is an environment provided for user interaction.
Ø       It is a command language interpreter that executes commands read from the standard input device such as keyboard or from a file.
Ø       The shell gets started when you log in or open a console (terminal).
Ø       Quick and dirty way to execute utilities.
Ø       The shell is not part of system kernel, but uses the system kernel to execute programs, create files etc.
Ø       Several shells are available for Linux including:
Ø       BASH ( Bourne-Again SHell ) - Most common shell in Linux. It's Open Source.
Ø       CSH (C SHell) - The C shell's syntax and usage are very similar to the C programming language.
Ø       KSH (Korn SHell) - Created by David Korn at AT & T Bell Labs. The Korn Shell also was the base for the POSIX Shell standard specifications.
Ø       TCSH - It is an enhanced but completely compatible version of the Berkeley UNIX C shell (CSH).
Please note that each shell does the same job, but each understands different command syntax and provides different built-in functions. Under MS-DOS, the shell name is COMMAND.COM which is also used for the same purpose, but it is by far not as powerful as our Linux Shells are!

Linux log files location and how do I view logs files?


Q. I am new to Linux and I would like to know where are the log files located under Debian or Cento OS Linux server? How do I open or view log files?

Ans. Almost all logfiles are located under /var/log directory (and subdirectory). You can change to this directory using cd command but you need to be the root user. You can use less, more, cat or tail command to see the logs.

Go to /var/logs directory:

How do I rotate log files?


Q. How do I rotate log files under Linux operating system?

A. You need use tool called logrotate, which is designed to ease administration of systems that generate large numbers of log files. It allows automatic rotation, compression, removal, and mailing of log files.

Each log file may be handled daily, weekly, monthly, or when it grows too large. With this tool you keep logs longer with less disk space.

Default configuration file

The default configuration file is /etc/logrotate.conf:

Redhat Enterprise Linux 5 / CentOS 5 monitor and track TCP connections on the network


Q. How do I track and monitor connection for eth1 public network interface under Redhat Enterprise Linux (RHEL) 5 server?

Ans.You can use netstat command or tcptrack command. Both command can show established TCP connection and provides the ability to monitor the same.

BASIC LDAP CONFIGURATION For RHEL / Centos / Fedora


INTRO: LDAP stands for Lightweight Directory Access Protocol. It is used as centralized data (or Directory) server (not database server) for various purposes.

There is a difference between Directory server and a Database server.
In Directory server the data is read more frequently than it is written.
In Database server the data is written more frequently than it is read.

Here we shall see how LDAP is used for creating centralized users (Network users).
The Network Users can also be configured using NIS (Network Information Service).

SUPPORTIVE SERVICES:

Configuration of NFS is required at server and client end. NFS plays the backbone for LDAP as it provides the Directory throughout the network.

Without NFS configuration of LDAP does not work.

Monday, September 3, 2012

Linux: Iptables Examples For New SysAdmins Part -->3


Before see this post please read my previous post (Linux: Iptables Examples For New SysAdmins Part -->2)


#12: Log and Drop Packets

 

Type the following to log and block IP spoofing on public interface called eth1

# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j LOG --log-prefix "IP_SPOOF A:

# iptables -A INPUT -i eth1 -s 10.0.0.0/8 -j DROP

Linux: Iptables Examples For New SysAdmins Part -->2


Before see this post please read my previous post (Linux: Iptables Examples For New SysAdmins Part -->1)

#3: Delete Firewall Rules

To display line number along with other information for existing rules, enter:

# iptables -L INPUT  -n --line-numbers
# iptables -L OUTPUT -n --line-numbers
# iptables -L OUTPUT -n --line-numbers | less
# iptables -L OUTPUT -n --line-numbers | grep 192.0.43.10

Linux: Iptables Examples For New SysAdmins Part -->1


Linux comes with a host based firewall called Netfilter. According to the official project site:
netfilter is a set of hooks inside the Linux kernel that allows kernel modules to register callback functions with the network stack. A registered callback function is then called back for every packet that traverses the respective hook within the network stack.
This Linux based firewall is controlled by the program called iptables to handles filtering for IPv4, and ip6tables handles filtering for IPv6. I strongly recommend that you first read our quick tutorial thatexplains how to configure a host-based firewall called Netfilter (iptables) under CentOS / RHEL / Fedora / Redhat Enterprise Linux. This post list most common iptables solutions required by a new Linux user to secure his or her Linux operating system from intruders.

Powered by Blogger.