Posts tagged linux

Setup plugins directory in Linux (debian) for Firefox

I had issues with Firefox not finding the plugins for flash. I had to setup the following environment variable for it to find it:

Check if it is already set:

echo $MOZ_PLUGIN_PATH

If it is not, set it:

export MOZ_PLUGIN_PATH=/home/user/.mozilla/plugins

Any path will work, I just used the .mozilla directory to keep things clean.

You should restart Firefox to see the plugins.

 

This was tested on Debian Wheezy.

Recover MySQL root password on Linux and Windows

It happens that sometimes (after 2 days ūüôā ) you forget the password for your root user on MySQL, well there are few steps to perform to recover it.

This was performed on version:

$ mysql -V
mysql  Ver 14.14 Distrib 5.1.61, for debian-linux-gnu (x86_64) using readline 6.2

The following steps need to be performed as root user, so either login with it or use sudo.

Step 1:Stop the MySQL service

$ sudo /etc/init.d/mysql stop

Step 2: Start the MySQL server without password

$ sudo mysqld_safe --skip-grant-tables &

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

$ sudo mysql -u root

Step 4: Change the password for the root user

mysql> use mysql;
Database changed
mysql> update user set password=PASSWORD("YOUR_NEW_PASS") where user = 'root';
Query OK, 3 rows affected (0.01 sec)
Rows matched: 3  Changed: 3  Warnings: 0
mysql> flush privileges;
Query OK, 0 rows affected (0.00 sec)
mysql> quit
Bye

Step 5: Stop the MySQL server again

$ sudo /etc/init.d/mysql stop

Step 6: Start the MySQL server (normally) and test the new password

$ sudo /etc/init.d/mysql start
$ sudo mysql -u root -p

 

This should also work on Windows as well, you will just need to use different commands for start/stop of the MySQL deamon.

 

 

Surveillance system with Motion

There is a time when you are leaving your home empty and you don’t have an expensive security and alarm system. You need to be protected and be aware if there are any changes or visits that you do not approve of while you are gone. There is an easy way to achieve just that with Motion. What you need is:

  1. Linux OS (ex. Ubuntu)
  2. Motion (free)
  3. Webcam
  4. Internet (optional)
  5. Hosting (optional)
  6. Smartphone with data plan (optional)

After you have your computer ready, webcam installed and working, go and download the Motion project or use Ubuntu’s apt to get it (check to get the latest version):

sudo apt-get install motion

Run the program (Motion) with root privileges, like sudo motion, however please note that you should probably run it with sleep or cron, otherwise it will activate immediately and most probably detect you while you are exiting the room.

Now you are all set for the basic surveillance with just a webcam which will record when there is a movement in front of the camera, however there are some more advanced options which could help a lot.

Email you when there is movement detected

For this you will need to install sendmail and mutt, assuming you are on Ubuntu

sudo apt-get install sendmail mutt

The basic settings for sendmail are enough for most users, but if you are an advanced user feel free to modify it as you desire.

Open the file /etc/motion/motion.conf in your favorite text editor (ex. vim), then locate the text on_even_start value and change the value part with:

echo "This is the body of the message" | mutt -s "Motion has been detected" your@mail.com

If there is a ; (semi-colon) on the beginning of the row, remove it, also if there is any empty space before the on_event_start.

Sending images to a webserver

It would be good to have the images taken from the motion to a webserver so that you can check from a remote location what is there on the images and report to the police if needed.
Open the /etc/motion/motion.conf file again in a text editor and locate the text on_picture_save value and change the value part with:

scp %f user@yourdomain.com:/path/for/images/

If there is a ; (semi-colon) on the beginning of the row, remove it, also if there is any empty space before the on_picture_save.

Enable login without password on your webserver

You need to create a ssh key on your machine with the following

sudo ssh-keygen -t dsa

Upload the key to your webserver:

sudo ssh-copy-id -i /root/.ssh/id_dsa.pub user@yourdomain.com

Tips and tricks: if you have a LED light on your camera, put a plastic electrician tape (isolation tape) on it so that the camera is not noticeable. Also, make sure you have some light in the room, unless the camera has a feature for night vision.

Execute process in Linux/UNIX to run in the background by using NOHUP

If you need to execute a process that will run in the background so that it does not lock one terminal window then you should try using the NOHUP command.

Example usage:

nohup <command here> &

After executing it, a nohup.out file will be created (append if it exists) which will contain all the output from the command (if any).

However, if you want to close the terminal window, like if you are working on a remote machine, do the following:

(nohup <command here> & ) &

This will disconnect the process from your session completely so you should be able to close the terminal window and do not interrupt the process.

To check if the process is still running, perform the following:

ps -ef|grep -i <command name or part of command name>

This is listing all the processes on the machine and then grepping for the command name with case insensitive (-i).

If you want to stop the process, you will need to kill it with the following command:

kill <process id>

The process-id can be seen from running the ps command above. In most instances it is the first number of the row.

If the process hangs after the kill command, do force kill:

kill -9 <process id>

This will kill any process, so please double check the process id before executing it.

Safely erase a hard disk drive with shred

I have an older tiny HDD of 80GB and I am planning to give it to a friend or donate it to the local hacklab, but before it goes out of the house I want to make sure that nobody (at least with the technology available to most individuals) can restore what was on the disk. There was nothing very important or secretive on it, but people snooping around my files creeps me out a bit.

There are many ways to completely erase a hard disk drive, a partition or individual files with the GNU/Linux utility called shred.

The command to use is very simple:

sudo shred -n <NUMBER OF ITERATIONS> -vz /dev/to/hddOrPartition

And to shred a file:

shred -n <NUMBER OF ITERATIONS> -v file1 file2 file3 etc

It should be executed as super user/root so that there will be full access to erase/write everything. I use about 20 iterations (default is 25), because that seems like enough to me. The -z option means to run an extra run at the end which will zero the drive which will hide the shredding (in -n is 20, there will be total of 21 passes). -v is verbose, to show progress of the task.

WARNING: please be VERY careful about the disk/partition that you select because EVERYTHING on it will be deleted. Create backup before the command is executed!

 

Enable global keys (hot-keys) in Ubuntu on Asus K53

On Asus K53 most of the hot-keys are not working with the default installation of Ubuntu 11.04 with kernel 2.6.38-8, however there is a package available that will enable them, here are instructions on how to perform that:

sudo apt-get install git  (unless you already have git installed)
git clone git://git.iksaif.net/acpi4asus-dkms.git
cd acpi4asus-dkms 
make 
sudo make install
sudo modprobe asus-nb-wmi   (this command will load the newly installed module)

After every kernel update the above will be erased and you will need to re-do it every time until it is included in a kernel version at a later stage. To make it easier create a .deb package which will be easier to install.

sudo apt-get install debhelper 
cd acpi4asus-dkms 
dpkg-buildpackage
sudo dpkg -i [newly-created-package].deb
sudo modprobe asus-nb-wmi

Change Network Card MAC in Ubuntu/Linux

A Media Access Control address (MAC address) is a unique identifier assigned to network interfaces for communications on the physical network segment. Read more about MAC addresses here.

Tip: Please write down your current MAC address before you continue

To change the MAC address in Ubuntu, perform the following:

Temporary solution

  1. Open terminal and check your current MAC address:
    ifconfig |grep HWaddr  

    Output should be something like this (MAC’s are red):
    eth0           Link encap:Ethernet  HWaddr f4:6d:0b:37:f9:83
    vboxnet0  Link encap:Ethernet  HWaddr 0b:00:23:00:00:00
    wlan0       Link encap:Ethernet  HWaddr e0:c9:d5:1a:ed:b5

  2. Now, disable the network interface (eth0 for the wired network connection, wlan0 for wireless etc.):
    sudo ifconfig eth0 down
     

     

  3. Change the MAC address:
    sudo ifconfig eth0 hw ether 00:15:a5:d5:39:19
     

  4. Enable the network interface:
    sudo ifconfig eth0 up
     

  5. Check if the change is successful:
    ifconfig |grep HWaddr  

    Should return the changed address:
    eth0           Link encap:Ethernet  HWaddr 00:15:a5:d5:39:19
    vboxnet0  Link encap:Ethernet  HWaddr 0b:00:23:00:00:00
    wlan0       Link encap:Ethernet  HWaddr e0:c9:d5:1a:ed:b5

Permanent solution

  1. Open the interfaces file, you can choose any text editor you want:
    sudo vi /etc/network/interfaces  

    You should see something like the following:
    auto lo
    iface lo inet loopback

  2. Add this line at the bottom of the file:
    hwaddress ether 00:15:a5:d5:39:19 

    The red text is the MAC address, so replace this one with your desired address.

  3. Restart the networking service or your computer:
    sudo /etc/init.d/networking restart

Common issue(es)

  1. If there is no connectivity after ifconfig eth0 up or sudo /etc/init.d/networking restart try the following:
    dhclient eth0 

    This will request a new IP address and it should fix the connectivity issue.

Go to Top