Monday, May 12, 2014

How to Recover MYSQL Root Password

How to Recover MYSQL Root Password

Here, i will explain how can we recover mysql root password when we forget or else. I will explain to recover it by using simple steps as follows.
[root@linuxpathfinder ~]# mysql -u root -p
Enter password:
ERROR 1045 (28000): Access denied for user ‘root’@’localhost’ (using password: YES)
:: First of all use any one of the following command to stop the mysql service.
# service mysqld stop
(or)
# /etc/rc.d/init.d/mysqld stop
[root@linuxpathfinder ~]# service mysqld stop
Stopping mysqld:                                           [  OK  ]
:: After that start mysql service as following method.
[root@linuxpathfinder ~]# mysqld_safe –skip-grant-tables &
[1] 1564
[root@linuxpathfinder ~]# 121023 12:54:57 mysqld_safe Logging to ‘/var/log/mysqld.log’.
121023 12:54:58 mysqld_safe Starting mysqld daemon with databases from /var/lib/mysql
mysqld_safe method is mostly used and recommended way to start a mysqld server on Unix/Linux.
:: Now login without password into mysql root user
[root@linuxpathfinder ~]# mysql -u root
Welcome to the MySQL monitor.  Commands end with ; or \g.
Your MySQL connection id is 1
Server version: 5.1.69 Source distribution
Copyright (c) 2000, 2013, Oracle and/or its affiliates. All rights reserved.
Oracle is a registered trademark of Oracle Corporation and/or its
affiliates. Other names may be trademarks of their respective
owners.
Type ‘help;’ or ‘\h’ for help. Type ‘\c’ to clear the current input statement.
mysql>
:: Now its time to update your password
mysql> use mysql;
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql>
mysql> UPDATE user SET password=PASSWORD(“newrootpassword”) WHERE User=’root’;
Query OK, 2 rows affected (0.00 sec)
Rows matched: 2  Changed: 2  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit;
:: Now require restart service (stop and start) of mysql server.
[root@linuxpathfinder ~]# /etc/rc.d/init.d/mysqld stop
131023 13:11:39 mysqld_safe mysqld from pid file /var/run/mysqld/mysqld.pid ended
Stopping mysqld:                                           [  OK  ]
[1]+  Done                    mysqld_safe –skip-grant-tables
[root@linuxpathfinder ~]# /etc/rc.d/init.d/mysqld start
Starting mysqld:                                           [  OK  ]
:: Access your mysql database with your recently created new password.
mysql -u root -p
Now above method to change mysql root password process has been completed. Please let me know if you follow any different way to recover lost mysql password.

Install LAMP Server On RHEL 6, CentOS 6 and Fedora 18

Install LAMP Server On RHEL 6, CentOS 6 and Fedora 18

LAMP stands for (Linux, Apache, MySQL, PHP/Perl/Python) OS and open-source software stack. In this tutorial, we will discuss the LAMP installation on RHEL6.x, CentOS6.x and Fedora18 (x stands for versions).
My server hostname and IP address are server.linuxpathfinder.local and 192.168.1.111/24, respectively.

Install Apache HTTP Server:


The Apache HTTP Server is a web server application notable for playing a key role in the initial growth of the World Wide Web. It provides a full range of web server features including CGI (Common Gateway Interface) defines a way for a web server to interact with external content-generating programs, SSL (Secure Sockets Layer) is an encryption mechanism over HTTP which allows you to send sensitive or confidential information over the internet to a client and vice versa and virtual domains which refers to the practice of running more than one web site on a single machine.
To start the installation of Apache server, write on terminal as shown below:
# yum install httpd -y
After complete installation, start the Apache service and define to start automatically on every reboot:
# service httpd start
# chkconfig httpd on
In firewall/router file we need to allow Apache server default port 80 to connect from remote systems. The firewall file location, edit file /etc/sysconfig/iptables,
# vim /etc/sysconfig/iptables
Add the following lines.
[....]
-A INPUT -m state –state NEW -m tcp -p tcp –dport 80 -j ACCEPT
[....]
After changes restart iptables service:
# service iptables restart
# netstat -tulpn | grep :80
tcp        0      0 :::80    :::*    LISTEN    2438/httpd
Now Test Apache:
To verify web server open your web browser and navigate to http://localhost/ or http://server-ip-address/.
apache-installation-01

Install MySQL Server:


MySQL is a free Relational Database Management System (RDBMS) that uses Structured Query Language (SQL), world’s second most used database. MySQL is a mostly used for web applications, and is a main component of mostly used LAMP open-source web application.
Enter the following command to install MySQL server:
# yum install mysql mysql-server -y
After complete installation, start the MySQL service and define to start automatically on every reboot:
# service mysqld start
# chkconfig mysqld on
MySQL root password setup:
Mysql root user doesn’t has password initially. So, we have to setup mysql root user password to secure mysql.
# mysql_secure_installation
NOTE: RUNNING ALL PARTS OF THIS SCRIPT IS RECOMMENDED FOR ALL MySQL
SERVERS IN PRODUCTION USE!  PLEASE READ EACH STEP CAREFULLY!
In order to log into MySQL to secure it, we’ll need the current
password for the root user.  If you’ve just installed MySQL, and
you haven’t set the root password yet, the password will be blank,
so you should just press enter here.
Enter current password for root (enter for none):
OK, successfully used password, moving on…
Setting the root password ensures that nobody can log into the MySQL
root user without the proper authorisation.
Set root password? [Y/n] y
New password:                            ## Enter new password ##
Re-enter new password:            ## Re-enter new password ##
Password updated successfully!
Reloading privilege tables..
… Success!
By default, a MySQL installation has an anonymous user, allowing anyone
to log into MySQL without having to have a user account created for
them.  This is intended only for testing, and to make the installation
go a bit smoother.  You should remove them before moving into a
production environment.
Remove anonymous users? [Y/n] y
… Success!
Normally, root should only be allowed to connect from ‘localhost’.  This
ensures that someone cannot guess at the root password from the network.
Disallow root login remotely? [Y/n] y
… Success!
By default, MySQL comes with a database named ‘test’ that anyone can
access.  This is also intended only for testing, and should be removed
before moving into a production environment.
Remove test database and access to it? [Y/n] y
– Dropping test database…
… Success!
– Removing privileges on test database…
… Success!
Reloading the privilege tables will ensure that all changes made so far
will take effect immediately.
Reload privilege tables now? [Y/n] y
… Success!
Cleaning up…
All done!  If you’ve completed all of the above steps, your MySQL
installation should now be secure.
Thanks for using MySQL!

PHP Installation:


PHP (Hypertext Preprocessor), an open source, server-side, HTML embedded scripting language used to create dynamic Web pages.
Install PHP with following command:
# yum install php -y
Now Test PHP
Create a sample “infophp.php” file in Apache document root folder and append following lines:
# vi /var/www/html/infophp.php
Add the following lines.

phpinfo();
?>
Restart httpd service:
# service httpd restart
Navigate to  http://server-ip-address/infophp.php to see all details about php like (version, build date commands etc.)
If need MySQL support in PHP, must install “php-mysql” package. And if we need to install all php modules just we’ll use “yum install php*” command.
# yum install php-mysql -y
Open the infophp.php file in browser using http://domain-name/infophp.php or http://ip-address/infophp.php. Installed mysql module will be available there.
php-installation-01

phpMyAdmin Installation:


phpMyAdmin is used to manage your installed MySQL database (RDBMS). phpMyAdmin is a free open-source web interface tool. For phpMyAdmin installation we need to install EPEL repository coz of phpMyAdmin is not available in CentOS official repositories.
How to install EPEL repository:
# wget http://epel.mirror.net.in/epel/6/i386/epel-release-6-8.noarch.rpm
# rpm -Uvh epel-release-6-8.noarch.rpm
Sample Output:
Preparing…       ########################################### [100%]
package epel-release-6-8.noarch is already installed
Now install phpMyAdmin
# yum install phpmyadmin -y
phpMyAdmin Configuration:
Edit the phpmyadmin.conf file.
# vim /etc/httpd/conf.d/phpMyAdmin.conf
Find and comment the whole / section as shown below:
[...]
Alias /phpMyAdmin /usr/share/phpMyAdmin
Alias /phpmyadmin /usr/share/phpMyAdmin
#
#  
#     # Apache 2.4
#    
#       Require ip 127.0.0.1
#       Require ip ::1
#    

#  
#  
#     # Apache 2.2
#     Order Deny,Allow
#     Deny from All
#     Allow from 127.0.0.1
#     Allow from ::1
#  
#
[...]
Open  “config.inc.php” file and change from “cookie” to “http” to change the authentication in phpMyAdmin:
# cp /usr/share/phpMyAdmin/config.sample.inc.php /usr/share/phpMyAdmin/config.inc.php
# vim /usr/share/phpMyAdmin/config.inc.php
Change cookie to http.
[...]
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = ‘cookie’;
to
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = ‘http’;
[...]
Restart the Apache service:
# service httpd restart
Now access phpmyadmin console by navigating to http://server-ip/phpmyadmin/ from your browser.
In username and password prompt, you have to put your MySQL username and password. In my case its “root” and “passw0rd”.
phpmyadmin-installation-01
Now you can manage MariaDB database from phpMyAdmin web interface.
Enjoy! Your LAMP server is up and ready to use.

How To Enable Root User (Super User) in Ubuntu

How To Enable Root User (Super User) in Ubuntu

Question: how to able to do su – on Ubuntu. It says “su: Authentication failure”. How fix it, and possible to login to Ubuntu using root account directly?
Answer: Let us address these two questions one by one.
Warning: It is not recommended to enabled root. It is suggested that user should always try to perform all administrative tasks using ‘sudo’.

How to able to login using ‘su’ command

In Ubuntu, root account password is locked by default. So, when you want to do “su -”, you’ll get following Authentication failure error message.
 asifark@linuxpathfinder:~$ su -
 Password:
 su: Authentication failure
To enable super user account password
As following first of all set a password for root user.
 asifark@linuxpathfinder:~$ sudo passwd root
 [sudo] password for asifark:
 Enter new UNIX password:
 Retype new UNIX password:
 passwd: password updated successfully
You can login now as super user with su command with the new password.
 asifark@linuxpathfinder:~$ su -
 Password:
 root@linuxpathfinder:~#
How can we disable super user account password on Ubuntu
After that if you don’t want to use ‘su’ anymore, you can follow using one of the method to lock the root user password.
 asifark@linuxpathfinder:~$ sudo passwd -l root
 passwd: password expiry information changed.
( or )
 asifark@linuxpathfinder:~$ sudo usermod -p '!' root

How can we login directly using root account on Ubuntu?

First of all you will allow the root user to be logged in from the (X GUI) as explained below with the screenshot.
Go to System -> Administration -> Login window.
In the Security tab, click on “Allow local system administrator” near check box as you are seeing in the screenshot. Now you can login directly using root account after reboot the system.
enable-root-user-01

How to Show Date and Time in the Terminal

How to Show Date and Time in the Terminal

Introduction

In this tutorial we will talk about how to show date and time in the terminal. By default, the “prompt” or terminal displays the user name with which we are connected, the machine name and the path where it is located. As follows:
data-time-terminal-02
So we see here that the prompt is “ @ : ”.
Note: When the user is in his home, the path is replaced by a tild (“~”).
In this tutorial we will see how to change the appearance of the prompt to display the time, date, or other characters.

Procedure

We must first understand that the form display prompt is specific to each user defined in the environment variable “PS1″ initialized to start a session. We can check the value of the environment variable “PS1″ with the following command:
[root@localhost usr]# echo $PS1
Then we have the following result:
data-time-terminal-03
We can therefore understand that:
“\U” = user
“@”: The symbol at sign
“\H” = the name of the machine
“\W”: the current path
“$” Sign dollars
Knowing this, we can freely change the appearance of our prompt. This requires that the time and date can be placed with the characters “\ t” for the time (“time”) and (“date”) “\ d” for the date. We can change the value of “PS1″ to add these characters with the following command:
[root@localhost usr]# PS1=’\d\t\u@\h:\W$’
We will immediately after a prompt like this:
data-time-terminal-04
You can of course change the display order of elements at will.

Make the Change Permanent

Since we have only changed the environment variable, this change will only be temporary. Indeed, restart another session, the environment variable will be reset. For the change to be permanent for the user must add our line to change the PS1 variable in the initialization of bash file with the following command:
[root@localhost usr]# echo “PS1=’\d\t\u@\h:\W$’” >> ~/.bashrc
Then restart a session for verification. To make this change permanent same for all users, you must make the same change on the common bash initialization file for all users:
[root@localhost usr]# echo “PS1=’\d\t\u@\h:\W$’” >> /etc/bash.bashrc
Hope, this tutorial will informative for you. Enjoy!

Saturday, May 10, 2014

Howto: Setup ownCloud 6 on Redhat 6, CentOS 6 and Fedora 18

Howto: Setup ownCloud 6 on Redhat 6, CentOS 6 and Fedora 18

Owncloud provides services similar to dropbox. Many of the other websites similar to dropbox that provide file storage, syncing, and sharing functions. The benefit of owncloud is to taking control of our own data and the file storage space. The owncloud has lots of options, feature, configuration and plugins to consider. We will discuss basic functionality and configurations in this article.

Prerequisites:
ownCloud is PHP and database combination based, any flavor of the database. So need to be install Apache web server, PHP and MySQL server on CentOS 6 and Fedora 18. For demo purpose i installed both SQLite and MySQL on CentOS,
[root@linuxpathfinder ~]# yum install httpd php php-mysql mysql-server mysql sqlite php-dom php-mbstring php-gd php-pdo
You need to disable SELinux
[root@linuxpathfinder ~]# vim /etc/selinux/config
SELINUX=disabled

Download and Setup:
Download ownCloud from official website or enter the following command on terminal.
# wget http://download.owncloud.org/community/owncloud-6.0.0.tar.bz2
Extract the archive.
# tar -jxvf owncloud-5.0.5.tar.bz2
Move ownCloud under Apache server document root.
# mv owncloud /var/www/cloud
Allow the web server to read and write the files on cloud directory.
# chown -R apache.apache /var/www/cloud/

Create Database: (Optional)
MySQL server must be started before creating the database, login to MySQL server.
mysql -u root -p
Create database called “clouddb”
create database clouddb;
Allow “clouddbuser” to access the “clouddb” database on localhost with predefined password.
grant all on clouddb.* to ‘clouddbuser’@’localhost’ identified by ‘password’;

Configure Apache server:
While configuring Apache web server, it is recommended that you to enable .htaccess to get a enhanced security features, by default .htaccess is disabled in Apache server. To enable it, open your virtual host file and make AllowOverride is set to All.For example, here i used external config file instead of modifying main file.
vi /etc/httpd/conf.d/cloud.conf
Add the following.

Alias /cloud /var/www/cloud/


Options Indexes FollowSymLinks
AllowOverride All
Order allow,deny
allow from all
Remember to restart all services related to Apache server.

Configure ownCloud:
Open up web browser, point a URL to http://127.0.0.1/cloud ( http://Your-custom-domain). Browser will automatically take you to ownCloud setup page where it must be configured before going to live. Enter admin user name, password, data folder location and database details. You can choose any one of the database from SQLite or MySQL. If you choose SQLite database, you do not require to enter database details.
install-owncloud-01
where as MySQL database requires database user, password and data base name.
install-owncloud-2
Now you can start upload a file via browser, alternately you can download ownCloud client to upload the files.
install-owncloud-03
Enjoy !

Install SVN (Subversion) Server on CentOS

Install SVN (Subversion) Server on CentOS

Subversion is a free open source version control system. It is used by developers to maintain current and historical versions of files such as source code, web pages, and documentation etc. Subversion is used to manage and recover files/directories and the changes of them made all time.
Before start SVN setup, need to update yum repositories and packages as shown below:
[root@linuxpathfinder /]# yum update
Before installing SVN packages, you must install and configure apache Webserver. My server IP address is 192.168.227.128

Install and Configure Apache (httpd)


To install apache along with dependencies, type following command.
[root@linuxpathfinder /]# yum install httpd
After that, open apache configuration file /etc/httpd/conf/httpd.conf
Find “#ServerName www.example.com:80″
#ServerName www.example.com:80
and add this line below. “ServerName server-ip-address:80″
#ServerName www.example.com:80
ServerName 192.168.227.128
Start the apache (httpd) service.
[root@linuxpathfinder /]# service httpd start
to start apache service automatically while booting, type below command in CLI.
[root@linuxpathfinder /]# chkconfig –levels 235 httpd on
Now open your server ip address in the browser.
install-subversion-01
If apache web page is unable to open, disable the firewall (iptables) and selinux service on your server .
Iptables
[root@linuxpathfinder /]# service iptables stop
[root@linuxpathfinder /]# chkconfig iptables off
Selinux
open the file /etc/selinux/config and find the line
SELINUX=enforcing
and replace with
SELINUX=disabled
web page is able to open after reboot the server.

Install and Configure SVN Server


Type following command to start installing svn packages.
[root@linuxpathfinder /]# yum install subversion mod_dav_svn
Configure Subversion
Open the subversion config file ‘/etc/httpd/conf.d/subversion.conf’ and edit as follows.
LoadModule dav_svn_module     modules/mod_dav_svn.so
LoadModule authz_svn_module   modules/mod_authz_svn.so
##Add the following lines ##

DAV svn
SVNParentPath /var/www/svn
AuthType Basic
AuthName “Subversion repositories”
AuthUserFile /etc/svn-auth-users
Require valid-user

#
# Example configuration to enable HTTP access for a directory
# containing Subversion repositories, “/var/www/svn”.  Each repository
# must be both:
#
#   a) readable and writable by the ‘apache’ user, and
#
#   b) labelled with the ‘httpd_sys_content_t’ context if using
#   SELinux
# Add SVN (Subversion) users
Use following command:
## Create ark1 ##
htpasswd -cm /etc/svn-auth-users ark1
New password:
Re-type new password:
Adding password for user ark1
## Create ark2 ##
htpasswd -m /etc/svn-auth-users ark2
New password:
Re-type new password:
Adding password for user ark2
Note: Use exactly same file and path name (/etc/svn-auth-users) as used on subversion.conf file.

Create and Configure SVN Repository


[root@linuxpathfinder /]# mkdir /var/www/svn
[root@linuxpathfinder /]# cd /var/www/svn
Create a new repository and give permissions in the svn by issuing the below commands.
[root@linuxpathfinder svn]# svnadmin create newrepo
[root@linuxpathfinder svn]# chown -R apache.apache newrepo
Restart Apache:
# Fedora #
systemctl restart httpd.service
#OR#
service httpd restart
#CentOS / RHEL#
/etc/init.d/httpd restart
#OR#
service httpd restart
Goto http://192.168.227.128/svn/newrepo address and you should see something as shown below, write username and password:
install-subversion-02
SVN testrepo revision 0:
install-subversion-03
Configure repository
To disable anonymous access and enable access control add following rows to newrepo/conf/svnserve.conf file:
## Disable anonymous access ##
anon-access = none
## Enable access control ##
authz-db = authz

Create trunk, branches and tags structure


Create “template” directories with following command:
[root@linuxpathfinder /]# mkdir -p /tmp/subversion-template/{trunk,branches,tags}
Then import template to project repository using “svn import” command:
[root@linuxpathfinder /]# svn import -m ‘Initial import’ /tmp/subversion-template/ http://192.168.227.128/svn/newrepo/
Authentication realm: Subversion repositories
Password for ‘root’:
Authentication realm: Subversion repositories
Username: ark1
Password for ‘ark1′:
Adding         /tmp/subversion-template/trunk
Adding         /tmp/subversion-template/branches
Adding         /tmp/subversion-template/tags
———————————————————————–
ATTENTION!  Your password for authentication realm:
Subversion repositories
can only be stored to disk unencrypted!  You are advised to configure
your system so that Subversion can store passwords encrypted, if
possible.  See the documentation for details.
You can avoid future appearances of this warning by setting the value
of the ‘store-plaintext-passwords’ option to either ‘yes’ or ‘no’ in
‘/root/.subversion/servers’.
———————————————————————–
Store password unencrypted (yes/no)? yes
Committed revision 1.
Check results on browser and see testrepo revision 1:
install-subversion-04
Now your newly created directory structure will be listed under your main repository. Hope this tutorial helpful for you.

Install Subversion (Using uberSVN) on Centos 6

Install Subversion (Using uberSVN) on Centos 6

Subversion is a free open source version control system. It is used by developers to maintain current and previous all versions of files & directories such as source code, web pages and documentation etc. Subversion is used to manage and recover files/directories and the changes of them made all time.
uberSVN is a free open source application. uberSVN is introduced more development teams to the benefits of using Subversion for source control, configure Web interface for Subversion with built-in Apache Subversion versioning system. This is beneficial and much easier for users and programmers. A tutorial to installing Subversion on Linux CentOS 6 using easy-to-use uberSVN which manages Subversion using a nifty web interface.

Go to CLI and download the latest uberSVN 13.2 installer as shown below:

[root@linuxpathfinder ~]# wget http://download.ubersvn.com/uberSVN-64-1302.sh

Set executable permission using the chmod command to run this setup.

[root@linuxpathfinder ~]# chmod +x uberSVN-64-1302.sh

Now run the installer to download files to your current directory with following step.

[root@linuxpathfinder ~]# ./uberSVN-64-1302.sh

It will start by extracting number of files with lots of dots.

Uncompressing uberSVN-64-1302 Linux 64bit Installer……………………………………………….

Installer warns that installation for new deployments of uberSVN. Enter “Y for next step“.

IMPORTANT: This installer is for new deployments of uberSVN and should not be used for updating 
existing installations!

Do you wish to continue with the installation? [Y/n] y

Next, where uberSVN has to installed. Press Enter.

Where should uberSVN be installed? Note that installing to /root or a home directory (eg /home/name) may cause permission issues and is not recommended.

Enter installation location (/opt/ubersvn):

Confirm your installation location. Enter “Y”.

Are you sure you want to install to: /opt/ubersvn/ubersvn? [Y/n] y

What port you want to use for uberSVN by default run on the port 1024.

Apache Subversion may be installed with the ability to run on a privileged port number below 1024. See http://www.ubersvn.com/below1024 for security considerations.

Allow Apache Subversion to run on a port below 1024? [y/N]y

Next step to ask to start uberSVN on boot. Enter “Y“.

Linux distribution was detected as Redhat

Do you want uberSVN to start on boot? (y/n) (y)

In next and final step URL will prompt, go to browser and put the below URL.

Your uberSVN installation is nearly ready. Visit the following URL to complete configuration:
http://yourip:9890/ubersvn

Configuring uberSVN Interface


First uberSVN setup screen is now showing. In this first screen, it shows Installation Directory, Repo Storage Location and uberSVN key.
ubersvn-01
Your Admin User‘s account is required. Your full name, email, username and password. Go ahead for next step.
ubersvn-02
This step is to setup Portal and Apache to control users access to uberSVN & repositories. Put your machine IP address, uberSVN port and Apache port.
ubersvn-03
Next step is for email settings, select options as your requirement. Click the next button to continue.
ubersvn-04
It will take some time for new setup. Once completed then Start button as following.
ubersvn-05

uberSVN Interface


You are in login prompt. Now enter your admin username and password to access ubersvn.
ubersvn-06

Create Repositories and Add Users


In Subversion panel, simply you can create new repositories and setting up for users.
ubersvn-07

Subversion Start/Stop Service


Login to CLI and go to uberSVN’s binary directory.
[root@linuxpathfinder ~]# /opt/ubersvn/bin
Run the subversion start & stop script as shown below.
[root@linuxpathfinder bin]# ./ubersvncontrol start/stop &

Thats it! Now adding users and adding teams for more details and setting up new repositories.