Monday, 12 May 2014

How to Recover Mysql root password

Recover Mysql root password


One of the very worst scenarios for a system administrator is when they forget a password for the root account. That is the same case when a Database admin does the same for the root account for Mysql Database. So to help here, these are the following steps which one can perform to recover the root password back for Mysql database.

Stop Mysql Server:
$ sudo /etc/init.d/mysql stop

Then, start the mysql server with skip-grant-tables options. –skip-grant-tables option will force the mysql process not to read the user table into memory, so that when you try to login to the Mysql server, it won’t ask for the password.
$ sudo mysqld_safe --skip-grant-tables  &

Now connect to mysql server using mysql client without giving any password
$ mysql -u root -p

Now setup the new password for the root user:
mysql> use mysql;
mysql> update user set password=PASSWORD("NEWPASSWORD") where user="root";
 mysql> flush privileges;
 mysql> Ctrl+D [to exit]

Now stop the mysql server
$ sudo /etc/init.d/mysql stop
Now start the mysql server normally, so that it could read the password information.
$ sudo /etc/init.d/mysql start

Disable Ctrl Alt Delete in Ubuntu

Disable Ctrl+Alt+Delete
First and foremost, anyone that has physical access to the keyboard can simply use the
Ctrl+Alt+Delete key combination to reboot the server without having to log on. Sure, someone could
simply unplug the power source, but you should still prevent the use of this key combination on a
production server.
This forces an attacker to take more drastic measures to reboot the server, and will
prevent accidental reboots at the same time.

• To disable the reboot action taken by pressing the Ctrl+Alt+Delete key combination, comment out
the following line in the file /etc/init/control-alt-delete.conf.

#exec shutdown -r now "Control-Alt-Delete pressed"

#sudo vi /etc/init/control-alt-delete.conf
# control-alt-delete - emergency keypress handling
#
# This task is run whenever the Control-Alt-Delete key combination is
# pressed, and performs a safe reboot of the machine.
description     "emergency keypress handling"
author          "Scott James Remnant <scott@netsplit.com>"
start on control-alt-delete
task
#exec shutdown -r now "Control-Alt-Delete pressed"

Sunday, 11 May 2014

Package manager dpkg in Debian-based systems

dpkg is a package manager for Debian-based systems. It can install, remove, and build packages, but
unlike other package management systems, it cannot automatically download and install packages or
their dependencies. This section covers using dpkg to manage locally installed packages:

• To list all packages installed on the system, from a terminal prompt type:
dpkg -l

• Depending on the amount of packages on your system, this can generate a large amount of output.
Pipe the output through grep to see if a specific package is installed:

dpkg -l | grep apache2

Replace apache2 with any package name, part of a package name, or other regular expression.

• To list the files installed by a package, in this case the ufw package, enter:
dpkg -L ufw

• If you are not sure which package installed a file, dpkg -S may be able to tell you. For example:
 You can install a local .deb file by entering:

sudo dpkg -i zip_3.0-1_i386.deb

Change zip_3.0-4_i386.deb to the actual file name of the local .deb file you wish to install.

• Uninstalling a package can be accomplished by:

sudo dpkg -r zip

Uninstalling packages using dpkg, in most cases, is NOT recommended. It is better to use
a package manager that handles dependencies to ensure that the system is in a consistent
state. For example using
 dpkg -r zip
 will remove the zip package, but any packages that
depend on it will still be installed and may no longer function correctly.

For more dpkg options see the man page: man dpkg.

Saturday, 10 May 2014

How to Chanage Jboss Admin Password

By default jboss admin password will be same as user name admin. 
but we need to  secure the JBOSS server in a production environment, and You can change it by editing file-

 Jboss/server/default/conf/props/jmx-console-users.properties


Simply change the password and save: 

# A sample users.properties file for use with the UsersRolesLoginModule
admin=Your Password

Wednesday, 5 March 2014

How to Release Cache Memory In Linux


To check uses of Cache Memory

free -m

rahul@rahul-laptop:~# free -m
             total       used       free     shared    buffers     cached
Mem:           992        898         94          0         14        460
-/+ buffers/cache:        604        388
Swap:         1011        132        879

To Release/ Free  Cache Memory 

rahul@rahul-laptop:~# sync, echo 3 > /proc/sys/vm/drop_caches 

Above command will free used cache memory
 to verify run again free -m

     OR 

rahul@rahul-laptop:~# sync && echo 1 > /proc/sys/vm/drop_caches

Wednesday, 5 February 2014

The Runlevels in Linux



Definition for runlevel : A runlevel is a software configuration of the system which allows only a selected group of processes to exist. The processes spawned by init command/process for each of these runlevels are defined in the /etc/inittab file.
Runlevels control services started by the initialization process. The number of runlevels and services started on those runlevels varies with Linux distributions.
Print print current runlevel using who command:
$ who -r  
Or
$ runlevel

Different linux/unix disterbution’s runlevels


Redhat Linux:

Red Hat as well as most of its derivatives uses runlevels like this.  

# 0 – Halt (Do not set initdefault to this option.)
# 1 – Single User Mode
# 2 – Multi-user, without NFS (The same as 3, if you do not have networking)
# 3 – Full Multi-user Mode
# 4 – Unused
# 5 – X11
# 6 – Reboot (Do not set initdefault to this option.)
  

Debian Linux :
Debian, as well as most of the distributions based on it, like Ubuntu, does not make any distinction between runlevels 2 to 5. See also the Debian FAQ on booting.
0 – Halt
1 – Single
2 – Full multi-user with display manager (GUI)
3 – Full multi-user with display manager (GUI)
4 – Full multi-user with display manager (GUI)
5 – Full multi-user with display manager (GUI)
6 – Reboot


SUSE Linux:
SUSE uses a similar setup as Red Hat :
0 – Halt
1 – Single
2 – Full multi-user with no networking
3 – Full multi-user NO display manager
4 – Not used/User definable
5 – Full multi-user with display manager (GUI)
6 – Reboot


Solaris
0 – operating system halted; (SPARC only) drop to OpenBoot prompt
S – single-user with only root filesystem mounted (as read-only)
1 – single-user mode with all local filesystems mounted (read-write)
2 – multi-user with most daemons started.
3 – multi-user, identical to 2 (runlevel 3 runs both /sbin/rc2 and /sbin/rc3), with filesystems exported, plus some other network services started.
4 – alternative multi-user, user defined
5 – shut down, power-off if hardware supports it
6 – reboot