Tuesday, March 13, 2012

Courier mail server


                  The Courier mail server is a mail transfer agent (MTA) server that provides ESMTP, IMAP, POP3, SMAP, webmail, and mailing list services with individual components. It is best known for its IMAP server component.

                Courier can function as an intermediate mail relay, between an internal LAN and the Internet, or perform final delivery to mailboxes. Courier uses maildirs as its native storage format and can also deliver mail to legacy mailbox files. Configuration files are in plain text format and may include Perl scripts.Courier can provide mail services for regular operating system accounts. Courier can also provide mail services for virtual mail accounts, managed by any of LDAP directory service, Berkeley DB, MySQL or PostgreSQL authentication database.
 
              Parts of Courier, such as the maildrop filtering system, the webmail and IMAP server, can also be installed as independent packages which can be used with other mail servers. Courier-IMAP is a particularly popular combination with Qmail, Exim, and Postfix servers that are configured to use maildirs.Courier's source compiles on most POSIX-based operating systems based on Linux and BSD-derived kernels. It uses SMTP extensions for list management and spam filtering.A review of SourceForge on February 24, 2009 indicates that Courier had been downloaded from that site over 1,000,000 times ranking 282nd on all packages with numerous third-party applications


              The Courier mail transfer agent (MTA) is an integrated mail/groupware server based on open commodity protocols, such as ESMTP, IMAP, POP3, LDAP, SSL, and HTTP. Courier provides ESMTP, IMAP, POP3, webmail, and mailing list services within a single, consistent, framework. Individual components can be enabled or disabled at will. The Courier mail server now implements basic web-based calendaring and scheduling services integrated in the webmail module. Advanced groupware calendaring services will follow soon.

            The Courier mail server's source code should compile on most POSIX-based operating systems based on Linux, and BSD-derived kernels. The Courier mail server should also compile on Solaris and AIX, with some help from Sun's or IBM's freeware add-on tools for their respective operating systems.
The Courier mail server evolved out of several related projects, that merged together (more on that later). The Courier mail server implements SMTP extensions for mailing list management and spam filtering. The Courier mail server can function as an intermediate mail relay, relaying mail between an internal LAN and the Internet, or perform final delivery to mailboxes. The Courier mail server uses maildirs as its native mail storage format, but it can also deliver mail to legacy mailbox files as well. The Courier mail server's configuration is set by plain text files and Perl scripts. Most of The Courier mail server's configuration can now be adjusted from a web browser, using The Courier mail server's web-based administration module.
The Courier mail server can provide mail services for regular operating system accounts. The Courier mail server can also provide mail services for virtual mail accounts, managed by an LDAP, MySQL, or PostgreSQL-based authentication database.

 

Configuration file locations on Linux dedicated servers


Configuration file locations on Linux dedicated servers

Global PHP Config = /usr/local/lib/php.ini

MySQL Config = /etc/my.cnf

PureFTPd Config = /etc/pure-ftpd.conf

Apache Config = /etc/httpd/conf/httpd.conf

Exim Config = /etc/exim.conf

Courier Config = /etc/log.d/conf/services/courier.conf

IMAP Config = /etc/log.d/conf/services/imapd.conf

DNS Config = /etc/named.conf

SSHD Config = /etc/ssh/sshd_config

IP Config = /etc/sysconfig/network-scripts/

FTP  =  /etc/vsftpd/vsftpd.conf

SELinux  =  /etc/sysconfig/selinux

SAMBA  =   /etc/samba/smb.conf

Sendmail   = /etc/mail/sendmail.cf  and /etc/mail/sendmail.mc

Postfix   =  /etc/postfix/main.cf

VPN   =  /etc/ipsec.conf

Monday, March 5, 2012

DNS Related Questions


                    

Some DNS Related Questions

 

 How DNS resolution works?


A client application requests an IP address from the nameserver usually by connecting to UDP port 53. The nameserver will attempt to resolve the FQDN based on its resolver library, which may contain authoritative information about the host requested or cached data about that name from an earlier query.
If the nameserver does not already have the answer in its resolver library, it will turn to root nameservers, to determine which nameservers are authoritative for the FQDN in question. Then, with that information, it will query the authoritative nameservers for that name to determine the IP address.


What is FQDN and a secondary nameserver?


FQDN of a host can be broken down into sections organized in a tree hierarchy. Except for the hostname, every section divided by “.” is a called a zone.
Zones are defined on authoritative nameservers in zone files. Zone files are stored on primary nameservers (also called master nameservers), which are truly authoritative and where changes are made to the files.
Secondary nameservers (also called slave nameservers) receive their zone files from the primary nameservers. Any nameserver can be a primary and secondary nameserver for different zones at the same time, and they may also be considered authoritative for multiple zones. It all depends on the nameserver’s particular configuration.
Every second level domain should have one primary and one secondary nameserver running on different physical machines for redundancy.
There are four nameserver configuration types:
master — Stores original and authoritative zone records for a certain zone, answering questions from other nameservers searching for answers concerning that namespace.
slave — Also answers queries from other nameservers concerning namespaces for which it is considered an authority. However, slave nameservers get their namespace information from master nameservers via a zone transfer, where the slave sends the master a NOTIFY request for a particular zone and the master responds with the information, if the slave is authorized to receive the transfer.
caching-only — Offers name to IP resolution services but is not authoritative for any zones. Answers for all resolutions are usually cached in a database stored in memory for a fixed period of time, usually specified by the retrieved zone record, for quicker resolution for other DNS clients after the first resolution.
forwarding — Forwards requests to a specific list of nameservers to be resolved. If none of the specified nameservers can perform the resolution, the process stops and the resolution fails.


What are ZONE files?


Zone files contain information about a particular namespace. Zone files are stored in /var/named working directory. Each zone file is named according to the file option data in the zone statement, usually in a way that relates to the domain in question and identifies the file as containing zone data, such as example.com.zone.
Each zone file may contain directives and resource records. Directives tell the nameserver to do a certain thing or apply a special setting to the zone. Resource records define the parameters of the zone, assigning an identity within the zone’s namespace to particular systems. Directives are optional, but resource records are required to provide nameservice to that zone. All directives and resource records should go on their own lines.
$ vi /var/named/zones/llc.com.db
llc.com. IN SOA dns1.llc.com. root.dns1.llc.com. (
001 ; serial
1H ; refresh
15M ; retry
1W ; expiry
1H ; ttl
)
@ IN NS dns1
dns1 IN A 192.168.2.5
@ IN A 192.168.2.5
www IN CNAME dns1
redhat.llc.com. IN NS dns1.redhat.llc.com.
dns1.redhat.llc.com. IN A 192.168.2.10
$ vi /var/named/zones/2.168.192.db
llc.com. IN SOA dns1.llc.com. root.dns1.llc.com. (
001 ; serial
1H ; refresh
15M ; retry
1W ; expiry
1H ; ttl
)
@ IN NS dns1
5 IN PTR dns1.llc.com.


What is an MX record?


MX record allows you to numerically rank the email servers you would prefer to receive email for this namespace, giving preference to some email systems over others. The MX resource record with the lowest is preferred over the others, but you can set multiple email servers with the same value to distribute email traffic between them.
IN MX 10 mail.domain.com.
IN MX 20 mail2.domain.com.

Linux Questions with answers


                     Linux Interview Questions with answers  

Which command is used to check the number of files and disk space used and the each user’s defined quota?

repquota command is used to check the status of the user’s quota along with the disk space and number of files used. This command gives a summary of the user’s quota that how much space and files are left for the user. Every user has a defined quota in Linux. This is done mainly for the security, as some users have only limited access to files. This provides a security to the files from unwanted access. The quota can be given to a single user or to a group of users.

What is the name and path of the main system log?

By default the main system log is /var/log/messages. This file contains all the messages and the script written by the user. By default all scripts are saved in this file. This is the standard system log file, which contains messages from all system software, non-kernel boot issues, and messages that go to 'dmesg'. dmesg is a system file that is written upon system boot.

How secured is Linux? Explain.

Security is the most important aspect of an operating system. Due to its unique authentication module, Linux is considered as more secured than other operating systems. Linux consists of PAM. PAM is Pluggable Authentication Modules. It provides a layer between applications and actual authentication mechanism. It is a library of loadable modules which are called by the application for authentication. It also allows the administrator to control when a user can log in. All PAM applications are configured in the directory "/etc/pam.d" or in a file "/etc/pam.conf". PAM is controlled using the configuration file or the configuration directory.

Can Linux computer be made a router so that several machines may share a single Internet connection? How?

Yes a Linux machine can be made a router. This is called "IP Masquerade." IP Masquerade is a networking function in Linux similar to the one-to-many (1: Many) NAT (Network Address Translation) servers found in many commercial firewalls and network routers. The IP Masquerade feature allows other "internal" computers connected to this Linux box (via PPP, Ethernet, etc.) to also reach the Internet as well. Linux IP Masquerading allows this functionality even if the internal computers do not have IP addresses.
The IP masquerading can be done by the following steps:

1. The Linux PC must have an internet connection and a connection to LAN. Typically, the Linux PC has two network interfaces-an Ethernet card for the LAN and a dial-up PPP connection to the Internet (through an ISP).

2. All other systems on your LAN use the Linux PC as the default gateway for TCP/IP networking. Use the same ISP-provided DNS addresses on all systems.

3. Enable IP forwarding in the kernel. By default the IP forwarding is not enabled. To ensure that IP forwarding is enabled when you reboot your system, place this command in the /etc/rc.d/rc.local file.

4. Run /sbin/iptables-the IP packet filter administration program-to set up the rules that enable the Linux PC to masquerade for your LAN.

What is the minimum number of partitions you need to install Linux?

Minimum 2 partitions are needed for installing Linux. The one is / or root which contains all the files and the other is swap. Linux file system is function specific which means that files and folders are organized according to their functionality. For example, all executables are in one folder, all devices in another, all libraries in another and so on. / or ‘root’ is the base of this file system. All the other folders are under this one. / can be consider as C: .Swap is a partition that will be used as virtual memory. If there is no more available RAM a Linux computer will use an area of the hard disk, called swap, to temporarily store data. In other words it is a way of expanding your computers RAM.

Which command is used to review boot messages?

dmesg command is used to review boot messages. This command will display system messages contained in the kernel ring buffer. We can use this command immediately after booting to see boot messages. A ring buffer is a buffer of fixed size for which any new data added to it overwrites the oldest data in it. Its basic syntax is

dmesg [options]

Invoking dmesg without any of its options causes it to write all the kernel messages to standard output. This usually produces far too many lines to fit into the display screen all at once, and thus only the final messages are visible. However, the output can be redirected to the less command through the use of a pipe, thereby allowing the startup messages to be viewed on one screen at a time
dmesg | less

Which utility is used to make automate rotation of a log?

logrotate command is used to make automate rotation of log.
Syntax of the command is:
logrotate [-dv] [-f|] [-s|] config_file+
It allows automatic rotation, compression, removal, and mailing of log files. This command is mainly used for rotating and compressing log files. This job is done every day when a log file becomes too large. This command can also be run by giving on command line. We can done force rotation by giving –f option with this command in command line. This command is also used for mailing. We can give –m option for mailing with this command. This option takes two arguments one is subject and other is recipient name.

What are the partitions created on the mail server hard drive?

The main partitions are done firstly which are root, swap and boot partition. But for the mail server three different partitions are also done which are as follows:
1. /var/spool- This is done so that if something goes wrong with the mail server or spool than the output cannot overrun the file system.
2. /tmp- putting this on its own partition prevents any user item or software from overrunning the system files.
3. /home- putting this on its own is useful for system upgrades or reinstalls. It allow not to wipe off the /home hierarchy along with other areas.

What are the fields in the/etc/passwd file?

It contains all the information of the users who log into the system. It contains a list of the system's accounts, giving for each account some useful information like user ID, group ID, home directory, shell, etc. It should have general read permission as many utilities, like ls use it to map user IDs to user names, but write access only for the superuser (root). The main fields of /etc/passwd file are:
1. Username: It is used when user logs in. It should be between 1 and 32 characters in length.
2. Password: An x character indicates that encrypted password is stored in /etc/shadow file.
3. User ID (UID): Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.
4. Group ID (GID): The primary group ID (stored in /etc/group file)
5. User ID Info: The comment field. It allow you to add extra information about the users such as user's full name, phone number etc. This field use by finger command.
6. Home directory: The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes /
7. Command/shell: The absolute path of a command or shell (/bin/bash). Typically, this is a shell.

Which commands are used to set a processor-intensive job to use less CPU time?

nice command is used for changing priority of the jobs.
Syntax: nice [OPTION] [COMMAND [ARG]...]
Range of priority goes from -20 (highest priority) to 19 (lowest).Priority is given to a job so that the most important job is executed first by the kernel and then the other least important jobs. This takes less CPU times as the jobs are scheduled and are given priorities so the CPU executes fast. The priority is given by numbers like -20 describe the highest priority and 19 describe the least priority.

How to change window manager by editing your home directory?

/.xinitrc file allows changing the window manager we want to use when logging into X from that account. The dot in the file name shows you that the file is a hidden file and doesn't show when you do a normal directory listing. For setting a window manager we have to save a command in this file. The syntax of command is: exec windowmanager.After this, save the file. Next time when you run a startx a new window manager will open and become default. The commands for starting some popular window managers and desktop environments are:
-KDE = startkde
-Gnome = gnome-session
-Blackbox = blackbox
-FVWM = fvwm
-Window Maker = wmaker
-IceWM = icewm

How documentation of an application is stored?

When a new application is installed its documentation is also installed. This documentation is stored under the directory named for application. For example if my application name is App1 then the path of the documentation will be /user/doc/App1. It contains all the information about the application. It contains date of creating application, name of application and other important module of the application. We can get the basic information of application from the documentation.

How shadow passwords are given?

pwconv command is used for giving shadow passwords. Shadow passwords are given for better system security. The pwconv command creates the file /etc/shadow and changes all passwords to ‘x’ in the /etc/passwd file. First, entries in the shadowed file which don't exist in the main file are removed. Then, shadowed entries which don't have `x' as the password in the main file are updated. Any missing shadowed entries are added. Finally, passwords in the main file are replaced with `x'. These programs can be used for initial conversion as well to update the shadowed file if the main file is edited by hand.

How do you create a new user account?

useradd command is used for creating a new user account. When invoked without the
-D option, the useradd command creates a new user account using the values specified on the command line and the default values from the system. The new user account will be entered into the system files as needed, and initial files copied, depending on the command line options. This command uses the system default as home directory. If –m option is given then the home directory is made.

Which password package is installed for the security of central password?

Shadow password packages are used for security of central passwords. Security is the most important aspect of every operating system. When this package is not installed the user information including passwords is stored in the /etc/passwd file. The password is stored in an encoded format. These encoded forms can be easily identified by the System crackers by randomly encoding the passwords from dictionaries. The Shadow Package solves the problem by relocating the passwords to another file (usually /etc/shadow). The /etc/shadow file is set so that it cannot be read by just anyone. Only root will be able to read and write to the /etc/shadow file.

Which shell do you assign to a POP3 mail-only account?

POP3 mail only account is assigned to the /bin/false shell. However, assigning bash shell to a POP3 mail only gives user login access, which is avoided. /bin/nologin can also be used. This shell is provided to the user when we don’t want to give shell access to the user. The user cannot access the shell and it reject shell login on the server like on telnet. It is mainly for the security of the shells. POP3 is basically used for downloading mail to mail program. So for illegal downloading of emails on the shell this account is assigned to the /bin/false shell or /bin/nologin. These both shells are same they both do the same work of rejecting the user login to the shell. The main difference between these two shells is that false shell shows the incorrect code and any unusual coding when user login with it. But the nologin shell simply tells that no such account is available. So nologin shell is used mostly in Linux.

Which daemon is responsible for tracking events on Linux system?

syslogd is responsible for tracking system information and save it to the desired log files. It provides two system utilities which provide system logging and kernel message trapping. Internet and UNIX domain sockets support enable this utility package to support both local and remote logging. Every logged message contains at least a time and a hostname field, normally a program name field, too. So to track these information this daemon is used. syslogd mainly reacts to the set of signals given by the user. These are the signals given to syslogd: SIGHUP: This lets syslogd perform a re-initialization. All open files are closed, the configuration file (default is /etc/syslog.conf) will be reread and the syslog facility is started again. SIGTERM: The syslogd will die. SIGINT, SIGQUIT: If debugging is enabled these are ignored, otherwise syslogd will die. SIGUSR1: Switch debugging on/off. This option can only be used if syslogd is started with the - d debug option. SIGCHLD: Wait for Childs if some were born, because of waiting messages.

Which daemon is used for scheduling of the commands?

The crontab command is used for scheduling of the commands to run at a later time. SYNTAX
crontab [ -u user ] file
crontab [ -u user ] { -l | -r | -e }

Options
-l List - display the current crontab entries.

-r Remove the current crontab.

-e Edit the current crontab using the editor specified by the VISUAL or EDITOR environment variables.
When user exits from the editor, the modified crontab will be installed automatically. Each user can have their own crontab, and though these are files in /var, they are not intended to be edited directly. If the –u option is given than the crontab gives the name of the user whose crontab is to be tweaked. If it is given without this then it will display the crontab of the user who is executing the command.

How environment variable is set so that the file permission can be automatically set to the newly created files?

umask command is used to set file permission on newly created files automatically.
Syntax
umask [-p] [-S] [mode]
It is represented in octal numbers. We can simply use this command without arguments to see the current file permissions. To change the permissions, mode is given in the arguments. The default umask used for normal user is 0002. The default umask for the root user is 0022. For calculating the original values, the values shown by the umask must be subtracted by the default values. It is mainly used for masking of the file and directory permission. The /etc/profile script is where the umask command is usually set for all users. The –S option can be used to see the current default permissions displayed in the alpha symbolic format.
For example, umask 022 ensures that new files will have at most 755 permissions (777 NAND 022).
The permissions can be calculated by taking the NAND of original value with the default values of files and directories.     

IMPORTANT LINUX QUESTIONS WITH ANSWERS


SOME IMPORTANT LINUX QUESTIONS WITH ANSWERS

 

What is Linux and why is it so popular?

            Linux is a multiuser, multitask GUI based open source operating system developed by Linus Torvalds Torvalds has invited the community to enhance the Linux kernel and thousands of system programmers worked on to enhance.
           Prior to Linux, there is UNIX. The desktop work stations from various companies were based on UNIX. Later a numerous companies entered and each one of them had their own UNIX version. As the proprietary authority is owned by each company and the lack of central authority weaken UNIX. As Linux is free and runs on any PC platform it gained the popularity very quickly. The following are few more reasons for its popularity:

- People who are familiar with UNIX can work on Linux with ease and comfort.
- People who want great control over network security and on operating system

1. Every command in Linux is a

          Correct answer: executable program

2. How long can a filename in Linux be?

           Correct answer: 255 characters

3. What is the shortcut to the login directory?

         Correct answer: cd + enter key

4. The hierarchy of a series of directories branching in a user system starts from

        Correct answer: /home

5. Saving open files, flush the system cache and other necessary system maintenance are allowed by.

         Correct answer: logging off the system

6. Which directory contains configuration files that stores system and application setting?                 

         Correct answer:   /etc

7. Which command is used to find data files, programs, directories that match the search argument?
                      

         Correct answer:  locate

8. Applications written to provide a GUI shell for Unix and Linux are called

          Correct answer: x windows

9. The advantage of using NFS rather than Samba for file sharing in Linux is

          Correct answer: compatibility with Windows file sharing

10. Which framework is provided for the programs to interchange information about Linux OS?

          Correct answer: Resource Definition Framework

11. To implement new application on IBM z/10. Which of the following options need to be considered if it to be implemented in Linux?

           Correct answer: Red Hat Linux does not support all the devices supported by IBM z/OS

12. Which of the following has greater market share of Linux SW/HW environment?

           Correct answer: Linux on z10

13. Which of the following commands can be run to remove all the rules in an iptables table?    

              Correct answer:   iptables -F

14. Which of the following is the BEST way to set up SSH(Secure Shell) for communicating between Systems without needing passwords?
 

         Correct answer:   Use ssh-keygen for generating public-private keys.

15. How much usable space is available, when a Linux system is configured with a RAID 5 array that consists of six 20 GB hard disk drives?

        Correct answer: 120

16. Which of the following commands can be used to check for file corruption?

        Correct answer: md5sum

17. Which of the following allows to secure remote command line access?

         Correct answer:  SSH(Secure Shell)


18. Which of the following supports for creating a Linux VPN (Virtual Private Network)?

        Correct answer: 3DES

19. Which of the following commands delete the files from the /tmp directory, issued by non-root user?

         Correct answer: su -c "rm -rf /tmp/*"

20. Which configuration does cardmgr read at Linux system startup?

         Correct answer: PCMCIA cards

21. When a computer system is reported problems with inodes and blocks, which of the following is the problem and its solution to rectify it?

         Correct answer: The file system has become corrupt and needs to be repaired.

22. Which Linux command will successfully mounts a USB drive?

          Correct answer: mount /dev/sda1 /mnt/usb

23. ___________ is a common tool for determining services and ports running on a remote Linux.

          Correct answer:   nmap


24. For supporting new diskless client workstations, which of the following services needs to be installed on a server?

           Correct answer: PXE (Preboot eXecution Environment) and tftpd

25. Which of the following will kill the process 1010 by an administrator(logged in as a standard user)? The process 1010 was started by the root user.

             Correct answer: su -c "kill 1010"

26. Which of the following Linux commands could be used to find what processor was detected on boot, when a laptop system is slow/

             Correct answer:  POST

27. How to accomplish the LILO boot configuration updation for supporting a newly installed IDE hard drive?

             Correct answer: Edit lilo.conf and run "lilo -v -v"

Sunday, March 4, 2012

Interview questions in Linux



                                         Interview Questions



1) What is the difference between TCP and UDP?

The basic difference is that TCP establishes a connection before sending data and this allows it to control the dataflow and guarantee that all packets get delivered. UDP simply chucks datagrams onto the wire and if some get lost or arrive in bad order there’s no way to request a resend. However UDP has low network overhead so some services such as DNS resolution, SNMP, DHCP, RIP and VOIP use UDP for its speed and any errors are usually dealt with on the application layer rather than network layer.

2) What is the TCP hand shake?

TCP requires three packets to set up a socket connection, before any user data can be sent. This is called the tree way TCP handshake. First the requester sends a SYN packet and expects a SYN-ACK packet, to which the initiator replies with ACK packet plus the first chunk of user data. From there on the TCP connection is established and two sides exchange user data using features such as message acknowledgment, retransmission and timeout.

3) How does DNS resolution work?

A client application requests an IP address from the name server usually by connecting to UDP port 53. The name server will attempt to resolve the FQDN based on its resolver library, which may contain authoritative information about the host requested or cached data about that name from an earlier query. If the name server does not already have the answer, it will turn to root name servers to determine the authoritative for the FQDN in question. Then, with that information, it will query the authoritative name servers for that name to determine the IP address.


4) What is an MX record?

MX record numerically ranks the mail servers you would prefer to receive email for a domain. The MX record with the lowest number is preferred over the others, but you can set multiple email servers with the same value for simple load balancing.


5) Describe Linux boot-up sequence

BIOS reads the MBR where Boot Loader sits, Boot Loader reads Kernel into memory, Kernel starts Init process, Init reads inittab, executes rc.sysinit, the rc script than starts services to reach the default run level and once this is done the last thing that gets run is the rc.local script.

6) What is an INODE?

All files have its description stored in a structure called ‘inode’. The inode contains info about the file-size, access and modification time, permission and so on. In addition to descriptions about the file, the inode contains pointers to the data blocks of the file.

7) How do you search for a pattern and than replace it in an entire file?

Using Sed or in Vi editor the search usually involves character ‘s’ slash the pattern to be searched, slash the pattern to replace it with, slash ‘g’ which stands for entire file.

8) How do you list and flush all IPtables?

Using the iptables command with –L switch first to see all the rules currently present in memory and than –F to flush them.

9) How do you list compiled-in Apache modules?

Run the httpd daemon as a command with –l parameter.

10) What is a zombie?

Zombie processes can be identified in the output of ‘ps’ by the presence of ‘Z’ in the STAT column. Zombies are child processes whose parent process died without reaping its children. Zombies can’t be killed with the usual KILL signal.

50 Most Frequently Used UNIX / Linux Commands (With Examples)


     This article provides practical examples for 50 most frequently used commands in Linux / UNIX.
This is not a comprehensive list by any means, but this should give you a jumpstart on some of the common Linux commands. Bookmark this article for your future reference.

Did I miss any frequently used Linux commands? Leave a comment and let me know.

1. tar command examples

Create a new tar archive.
$ tar cvf archive_name.tar dirname/
Extract from an existing tar archive.
$ tar xvf archive_name.tar
View an existing tar archive.
$ tar tvf archive_name.tar

 

2. grep command examples

Search for a given string in a file (case in-sensitive search).
$ grep -i "the" demo_file
Print the matched line, along with the 3 lines after it.
$ grep -A 3 -i "example" demo_text
Search for a given string in all files recursively
$ grep -r "ramesh" *

 

3. find command examples

Find files using file-name ( case in-sensitve find)
# find -iname "MyCProgram.c"
Execute commands on files found by the find command
$ find -iname "MyCProgram.c" -exec md5sum {} \;
Find all empty files in home directory
# find ~ -empty

 

4. ssh command examples

Login to remote host
ssh -l jsmith remotehost.example.com
Debug ssh client
ssh -v -l jsmith remotehost.example.com
Display ssh client version
$ ssh -V
OpenSSH_3.9p1, OpenSSL 0.9.7a Feb 19 2003

 

5. sed command examples

When you copy a DOS file to Unix, you could find \r\n in the end of each line. This example converts the DOS file format to Unix file format using sed command.
$sed 's/.$//' filename
Print file content in reverse order
$ sed -n '1!G;h;$p' thegeekstuff.txt
Add line number for all non-empty-lines in a file
$ sed '/./=' thegeekstuff.txt | sed 'N; s/\n/ /'

 

6. awk command examples

Remove duplicate lines using awk
$ awk '!($0 in array) { array[$0]; print }' temp
Print all lines from /etc/passwd that has the same uid and gid
$awk -F ':' '$3==$4' passwd.txt
Print only specific field from a file.
$ awk '{print $2,$5;}' employee.txt

 

7. vim command examples

Go to the 143rd line of file
$ vim +143 filename.txt
Go to the first match of the specified
$ vim +/search-term filename.txt
Open the file in read only mode.
$ vim -R /etc/passwd

 

8. diff command examples

Ignore white space while comparing.
# diff -w name_list.txt name_list_new.txt
 
2c2,3
< John Doe --- > John M Doe
> Jason Bourne

 

9. sort command examples

Sort a file in ascending order
$ sort names.txt
Sort a file in descending order
$ sort -r names.txt
Sort passwd file by 3rd field.
$ sort -t: -k 3n /etc/passwd | more

10. export command examples

To view oracle related environment variables.
$ export | grep ORACLE
declare -x ORACLE_BASE="/u01/app/oracle"
declare -x ORACLE_HOME="/u01/app/oracle/product/10.2.0"
declare -x ORACLE_SID="med"
declare -x ORACLE_TERM="xterm"
To export an environment variable:
$ export ORACLE_HOME=/u01/app/oracle/product/10.2.0

 

11. xargs command examples

Copy all images to external hard-drive
# ls *.jpg | xargs -n1 -i cp {} /external-hard-drive/directory
Search all jpg images in the system and archive it.
# find / -name *.jpg -type f -print | xargs tar -cvzf images.tar.gz
Download all the URLs mentioned in the url-list.txt file
# cat url-list.txt | xargs wget –c

 

12. ls command examples

Display filesize in human readable format (e.g. KB, MB etc.,)
$ ls -lh
-rw-r----- 1 ramesh team-dev 8.9M Jun 12 15:27 arch-linux.txt.gz
Order Files Based on Last Modified Time (In Reverse Order) Using ls -ltr
$ ls -ltr
Visual Classification of Files With Special Characters Using ls -F
$ ls -F

 

 

13. pwd command

pwd is Print working directory. What else can be said about the good old pwd who has been printing the current directory name for ages.

 

14. cd command examples

Use “cd -” to toggle between the last two directories
Use “shopt -s cdspell” to automatically correct mistyped directory names on cd

 

15. gzip command examples

To create a *.gz compressed file:
$ gzip test.txt
To uncompress a *.gz file:
$ gzip -d test.txt.gz
Display compression ratio of the compressed file using gzip -l
$ gzip -l *.gz
         compressed        uncompressed  ratio uncompressed_name
              23709               97975  75.8% asp-patch-rpms.txt

 

16. bzip2 command examples

To create a *.bz2 compressed file:
$ bzip2 test.txt
To uncompress a *.bz2 file:
bzip2 -d test.txt.bz2

 

17. unzip command examples

To extract a *.zip compressed file:
$ unzip test.zip
View the contents of *.zip file (Without unzipping it):
$ unzip -l jasper.zip
Archive:  jasper.zip
  Length     Date   Time    Name
 --------    ----   ----    ----
    40995  11-30-98 23:50   META-INF/MANIFEST.MF
    32169  08-25-98 21:07   classes_
    15964  08-25-98 21:07   classes_names
    10542  08-25-98 21:07   classes_ncomp

 

18. shutdown command examples

Shutdown the system and turn the power off immediately.
# shutdown -h now
Shutdown the system after 10 minutes.
# shutdown -h +10
Reboot the system using shutdown command.
# shutdown -r now
Force the filesystem check during reboot.
# shutdown -Fr now

 

19. ftp command examples

Both ftp and secure ftp (sftp) has similar commands. To connect to a remote server and download multiple files, do the following.
$ ftp IP/hostname
ftp> mget *.html
To view the file names located on the remote server before downloading, mls ftp command as shown below.
ftp> mls *.html -
/ftptest/features.html
/ftptest/index.html
/ftptest/othertools.html
/ftptest/samplereport.html
/ftptest/usage.html

 

20. crontab command examples

View crontab entry for a specific user
# crontab -u john -l
Schedule a cron job every 10 minutes.
*/10 * * * * /home/ramesh/check-disk-space

 

21. service command examples

Service command is used to run the system V init scripts. i.e Instead of calling the scripts located in the /etc/init.d/ directory with their full path, you can use the service command.
Check the status of a service:
# service ssh status
Check the steatus of all the services.
service --status-all
Restart a service.
# service ssh restart

 

22. ps command examples

ps command is used to display information about the processes that are running in the system.
While there are lot of arguments that could be passed to a ps command, following are some of the common ones.
To view current running processes.
$ ps -ef | more
To view current running processes in a tree structure. H option stands for process hierarchy.
$ ps -efH | more

 

23. free command examples

This command is used to display the free, used, swap memory available in the system.
Typical free command output. The output is displayed in bytes.
$ free
             total       used       free     shared    buffers     cached
Mem:       3566408    1580220    1986188          0     203988     902960
-/+ buffers/cache:     473272    3093136
Swap:      4000176          0    4000176
If you want to quickly check how many GB of RAM your system has use the -g option. -b option displays in bytes, -k in kilo bytes, -m in mega bytes.
$ free -g
             total       used       free     shared    buffers     cached
Mem:             3          1          1          0          0          0
-/+ buffers/cache:          0          2
Swap:            3          0          3
If you want to see a total memory ( including the swap), use the -t switch, which will display a total line as shown below.
ramesh@ramesh-laptop:~$ free -t
             total       used       free     shared    buffers     cached
Mem:       3566408    1592148    1974260          0     204260     912556
-/+ buffers/cache:     475332    3091076
Swap:      4000176          0    4000176
Total:     7566584    1592148    5974436

 

24. top command examples

top command displays the top processes in the system ( by default sorted by cpu usage ). To sort top output by any column, Press O (upper-case O) , which will display all the possible columns that you can sort by as shown below.
Current Sort Field:  P  for window 1:Def
Select sort field via field letter, type any other key to return
 
  a: PID        = Process Id              v: nDRT       = Dirty Pages count
  d: UID        = User Id                 y: WCHAN      = Sleeping in Function
  e: USER       = User Name               z: Flags      = Task Flags
  ........
To displays only the processes that belong to a particular user use -u option. The following will show only the top processes that belongs to oracle user.
$ top -u oracle

 

25. df command examples

Displays the file system disk space usage. By default df -k displays output in bytes.
$ df -k
Filesystem           1K-blocks      Used Available Use% Mounted on
/dev/sda1             29530400   3233104  24797232  12% /
/dev/sda2            120367992  50171596  64082060  44% /home
df -h displays output in human readable form. i.e size will be displayed in GB’s.
ramesh@ramesh-laptop:~$ df -h
Filesystem            Size  Used Avail Use% Mounted on
/dev/sda1              29G  3.1G   24G  12% /
/dev/sda2             115G   48G   62G  44% /home
Use -T option to display what type of file system.
ramesh@ramesh-laptop:~$ df -T
Filesystem    Type   1K-blocks      Used Available Use% Mounted on
/dev/sda1     ext4    29530400   3233120  24797216  12% /
/dev/sda2     ext4   120367992  50171596  64082060  44% /home

 

26. kill command examples

Use kill command to terminate a process. First get the process id using ps -ef command, then use kill -9 to kill the running Linux process as shown below. You can also use killall, pkill, xkill to terminate a unix process.
$ ps -ef | grep vim
ramesh    7243  7222  9 22:43 pts/2    00:00:00 vim
 
$ kill -9 7243

 

27. rm command examples

Get confirmation before removing the file.
$ rm -i filename.txt
It is very useful while giving shell metacharacters in the file name argument.
Print the filename and get confirmation before removing the file.
$ rm -i file*
Following example recursively removes all files and directories under the example directory. This also removes the example directory itself.
$ rm -r example

 

28. cp command examples

Copy file1 to file2 preserving the mode, ownership and timestamp.
$ cp -p file1 file2
Copy file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ cp -i file1 file2

 

29. mv command examples

Rename file1 to file2. if file2 exists prompt for confirmation before overwritting it.
$ mv -i file1 file2
Note: mv -f is just the opposite, which will overwrite file2 without prompting.
mv -v will print what is happening during file rename, which is useful while specifying shell metacharacters in the file name argument.
$ mv -v file1 file2

 

30. cat command examples

You can view multiple files at the same time. Following example prints the content of file1 followed by file2 to stdout.
$ cat file1 file2
While displaying the file, following cat -n command will prepend the line number to each line of the output.
$ cat -n /etc/logrotate.conf
    1   /var/log/btmp {
    2       missingok
    3       monthly
    4       create 0660 root utmp
    5       rotate 1
    6   }

 

31. mount command examples

To mount a file system, you should first create a directory and mount it as shown below.
# mkdir /u01
 
# mount /dev/sdb1 /u01
You can also add this to the fstab for automatic mounting. i.e Anytime system is restarted, the filesystem will be mounted.
/dev/sdb1 /u01 ext2 defaults 0 2

 

32. chmod command examples

chmod command is used to change the permissions for a file or directory.
Give full access to user and group (i.e read, write and execute ) on a specific file.
$ chmod ug+rwx file.txt
Revoke all access for the group (i.e read, write and execute ) on a specific file.
$ chmod g-rwx file.txt
Apply the file permissions recursively to all the files in the sub-directories.
$ chmod -R ug+rwx file.txt

33. chown command examples

chown command is used to change the owner and group of a file. \
To change owner to oracle and group to db on a file. i.e Change both owner and group at the same time.
$ chown oracle:dba dbora.sh
Use -R to change the ownership recursively.
$ chown -R oracle:dba /home/oracle

 

34. passwd command examples

Change your password from command line using passwd. This will prompt for the old password followed by the new password.
$ passwd
Super user can use passwd command to reset others password. This will not prompt for current password of the user.
# passwd USERNAME
Remove password for a specific user. Root user can disable password for a specific user. Once the password is disabled, the user can login without entering the password.
# passwd -d USERNAME

 

35. mkdir command examples

Following example creates a directory called temp under your home directory.
$ mkdir ~/temp
Create nested directories using one mkdir command. If any of these directories exist already, it will not display any error. If any of these directories doesn’t exist, it will create them.
$ mkdir -p dir1/dir2/dir3/dir4/

 

36. ifconfig command examples

Use ifconfig command to view or configure a network interface on the Linux system.
View all the interfaces along with status.
$ ifconfig -a
Start or stop a specific interface using up and down command as shown below.
$ ifconfig eth0 up
 
$ ifconfig eth0 down

37. uname command examples

Uname command displays important information about the system such as — Kernel name, Host name, Kernel release number,
Processor type, etc.,
Sample uname output from a Ubuntu laptop is shown below.
$ uname -a
Linux john-laptop 2.6.32-24-generic #41-Ubuntu SMP Thu Aug 19 01:12:52 UTC 2010 i686 GNU/Linux

 

38. whereis command examples

When you want to find out where a specific Unix command exists (for example, where does ls command exists?), you can execute the following command.
$ whereis ls
ls: /bin/ls /usr/share/man/man1/ls.1.gz /usr/share/man/man1p/ls.1p.gz
When you want to search an executable from a path other than the whereis default path, you can use -B option and give path as argument to it. This searches for the executable lsmk in the /tmp directory, and displays it, if it is available.
$ whereis -u -B /tmp -f lsmk
lsmk: /tmp/lsmk

 

39. whatis command examples

Whatis command displays a single line description about a command.
$ whatis ls
ls             (1)  - list directory contents
 
$ whatis ifconfig
ifconfig (8)         - configure a network interface

 

40. locate command examples

Using locate command you can quickly search for the location of a specific file (or group of files). Locate command uses the database created by updatedb.
The example below shows all files in the system that contains the word crontab in it.
$ locate crontab
/etc/anacrontab
/etc/crontab
/usr/bin/crontab
/usr/share/doc/cron/examples/crontab2english.pl.gz
/usr/share/man/man1/crontab.1.gz
/usr/share/man/man5/anacrontab.5.gz
/usr/share/man/man5/crontab.5.gz
/usr/share/vim/vim72/syntax/crontab.vim

 

41. man command examples

Display the man page of a specific command.
$ man crontab
When a man page for a command is located under more than one section, you can view the man page for that command from a specific section as shown below.
$ man SECTION-NUMBER commandname
Following 8 sections are available in the man page.
  1. General commands
  2. System calls
  3. C library functions
  4. Special files (usually devices, those found in /dev) and drivers
  5. File formats and conventions
  6. Games and screensavers
  7. Miscellaneous
  8. System administration commands and daemons
For example, when you do whatis crontab, you’ll notice that crontab has two man pages (section 1 and section 5). To view section 5 of crontab man page, do the following.
$ whatis crontab
crontab (1)          - maintain crontab files for individual users (V3)
crontab (5)          - tables for driving cron
 
$ man 5 crontab

 

42. tail command examples

Print the last 10 lines of a file by default.
$ tail filename.txt
Print N number of lines from the file named filename.txt
$ tail -n N filename.txt
View the content of the file in real time using tail -f. This is useful to view the log files, that keeps growing. The command can be terminated using CTRL-C.
$ tail -f log-file

 

43. less command examples

less is very efficient while viewing huge log files, as it doesn’t need to load the full file while opening.
$ less huge-log-file.log
One you open a file using less command, following two keys are very helpful.
CTRL+F – forward one window
CTRL+B – backward one window

 

44. su command examples

Switch to a different user account using su command. Super user can switch to any other user without entering their password.
$ su - USERNAME
Execute a single command from a different account name. In the following example, john can execute the ls command as raj username. Once the command is executed, it will come back to john’s account.
[john@dev-server]$ su - raj -c 'ls'
 
[john@dev-server]$
Login to a specified user account, and execute the specified shell instead of the default shell.
$ su -s 'SHELLNAME' USERNAME

 

45. mysql command examples

mysql is probably the most widely used open source database on Linux. Even if you don’t run a mysql database on your server, you might end-up using the mysql command ( client ) to connect to a mysql database running on the remote server.
To connect to a remote mysql database. This will prompt for a password.
$ mysql -u root -p -h 192.168.1.2
To connect to a local mysql database.
$ mysql -u root -p
If you want to specify the mysql root password in the command line itself, enter it immediately after -p (without any space).

 

46. yum command examples

To install apache using yum.
$ yum install httpd
To upgrade apache using yum.
$ yum update httpd
To uninstall/remove apache using yum.
$ yum remove httpd

 

47. rpm command examples

To install apache using rpm.
# rpm -ivh httpd-2.2.3-22.0.1.el5.i386.rpm
To upgrade apache using rpm.
# rpm -uvh httpd-2.2.3-22.0.1.el5.i386.rpm
To uninstall/remove apache using rpm.
# rpm -ev httpd

 

 

48. ping command examples

Ping a remote host by sending only 5 packets.
$ ping -c 5 gmail.com

 

49. date command examples

Set the system date:
# date -s "01/31/2010 23:59:53"
Once you’ve changed the system date, you should syncronize the hardware clock with the system date as shown below.
# hwclock –systohc
 
# hwclock --systohc –utc

 

50. wget command examples

The quick and effective method to download software, music, video from internet is using wget command.
$ wget http://prdownloads.sourceforge.net/sourceforge/nagios/nagios-3.2.1.tar.gz
Download and store it with a different name.
$ wget -O taglist.zip http://www.vim.org/scripts/download_script.php?src_id=7701

Bash Shortcuts Quick Reference

Bash Shortcuts Quick Reference

Ctrl-a                 Move  to the start of the line.

 Ctrl-e                Move to the end of the line.

 Ctrl-b                Move back one character.

 Alt-b                 Move back one word.

 Ctrl-f                 Move forward one character.

 Alt-f                  Move forward one word.

 Ctrl-] x              Where x is any character, moves the cursor forward to the next occurance of x.

 Alt-Ctrl-] x       Where x is any character, moves the cursor backwards to the previous occurance of x.

 Ctrl-u                Delete from the cursor to the beginning of the line.

 Ctrl-k                Delete from the cursor to the end of the line.

 Ctrl-w               Delete from the cursor to the start of the word.

 Esc-Del            Delete previous word (may not work, instead try Esc followed by Backspace)

 Ctrl-y                Pastes text from the clipboard.

 Ctrl-l                 Clear the screen leaving the current line at the top of the screen.

 Ctrl-x                Ctrl-u Undo the last changes.(Ctrl-_ does the same )

 Alt-r                  Undo all changes to the line.

 Alt-Ctrl-e          Expand command line.

 Ctrl-r                 Incremental reverse search of history.

 Alt-p                  Non-incremental reverse search of history.

 !!                       Execute last command in history

 !abc                   Execute last command in history beginning with abc

 !abc:p               Print last command in history beginning with abc

 !n                      Execute nth command in history

 !$                      Last argument of last command

 !^                      First argument of last command

 ^abc^xyz          Replace first occurance of abc with xyz in last command and execute it  

Saturday, March 3, 2012

Benefits of Linux Hosting


Benefits of Linux Web Hosting

               Linux web hosting services are the most popular around and are offered by a large number of web hosting providers due to the fact that Linux web hosting packages are fairly cheap to offer and if done correctly can offer large profit margins. Linux is an open source operating system meaning that web hosting providers don’t have to pay a penny to use the operating system and if you choose to go for a Linux VPS server or Linux dedicated server then you will realize that you won’t be required to pay extra for the operating system. As well as being cost effective, Linux web hosting services can also provide you with a greater level of uptime that will allow you to focus on more important business activities without having to worry about the availability of your website or any of the other services that you may be running off your Linux web hosting account. Security is likely to be one of your major concerns but as a user of Linux web hosting you won’t have to worry about viruses infecting the server that your account is hosted on as similarly to Mac OSX on the desktop, Linux servers are immune to Windows based viruses and the number of Linux-specific viruses around is fairly low.
          Affordability is one of the major attractions to Linux web hosting for most web hosting customers. Those who have the most basic requirements aren’t going to be wanting to spend any large amounts of money on web hosting services meaning that they are going to be searching for the cheapest web hosting package available. Due to the fact that Linux is an open source operating system, it allows most web hosting providers to be competitive with their offerings of low cost web hosting services. Even though Linux web hosting services may be cheap, you will always be offered feature rich web hosting services that have support for PHP based websites as well as the facility to host at least one MySQL database.
             Uptime (sometimes referred to as reliability) is one of the biggest benefits of using Linux web hosting as Linux web hosting servers are generally more reliable than Windows web hosting servers. Some of the reasons for this increased level of reliability include:
  • Software updates and patches – with a Windows server the chances are that you are going to be required to restart the hosting server every time you install a new application or application update and all of these restarts can collectively add up to a large amount of downtime – the difference with Linux servers is that you probably won’t be required to restart your server every time you install a new application or update to an existing application, although you may be required to for larger updates that affect how the operating system itself interacts with the hardware and/or the software that you are running
  • Better use of server resources – Linux as an operating system is generally more conservative of the system resources that it has available to use meaning that there are going to be more spare resources available for the applications that you use the most to use – a larger amount of free system resources will also mean that if there does happen to be a load spike at any time, there are still the resources there to be able to cope with this spike whilst maintaining the server and a low load constantly to help ensure stability overall
  • Better control of web hosting accounts – reliability is also something that can be affected by the number of web hosting accounts that are hosted on a single server – the software available for Linux servers such as the cPanel control panel can provide web hosting providers with a much better way of managing individual web hosting accounts to make sure that a single web hosting account isn’t able to overload the entire server using a single, badly coded PHP script or website.
           The reliability available to you is likely to influence how visitors respond to your website as a website that is constantly down isn’t going to get a second visit in the eyes of most internet users. However, if you are able to offer a content rich website that is always available then you will be able to build up a good base of returning visitors.
          Regardless of whether you are going to be using your website to handle sensitive information of any type, you should still be concerned about the level of security that your web hosting provider will be able to offer you. The main security features of a Linux web hosting package are likely to include:
  • CSF firewall – this is one of the most widely used firewall applications for Linux servers for the simple fact that it is open source and therefore free to use, but at the same time it is also effective in fulfilling its primary purpose as a firewall – most web hosting companies use CSF to block the IP addresses of any servers or computers that try to hack into them, thus meaning that this firewall application plays a large role in keeping your Linux web hosting account and the data stored in your web space safe
  • Mod_security – this is an additional module to the Apache web server and can be highly effective in the prevention of web based attacks through compromised PHP scripts and MySQL databases – any web hosting company offering Linux web hosting is going to be using mod_security to a good extent to help keep their servers safe from any SQL injections or other forms of web based attack that could take place – in order for mod_security to be effective, a large rule set needs to be used
  • Your own scripts – if you are going to be hosting a dynamic website that you have scripted yourself on your Linux web hosting account then you may wish to double check your coding for any possible loopholes prior to publishing it in an active hosting environment – when developing a website quickly it can be very easy to use coding methods that are either outdated or insecure when compared to other methods that are available and for the most part it is important for you to be using code that can’t be compromised by potential hackers.
            Security is something that you won’t have to worry about with a Linux web hosting service, although in order to receive the highest levels of security possible you should consider using a highly reputable web hosting provider that has a good track record with security.