Wednesday, February 3, 2010

How to Recover MySQL Root Password

Do you want to recover the MySQL root password. its by no means, easy. But its quite simple if you follow the procedure. You will have to follow this step-by-step processes.

 
Here are the commands you need to type for each step (log in as the root user):
Step 1 : Stop the MySQL service:

# /etc/init.d/mysql stop

Output:

    Stopping MySQL database server: mysqld.

Step 2: Start the MySQL server w/o password:

# mysqld_safe --skip-grant-tables &

Output:

    [1] 5988
    Starting mysqld daemon with databases from /var/lib/mysql
    mysqld_safe[6025]: started

Step 3: Connect to the MySQL server using the MySQL client:

# mysql -u root

Output:

    Welcome to the MySQL monitor.  Commands end with ; or \g.
    Your MySQL connection id is 1 to server version: 4.1.15-Debian_1-log

    Type 'help;' or '\h' for help. Type '\c' to clear the buffer.

    mysql>

Step 4: Set a new MySQL root user password:

mysql> use mysql;
mysql> update user set password=PASSWORD("NEW-ROOT-PASSWORD") where User='root';
mysql> flush privileges;
mysql> quit
Step 5: Stop the MySQL server:

# /etc/init.d/mysql stop

Output:

    Stopping MySQL database server: mysqld
    STOPPING server from pid file /var/run/mysqld/mysqld.pid
    mysqld_safe[6186]: ended

    [1]+  Done                    mysqld_safe –skip-grant-tables

Now Start the MySQL server and test it:

# /etc/init.d/mysql start
# mysql -u root -p

Tuesday, February 2, 2010

How to Setup LDAP

Step-by-step OpenLDAP Installation and Configuration

This tutorial describes how to install and configure an OpenLDAP
server and also an OpenLDAP client.
Step by Step Installation and Configuration OpenLDAP Server

Software:  OS-Cent OS 4.4, openldap 2.2.13-6.4E
System name:   ldap.adminmart.com
Domain name:   adminmart.com
System IP:     192.168.1.212

Note: Use your domain name and IP instead of adminmart.

Easy steps for adding users:
   1. Create unix user
   2. Create unix user's ldap passwd file
   3. Convert passwd.file to ldif file
   4. Add ldap file to LDAP Directory using ldapadd
Step #1. Requirements

   compat-openldap.i386 0:2.1.30-6.4E
   openldap-clients.i386 0:2.2.13-6.4E
   openldap-devel.i386 0:2.2.13-6.4E
   openldap-servers.i386 0:2.2.13-6.4E
   openldap-servers-sql.i386 0:2.2.13-6.4E

You can install them using the command:

yum install *openldap* -y


Step #2. Start the service

[root@ldap ~]# chkconfig --levels 235 ldap on
[root@ldap ~]# service ldap start
Remove ads

Step #3. Create LDAP root user password

[root@ldap ~]# slappasswd
   New password:
   Re-enter new password:
   {SSHA}cWB1VzxDXZLf6F4pwvyNvApBQ8G/DltW
[root@ldap ~]#
Step #4. Update /etc/openldap/slapd.conf for the root password

[root@ldap ~]# vi /etc/openldap/slapd.conf

   #68 database        bdb
   #69 suffix          "dc=adminmart,dc=com"
   #70 rootdn          "cn=Manager,dc=adminmart,dc=com"
   #71 rootpw          {SSHA}cWB1VzxDXZLf6F4pwvyNvApBQ8G/DltW

Step #5. Apply Changes

[root@ldap ~]# service ldap restart
Step #6. Create test users

[root@ldap ~]# useradd test1
[root@ldap ~]# passwd test1
   Changing password for user test1.
   New UNIX password:
   Retype new UNIX password:
   passwd: all authentication tokens updated successfully.
[root@ldap ~]# useradd test2
[root@ldap ~]# passwd test2
   Changing password for user test2.
   New UNIX password:
   Retype new UNIX password:
   passwd: all authentication tokens updated successfully.
[root@ldap ~]#

Note: Repeat the same for the rest of users
Step #7. Migrate local users to LDAP

[root@ldap ~]# grep root /etc/passwd > /etc/openldap/passwd.root
[root@ldap ~]# grep test1 /etc/passwd > /etc/openldap/passwd.test1
[root@ldap ~]# grep test2 /etc/passwd > /etc/openldap/passwd.test2

 Note: Repeat the same for the rest of users
Step #8. Update default settings on file
/usr/share/openldap/migration/migrate_common.ph

   #71 $DEFAULT_MAIL_DOMAIN = "adminmart.com";
   #74 $DEFAULT_BASE = "dc=adminmart,dc=com";

Step #9. Convert passwd.file to ldif (LDAP Data Interchange Format) file

[root@ldap ~]# /usr/share/openldap/migration/migrate_passwd.pl
/etc/openldap/passwd.root /etc/openldap/root.ldif
[root@ldap ~]# /usr/share/openldap/migration/migrate_passwd.pl
/etc/openldap/passwd.test1 /etc/openldap/test1.ldif
[root@ldap ~]# /usr/share/openldap/migration/migrate_passwd.pl
/etc/openldap/passwd.test2 /etc/openldap/test2.ldif

Note: Repeat the same for the rest of users
Step #10. Update root.ldif file for the "Manager" of LDAP Server

[root@ldap ~]# vi /etc/openldap/root.ldif

   #1 dn: uid=root,ou=People,dc=adminmart,dc=com
   #2 uid: root
   #3 cn: Manager
   #4 objectClass: account

Step #11. Create a domain ldif file (/etc/openldap/adminmart.com.ldif)

[root@ldap ~]# cat /etc/openldap/adminmart.com.ldif

   dn: dc=adminmart,dc=com
   dc: adminmart
   description: LDAP Admin
   objectClass: dcObject
   objectClass: organizationalUnit
   ou: rootobject
   dn: ou=People, dc=adminmart,dc=com
   ou: People
   description: Users of adminmart
   objectClass: organizationalUnit

Step #12. Import all users in to the LDAP

Add the Domain ldif file

[root@ldap ~]# ldapadd -x -D "cn=Manager,dc=adminmart,dc=com" -W -f
/etc/openldap/adminmart.com.ldif
   Enter LDAP Password:
   adding new entry "dc=adminmart,dc=com"
   adding new entry "ou=People, dc=adminmart,dc=com"
[root@ldap ~]#

Add the users:

[root@ldap ~]# ldapadd -x -D "cn=Manager,dc=adminmart,dc=com" -W -f
/etc/openldap/root.ldif
   Enter LDAP Password:
   adding new entry "uid=root,ou=People,dc=adminmart,dc=com"
   adding new entry "uid=operator,ou=People,dc=adminmart,dc=com"
[root@ldap ~]#

[root@ldap ~]# ldapadd -x -D "cn=Manager,dc=adminmart,dc=com" -W -f
/etc/openldap/test1.ldif
   Enter LDAP Password:
   adding new entry "uid=test1,ou=People,dc=adminmart,dc=com"
[root@ldap ~]#

[root@ldap ~]# ldapadd -x -D "cn=Manager,dc=adminmart,dc=com" -W -f
/etc/openldap/test2.ldif
   Enter LDAP Password:
   adding new entry "uid=test2,ou=People,dc=adminmart,dc=com"
 [root@ldap ~]#

 Note: Repeat the same for the rest of users
Step #13. Apply Changes

[root@ldap ~]# service ldap restart
Step #14. Test LDAP Server

It prints all the user information:

[root@ldap ~]# ldapsearch -x -b 'dc=adminmart,dc=com' '(objectclass=*)'






Client Configuration
#authconfig-tui
#enable ldap


Thanks
Bilal.M.K