How to Add Date & Time with History in Linux

Introduction

The command history allows the use of words from previous command lines at the command prompt type. This simplifies spelling corrections and the repetition of complicated commands or arguments.

History Command

# history
  850  useradd admin
  851  passwd admin
  852  cd /home/admin/
  853  ls -l
  854  ls -la
  855  top

Edit the file /etc/bashrc add the entry at the end of the file /etc/bashrc

# vi /etc/bashrc
export HISTTIMEFORMAT="%h/%d - %H:%M:%S "

OR
You can also directly execute the following command:

# export HISTTIMEFORMAT="%h/%d - %H:%M:%S "

Now again check the “history” command:

# history
  850  31/08/15 07:22:21 useradd admin
  851  31/08/15 07:22:21 passwd admin
  852  31/08/15 07:22:21 cd /home/admin/
  853  31/08/15 07:22:21 ls -l
  854  31/08/15 07:22:21 ls -la
  855  31/08/15 07:22:21 top

Teams – Red Hat and Fedora Welcome Ubuntu to GNOME and Wayland with Open Arms

Canonical’s Mark Shuttleworth revealed nothing about Ubuntu’s development team that worked with the GNOME Devs, but until more details were revealed, it looks like the Red Hat Desktop and Fedora teams have taken the first step in welcoming Ubuntu and Canonical to the GNOME- And Wayland projects, hoping that they will have a fruitful long-term cooperation for the coming years.

“As most of you probably know that Mark Shuttleworth just announced that they would switch back to GNOME 3 and Wayland for Ubuntu, so I would like to welcome them on behalf of the Red Hat desktop and Fedora teams and say that We are looking forward to working to work with large canonical and Ubuntu people like Allison Lortie and Robert Ancell on projects of common interest around GNOME, Wayland and hopefully Flatpak, “said Christian Schaller in his recent blog post.

We do not know about Flatpak because Canonical will not give up its Snappy technologies, which seem to be very popular with the IoT (Internet of Things) manufacturers, but support for the next generation Wayland display server could be implemented Ubuntu 18.04 LTS operating system along with the GNOME shell interface. We can not wait to see how things stand out. Ubuntu as a GNU / Linux distribution will also be very popular without Unity.

How to Install PHP in nginx

Prerequisites

Install nginx web server

Step 1: Install PHP & PHP-FPM

Install packages php & php-fpm package on server using epel repository.

# yum --enablerepo=epel -y install php php-mbstring php-pear php-fpm

Step 2: Configure PHP-FPM

Modify user and group name in php-fpm configuration file.

# vi /etc/php-fpm.d/www.conf

user = nginx
group = nginx

Step 3: Start Service

Start php-fpm service.

# /etc/rc.d/init.d/php-fpm start

Starting php-fpm: [ OK ]
# chkconfig php-fpm on

Step 4: Configure default.conf file

Modify default.conf file.

# vi /etc/nginx/conf.d/default.conf
    # add follows in a "server" section

    location ~ \.php$ {
        fastcgi_pass   127.0.0.1:9000;
        fastcgi_index  index.php;
        fastcgi_param  SCRIPT_FILENAME  $document_root$fastcgi_script_name;
        include        /etc/nginx/fastcgi_params;
    }

Step 5: Restart Service

Restart nginx server to execute the latest configurations.

# /etc/rc.d/init.d/nginx restart

Stopping nginx: [ OK ]
Starting nginx: [ OK ]

Step 6: Create a PHP Page

Create a PHP test page and save the file.

# echo "" > /usr/share/nginx/html/info.php

Open Your favorite browser and hit the URL: http://Your-IP-Address/info.php
phpinfo

How to reset root password in Linux

Introduction

If you forgot your root password, then it’s not a big deal. Below are the methods to reset root password in different linux distributions.

Step 1: Power on Redat/CentOS 7 Server

First power on your Redhat/CentOS 7 server. At the boot menu, select the Kernel you want to boot up and press e to edit the selected boot entry.

Password1

Find the line rhgb quiet :

password2

and replace it with init=/bin/bash

Password3

 

Then press CTRL+X to enter into single user mode.

Step 2: Mount / partition

# mount -o remount,rw /

Step 3: Change root password

# passwd root

Step 4: Create File

# touch /.autorelabel

Step 5: Execute Command

# exec /sbin/init

How to Configure MySQL Master-Master Replication

Step 1: Install MySQL Server

Install MySQL Server on both machines.

# apt-get update
# apt-get install mysql-server mysql-client

Step 2: Configure MySQL Servers

Edit the /etc/mysql/my.cnf file on both machines. Add or modify the following values:

Server 1:

# vi /etc/mysql/my.cnf
        server_id           = 1
        log_bin             = /var/log/mysql/mysql-bin.log
        log_bin_index       = /var/log/mysql/mysql-bin.log.index
        relay_log           = /var/log/mysql/mysql-relay-bin
        relay_log_index     = /var/log/mysql/mysql-relay-bin.index
        expire_logs_days    = 10
        max_binlog_size     = 100M
        log_slave_updates   = 1
        auto-increment-increment = 2
        auto-increment-offset = 1

Server 2:

# vi /etc/mysql/my.cnf
        server_id           = 2
        log_bin             = /var/log/mysql/mysql-bin.log
        log_bin_index       = /var/log/mysql/mysql-bin.log.index
        relay_log           = /var/log/mysql/mysql-relay-bin
        relay_log_index     = /var/log/mysql/mysql-relay-bin.index
        expire_logs_days    = 10
        max_binlog_size     = 100M
        log_slave_updates   = 1
        auto-increment-increment = 2
        auto-increment-offset = 2

Step 3: Modify my.cnf file with bind-address

Edit or add bind-address in my.cnf

# vi /etc/mysql/my.cnf    	
        bind-address    = x.x.x.x

Step 4: Restart MySQL Server

After inserting the above entries restart mysql server.

# service mysqld restart

Step 5: Create Replication Users

Connect with mysql server as root

# mysql -u root -p

Configure the replication users on each Linode. Replace x.x.x.x with the private IP address of the opposing Linode, and password with a strong password:

mysql> GRANT REPLICATION SLAVE ON *.* TO 'replication'@'x.x.x.x' IDENTIFIED BY 'password';

Run the following command to test the configuration. Use the private IP address of the opposing Linode:

 mysql -ureplication -p -h x.x.x.x -P 3306

Step 6: Configure Database Replication

Server 1:

While logged into MySQL on Server 1, query the master status:

mysql> SHOW MASTER STATUS;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 |      120 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

Server 2:

On Server 2 at the MySQL prompt, set up the slave functionality for that database. Replace x.x.x.x with the private IP from the first server. Also replace the value for master_log_file with the file value from the previous step, and the value for master_log_pos with the position value.

mysql> SLAVE STOP;
mysql> CHANGE MASTER TO master_host='x.x.x.x', master_port=3306, master_user='replication', master_password='password', master_log_file='mysql-bin.000001', master_log_pos=106;
mysql> SLAVE START;

Step 7: Configure Database Replication Vice Versa

Server 2:

On Server 2, query the master status. Again note the file and position values.

mysql> SHOW MASTER STATUS;
    +------------------+----------+--------------+------------------+
    | File             | Position | Binlog_Do_DB | Binlog_Ignore_DB |
    +------------------+----------+--------------+------------------+
    | mysql-bin.000001 |      160 |              |                  |
    +------------------+----------+--------------+------------------+
    1 row in set (0.00 sec)

Server 1:

Set the slave database status on Server 1, replacing the same values swapped in step 2 with those from the Server 2.

mysql> SLAVE STOP;
mysql> CHANGE MASTER TO master_host='x.x.x.x', master_port=3306, master_user='replication', master_password='password', master_log_file='mysql-bin.000001', master_log_pos=160;
mysql> SLAVE START;

Step 8: Create Database

Test by creating a database and inserting a row:

Server 1:

mysql> create database test;
mysql> create table test.books (`id` varchar(10));

Server 2:

mysql> show tables in test;

MySQL Commands

How to create repository in Redhat 7 Linux

Introduction

Repository is database of application installation and up-gradation of packages which are available on different Linux distributions. The packages of distros are available on official websites or you can extract them from official CD/DVD. We can easily install, upgrade or delete packages from repository.

Step 1: Mount ISO from DVD or Folder

In order to create repository, first mount ISO image from Official DVD or download it from given websites.

# cd /root
# mount -o loop RHEL-7.0 Server.x86_64-dvd.iso /mnt/	(For Redhat 7)
# mount -r -t iso9660 -o loop -v rhel-server-6.4-x86_64-dvd.iso /mnt	(For Redhat 6)

Step 2: Create Repository

To create repository follow the following steps.

# cd /etc/yum.repos.d/
# vi rhel7.repo
[rhel7]
name=Redhat
baseurl=file:///mnt/
enabled=1
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-redhat-release

Step 3: Install Packages

Install Packages using yum command.

# yum clean all
# yum install ftp httpd gcc

SQL Server Commands

How to Configure Postfix, Dovecot, Virtual Domains, Virtual Users in CentOS

Step 1: Install Postfix

Install postfix using yum command:

# yum install postfix

Step 2: Run Postfix on Multi-Levels

Make sure run the postfix on multilevels:

# chkconfig postfix on

Step 3: Modify /etc/postfix/main.cf File

Make a copy of both these files main.cf & master.cf:

# cd /etc/postfix
# cp main.cf main.cf.bk
# cp master.cf master.cf.bk

Edit main.cf and change the following values:

# vi /etc/postfix/main.cf
myhostname = www.tecdistro.com
mydomain = tecdistro.com
myorigin = $mydomain
inet_interfaces = all
home_mailbox = Maildir/

Step 4: Create Postfix User

Create postfix user “userpostfix” on server with login shell as /sbin/nologin

# useradd -s /sbin/nologin userpostfix

Check the UID:GUID for the userpostfix user in /etc/passwd file

# tail /etc/passwd
userpostfix:x:1001:1001::/home/userpostfix:/sbin/nologin

Step 5: Configure Virtual domain

Add the following lines at the end of main.cf and replace the UID:GUID under virtual_minimum_uid, virtual_maximum_uid, virtual_uid_maps and virtual_gid_maps

# vi /etc/postfix/main.cf
virtual_mailbox_domains = /etc/postfix/virtual_domains
virtual_mailbox_base = /var/mail/vhosts
virtual_mailbox_maps = hash:/etc/postfix/vmailbox
virtual_minimum_uid = 1001
virtual_maximum_uid = 1001
virtual_uid_maps = static:1001
virtual_gid_maps = static:1001
virtual_alias_maps = hash:/etc/postfix/virtual

Create /etc/postfix/virtual_domains. It contains all the domains that are pointed on server.

# vi /etc/postfix/virtual_domains
tecdistro1.com
tecdistro2.net
tecdistro3.org

Step 6: Create Mail Directories

Create the mail directory, sub directory for the domains and assign the proper permissions.

# mkdir /var/mail/vhosts
# chgrp -R userpostfix /var/mail
# cd /var/mail/vhosts
# mkdir tecdistro1.com
# mkdir tecdistro2.net
# mkdir tecdistro3.org
# cd ..
# chown -R userpostfix:userpostfix vhosts

Note: Postfix will create the “Maildir” directories automatically and assign the proper permissions.

Step 7: Create /etc/postfix/vmailbox File

Create a file /etc/postfix/vmailbox and add all of the users that will receive e-mails.

# touch /etc/postfix/vmailbox
# vi /etc/postfix/vmailbox
@tecdistro1.com          tecdistro1.com/catch-all/
user1@tecdistro1.com        tecdistro1.com/user1/
user2@tecdistro1.com       tecdistro1.com/user2/
user1@tecdistro2.net        tecdistro2.net/user1/
user1@tecdistro3.org        tecdistro3.org/user1/

Note: Make sure you end up each line with “/”.
Postfix will automatically create Maildir structure (cur, new, tmp).

Step 7: Execute postmap Command

Create the hashed file (.db) using postmap command.

	
# postmap /etc/postfix/virtual
# postmap /etc/postfix/vmailbox

Step 8: Check postfix Status

Make sure postfix service is running fine and port 25 is opened for postfix.

# ps -eaf | grep postfix
postfix   1219  1590  0 12:05 ?        00:00:00 pickup -l -t fifo -u
root      1353 30585  0 12:06 pts/0    00:00:00 grep postfix
root      1590     1  0 Mar05 ?        00:01:03 /usr/libexec/postfix/master
postfix  23181  1590  0 Apr13 ?        00:00:07 qmgr -l -t fifo -u
# netstat -an | grep :25
tcp        0      0 0.0.0.0:25                  0.0.0.0:*                   LISTEN
tcp        0      0 :::25                       :::*                        LISTEN
tcp        0      0 ::ffff:159.8.18.154:80      ::ffff:157.55.39.57:25485   TIME_WAIT

Step 9: Reload postfix

Now reload the postfix service:

# service postfix reload

Step 10: Test Postfix

Test the mail using telnet command:

# telnet localhost smtp
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
220 server.tecdistro.com ESMTP Postfix
ehlo localhost
250-server.tecdistro.com
250-PIPELINING
250-SIZE 10240000
250-VRFY
250-ETRN
250-ENHANCEDSTATUSCODES
250-8BITMIME
250 DSN
mail from:support@tecdistro.com
250 2.1.0 Ok
rcpt to:sales@tecdistro.com
250 2.1.5 Ok
data
354 End data with .
Test Mail
.
250 2.0.0 Ok: queued as E7E1F5A1F6
quit
221 2.0.0 Bye
Connection closed by foreign host.

How to Configure Dovecot

Dovecot is an open-source POP and IMAP client.

Step 1: Install Dovecot

Install dovecot using yum command:

# yum install dovecot

Step 2: Configure Dovecot on Multi-Levels

To Configure dovecot on multilevels:

# chkconfig dovecot on

Step 3: Configure Dovecot Files

Then, go to conf.d folder and change the following lines in the following files.

# cd /etc/dovecot/
# vi dovecot.conf
protocols = imap pop3
# cd /etc/dovecot/conf.d/
# vi 10-auth.conf
disable_plaintext_auth = no
#!include auth-system.conf.ext
!include auth-passwdfile.conf.ext
# vi 10-logging.conf
log_path = /var/log/dovecot.log
auth_verbose = no
auth_debug = no
verbose_ssl = no
# vi 10-mail.conf
mail_location = maildir:/var/mail/vhosts/%d/%n
mail_uid = 1001
mail_gid = 1001
mail_privileged_group = userpostfix
# vi 10-master.conf
unix_listener auth-userdb {
  mode = 0600
  user = postfix
  group =  postfix
}
# Postfix smtp-auth
unix_listener /var/spool/postfix/private/auth {
  mode = 0666
  user = postfix
  group = postfix
}

Step 4: Reload Dovecot

Now reload the dovecot service:

 # service dovecot reload

Step 5: Test Dovecot

# telnet localhost pop3
Trying 127.0.0.1...
Connected to localhost.
Escape character is '^]'.
+OK Dovecot ready.
user sales@tecdistro.com
+OK
pass Test123
+OK Logged in.
list
+OK 1 messages:
1 3845
.
retr 1
+OK 3845 octets
Return-Path: <support@tecdistro.com>
X-Original-To: user1
Delivered-To: support@tecdistro.com
Received: from localhost (localhost [IPv6:::1])
by server.tecdistro.com (Postfix) with ESMTP id 117113FF18
for ; Thu, 7 Feb 2013 17:05:32 +0530 (IST)
Message-Id: <20130207113547.117113FF18@server.tecdistro.com>
Date: Thu, 7 Feb 2013 17:05:32 +0530 (IST)
From: support@tecdistro.com
To: undisclosed-recipients:;

.
test
quit
+OK Logging out.
Connection closed by foreign host.

How to Configure Squirrelmail

Step 1: Prerequisites

Step 2: Install Squirrelmail

Install EPEL repository and install SquirrelMail package from EPEL repository.

# wget http://dl.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -ivh epel-release-6-8.noarch.rpm 
# yum install squirrelmail
# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]

Step 3: Configure Squirrelmail

Configure conf.pl according to the server as following:

# cd /usr/share/squirrelmail/config/
# ./conf.pl 
SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Main Menu --
1.  Organization Preferences
2.  Server Settings
3.  Folder Defaults
4.  General Options
5.  Themes
6.  Address Books
7.  Message of the Day (MOTD)
8.  Plugins
9.  Database
10. Languages
D.  Set pre-defined settings for specific IMAP servers
C   Turn color off
S   Save data
Q   Quit
Command >>2

SquirrelMail Configuration : Read: config.php (1.4.0)
---------------------------------------------------------
Server Settings
General
-------
1.  Domain                 : tecdistro.com
2.  Invert Time            : false
3.  Sendmail or SMTP       : SMTP
A.  Update IMAP Settings   : localhost:143 (uw)
B.  Update SMTP Settings   : localhost:25
R   Return to Main Menu
C   Turn color off
S   Save data
Q   Quit
Command >> S

Press S to save datas and press Q to exit.

Step 4: Configure Squirrelmail with httpd.conf

Add the following lines in the httpd.conf file at the end.

# vi /etc/httpd/conf/httpd.conf
Alias /squirrelmail /usr/share/squirrelmail
<Directory /usr/share/squirrelmail>
    Options Indexes FollowSymLinks
    RewriteEngine On
    AllowOverride All
    DirectoryIndex index.php
    Order allow,deny
    Allow from all
</Directory>

Restart the httpd service.

# service httpd restart
Stopping httpd:                                            [  OK  ]
Starting httpd:                                            [  OK  ]