Monday, July 5, 2010

Resetting windows password using linux livecd

The application that we are going to use is chntpw. In this example, we will be using ubuntu livecd.

1. Put the livecd in the cd/dvd drive and boot your windows machine from the livecd.

2. Once booted, open the terminal and check for tool named "chntpw". If not there, you can install it using:

$ sudo apt-get install chntpw

3. After the tool is ready, mount the windows partition. Use "fdisk -lu" to check which partition should be mounted. To mount /dev/sda1 (assuming your windows partition is on /dev/sda1), use below command:
$ sudo mount /dev/sda1 /mnt

4. Find SAM file on the windows partition. Usually it is located in Windows/System32/config. Run the chntpw on the SAM file.
$ cd /mnt/Windows/System32/config
List all user in the SAM record
$ chntpw -l SAM
Interactively edit user credential
$ chntpw -i SAM

5. Follow the wizard of chntpw and clear administrator or any user's password that you want to access.

6. Save changes and restart machine. You can access the windows without password for administrator and users that you have cleared their password. Make sure you take out the livecd, otherwise the machine will boot into it instead of windows.

Friday, June 11, 2010

Checking hardisk information on linux

To check hardisk information such as model and serial number, there are a few useful commands like hdparm, sdparm and fdisk.

To check the information about first hardisk for PATA and SATA hardisk:

# hdparm -i /dev/sda

For SCSI disk, a different command is to be used:
# sdparm /dev/sda

To check the hardisk capacity and partitions contained in the hardisk, fdisk can be used:
# fdisk -lu /dev/sda

If your hardisk is smart compatible, you can refer here on how to install and use smart to find information and monitor the health of your hardisk.

Tuesday, June 8, 2010

Getting netbios name in linux

If you are using linux and administering a network full of windows machine, there is a tool called nbtscan to easily scan through the network and list all machines with their netbios name.

To install nbtscan in fedora:

# yum install nbtscan

To use it on single machine(let's say the machine's ip is 10.0.0.100):
# nbtscan 10.0.0.100

To scan the whole class C and list netbios names:
# nbtscan 10.0.0.0/24

To scan ip range:
# nbtscan 10.0.0.10-100

To get all options to use nbtscan:
# nbtscan -h

Tuesday, May 11, 2010

Backup and restore mysql databases

To backup(dump) single mysql database to a file:

mysqldump -u foo -p foodb > foodb.sql

where -u is for username, -p is for mysqldump to ask for password, foodb is the name of the database and foodb.sql is the file to dump the database.


To backup(dump) all databases to a file:

mysqldump -u foo -p --all-databases > alldb.sql

where -u is for username, -p is for mysqldump to ask for password, --all-databases is to tell mysqldump to dump all databases available and alldb.sql is the dumpfile name.


To restore back mysql database from dumpfile:


1. From terminal

mysql -u foo -p foodb < foodb.sql

-u and -p are similar to above, foodb is the name of the database and foodb.sql is the name of the dumpfile.


2. From inside mysql console where you have to access mysql console first:

mysql> source foodb.sql
or
mysql> \. foodb.sql

where foodb.sql is the dumpfile

Wednesday, April 21, 2010

Allowing full access to apache subdirectory

Usually, people will set basic authentication for apache directory (normally /var/www/html in centos). The reason is to protect the directory from unauthorized access. But what if a subdirectory inside (let say /var/www/html/mydirectory) needs full access? This is where .htaccess file comes into picture. To allow access to /var/www/html/mydirectory while maintaining authentication for /var/www/html, just follow below steps:


1. Go to /var/www/html/mydirectory
# cd /var/www/html/mydirectory

2. Create .htaccess file
# touch .htaccess

3. Put below items into that .htaccess file
Allow from all
Satisfy Any

4. You can try access http://servername/mydirectory using your browser. If still cannot access without password, try restart your apache
# httpd -k graceful

That's all :)