SOHO : Small Office Home Office
Freeware - Opensource software tips, tricks, tweaks & fixes for managing, securing, improving the performance of SOHO Desktop, Laptop, Networks

Friday, December 17, 2010

Manually Creating Shortcuts on Ubuntu Menu


Sometimes when an application is installed in Ubuntu the shortcuts are not created on the main menu and requires that you manually create the shortcuts for them.
Steps
  • Command line statement to execute the application
  • The path to the application
  • Location of the shortcut on the menu
We will say that we need to create a shortcut for an application called “myApp” and we want to add a shortcut to Applications -> Sound & Video.
First step is to switch to the /usr/share/applications directory where you’ll find all the shortcuts in the menu.
  • cd /usr/share/applications
We will create our shortcut.
  • sudo nano myapp.desktop
Now we’re going to add the details.
[Desktop Entry]
Name = myapp
Comment = My Application
Exec = /usr/bin/miapp
Icon = /usr/share/miapp/miapp.png
Terminal = false
Type = Application
Categories = Application;AudioVideo;
There are many more parameters you can use, but for this instance we’ll just stick to the basics. You can refer to the other shortcuts to see more options. To finish off save your changes and exit.
The important parameters that you need to have are Exec, Icon, Terminal and Categories.
Exec
This is where you place the path to the application you are creating the shortcut for. Sometimes a complete path is not necessary if the application will launch by simply typing a command.
Icon
This is the path to the icon you want displayed. Many applications come with their own set of icons. This is where you place the path to the icon you would like to reference this application with.
Terminal
Some applications require terminal while others don’t. Type in true if you would like the termial to be launched when the shortcut is initiated, otherwise leave it false.
Categories
This is where you add the menu placement for your shortcut. In our example we wanted to place our shortcut in Applications -> Sound & Video.
To see if it worked, see if you can find your MyApp shortcut under Applications -> Sound & Video.
Continue Reading...

Sunday, November 21, 2010

How to disable CPU core(s) in a multicore machine?

Method 1: "Change the Bootargs"

Change the boot arguments to use ony n number of CPU cores instead of m cores which are actually present, PROVIDED n

a) Add "maxcpus=n" in the bootargs during boot time:
 linux    /boot/vmlinuz-2.6.31-21-generic root=UUID=2ebbae04-b641-44e9-935f-8964159d79cb ro   quiet splash maxcpus=n
This will not be persistent across subsequent boots.

b) To make it permanent, modify/edit /etc/default/grub and add "maxcpus=n" in the following line:
GRUB_CMDLINE_LINUX_DEFAULT="quiet splash maxcpus=n"

Method 2: "Enable/Disable a CPU core on the fly"

On a Linux machine you can get the CPU information from /proc/cpuinfo file. On a dual core machine, you will get the output like this:
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
........
.....

processor : 1
vendor_id : GenuineIntel
........
.....
 To disable a core run the following command on a Ubuntu machine:
$ sudo sh -c "echo 'n' > /sys/devices/system/cpu/cpu1/online"

 Test if the core is disabled or not, check the /proc/cpuinfo file.
$ cat /proc/cpuinfo
processor : 0
vendor_id : GenuineIntel
........
.....

Now which method to choose from?

Method 1. is recommended since maxcpus=n should optimize some locks and instructions.
Choose Method 2. if you can't afford to restart your machine.

Happy Hacking!!

P.S. These instructions are only tested on a Dual core machine so I have no clue how they will behave on a multi-core(>2) environment.
Continue Reading...

Wednesday, November 10, 2010

Add user to mysql, commandline method


Solution: Here's an example of what I did recently to (a) create a new MySQL database and then (b) add a new MySQL user account to work with that database. As usual, the database name, username, and password have been changed.
First, from my Unix prompt, I log into my MySQL database with the mysql command line client:
unix> mysql -u root -p
(here I enter 'my_root_password' to get through the mysql prompt)

Next, I create my new MySQL database with the "create database" command:
mysql> create database my_database;
And now I create a MySQL user account, giving the user account all the priviliges it needs to "own" this database, with the MySQL grant command. Note that I assign both the username and password when I add this MySQL user:
mysql> GRANT ALL PRIVILEGES 
       ON my_database.* 
       TO 'my_user'@'localhost'
       IDENTIFIED BY 'my_password' 
       WITH GRANT OPTION;
Of course you can put that entire MySQL GRANT command on one line; I just put it on multiple lines here so it would be easier to read. Using this GRANT command is how you create a MySQL user account.
Update: Please see the Comments section below for an additional "MySQL add user" example that uses the "MySQL grant" command.

Note about this MySQL user account and "localhost"

It's important to note when I create this MySQL user, I'm giving the user access to this MySQL database from the computer system known as "localhost". This works fine when you're accessing this database with this new MySQL user account from the local computer system, but if you're going to access this database from another computer system, you'll need to specify the IP address of that remote system here instead of "localhost".
Continue Reading...

MySQL command to show list of databases on server


Q. I am new to MySQL database server. How do I show the list of databases on my server? Is there any good GUI frontend exists for the same?

A. You can use mysql command to connect to mysql server and list available databases.

Task: Mysql list databases

mysql is a simple command-line tool. mysql is command line and it is very easy to use. Invoke it from the prompt of your command interpreter as follows:
$ mysql

Output:
mysql>
You may need to provide mysql username, password and hostname, use:
$ mysql --user=your-user-name --password=your-password
mysql>

To list database type the following command

mysql> show databases;
Output:
+--------------------+
| Database           |
+--------------------+
| information_schema |
| mysql              |
+--------------------+
2 rows in set (0.00 sec)
information_schema and mysql are name of databases. To use these database and to list available tables type the following two commands:
mysql> use mysql;Output:
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
Now list tables:
mysql> show tables;Output:
+---------------------------+
| Tables_in_mysql           |
+---------------------------+
| columns_priv              |
| db                        |
| func                      |
| help_category             |
| help_keyword              |
| help_relation             |
| help_topic                |
| host                      |
| proc                      |
| procs_priv                |
| tables_priv               |
| time_zone                 |
| time_zone_leap_second     |
| time_zone_name            |
| time_zone_transition      |
| time_zone_transition_type |
| user                      |
+---------------------------+
17 rows in set (0.00 sec)

mysql>

GUI tools

Since you are new to MySQL, it is better to use GUI tools. Please refer previous article about "GUI Tools for managing MySQL databases server"
Continue Reading...

Recover MySQL root Password

You can recover MySQL database server password with following five easy steps.


Step # 1: Stop the MySQL server process.
Step # 2: Start the MySQL (mysqld) server/daemon process with the --skip-grant-tables option so that it will not prompt for password.
Step # 3: Connect to mysql server as the root user.
Step # 4: Setup new mysql root account password i.e. reset mysql password.
Step # 5: Exit and restart the MySQL server.
Here are commands you need to type for each step (login as the root user):

Step # 1 : Stop mysql service

# /etc/init.d/mysql stop
Output:
Stopping MySQL database server: mysqld.

Step # 2: Start to 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 mysql server using 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: Setup 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 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

Step # 6: Start MySQL server and test it

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

Mysql change root password by commandline


How do I change MySQL root password under Linux, FreeBSD, OpenBSD and UNIX like operating system over ssh / telnet session?
Setting up mysql password is one of the essential tasks. By default root user is MySQL admin account. Please note that the Linux / UNIX login root account for your operating system and MySQL root are different. They are separate and nothing to do with each other (indeed some admin removes root account and setup admin as mysql super user).

mysqladmin command to change root password

If you have never set a root password for MySQL, the server does not require a password at all for connecting as root. To setup root password for first time, use mysqladmin command at shell prompt as follows:
$ mysqladmin -u root password NEWPASSWORD
However, if you want to change (or update) a root password, then you need to use following command
$ mysqladmin -u root -p'oldpassword' password newpass
For example, If old password is abc, and set new password to 123456, enter:
$ mysqladmin -u root -p'abc' password '123456'

Change MySQL password for other user

To change a normal user password you need to type (let us assume you would like to change password for john)
$ mysqladmin -u john -p oldpassword password newpass

Changing MySQL root user password using MySQL sql command

This is another method. MySQL stores username and passwords in user table inside MySQL database. You can directly update password using the following method to update or change password for user john:
1) Login to mysql server, type following command at shell prompt:
$ mysql -u root -p
2) Use mysql database (type command at mysql> prompt):
mysql> use mysql;
3) Change password for user john:
mysql> update user set password=PASSWORD("NEWPASSWORD") where User='john';
4) Reload privileges:
mysql> flush privileges;
mysql> quit
This method you need to use while using PHP or Perl scripting.
Continue Reading...

How to add shopping cart to blogger?

The easiest way to add a shopping cart is to use Paypal Merchant Tools. Of course in order to make use of this service, you will need a Paypal account if you don't already have one. Signing up is free and easy. Plus by making use of Paypal Merchant Tools, you can accept credit card payments.

3 Steps to add shopping in blogger

  1. You will have to prepare your post. Add photographs, description, prices, etc.
  2. Sign into your Paypal account.
    • Click on the Merchant Tool tab.
    • At the right sidebar, click on "Paypal Shopping Cart"
    • Enter the details like Item Name/Service, Item ID/Number (optional), Price of Item/Service you want to sell, Currency, etc.
    • Then either tick the Paypal "Add to Cart" button or if you have your own button hosted on the web, enter its URL.
    • Click the "Create button now"  at the bottom of the page
    • Two  HTML script will be generated - one for the "Add to Shopping Cart" button and another for the "View Cart" button. Copy the HTML scripts and paste them in the appropriate places in your Post Editor Window.
    •  Add further buttons if required
  3. Publish the post.
Continue Reading...

Monday, October 18, 2010

Malwarebytes automatic update and scan for free version

Malwarebytes is a site dedicated to fighting malware. Malwarebytes has developed a variety of tools that can identify and remove malicious software from your computer. When your computer becomes infected, Malwarebytes can provide the needed assistance to remove the infection and restore the machine back to optimum performance.

The free edition is for home user or for personal use.

Here are handling for Windows XP:
  • Click on Start Menu> All Programs> Accessories> System Tools> Scheduled Tasks.
  • Choose Create a scheduled task.
Continue Reading...

Thursday, October 14, 2010

How do I use multiple screens on one terminal session over ssh?


How do I Use Multiple Screens on One Terminal over ssh session?

Most of the time GUI is not available on remote Linux system, you login over ssh and start to work, if you need to run two or three task at a time, you login over ssh two or three times. However, with screen windows manager utility you can run multiple terminals at the same time from single console login over ssh session (UNIX guru uses the term called multiplexing for this concept). Any seasoned Linux admin should be aware of this nifty tool.

Install screen if it is not installed under Debian Linux

Type the following command:
# apt-get install screen

FreeBSD user can use ports to install screen

# cd /usr/ports/misc/screen
# make install clean

Login to remote server over ssh

$ ssh me@myserver.com
(C) Start screen session. You can name your window/session (1 is name of session):
$ screen -S 1
Let us start pine mail reader on first session or window.
$ pine
(D) Next you would like to download something from ftp/http site while you are reading emails. You need to create another screen window by pressing special key combination. Press CTRL + a followed by c key (first hit CTRL+a, releases both keys and press c). As soon as you hit 'c' you will get new shell prompt at console. Now use wget to download belenix.iso.bz2 (Solaris live CD) from net:
$ wget http://www.genunix.org/distributions/belenix_site/binfiles/belenix.iso.bz2

(E) But how do I switch between these two tasks?

  • Switching between windows is the specialty of screen utility. So to switch between pine and wget window (or session) press CTRL+a followed by n key (first hit CTRL+a, releases both keys and press n).
  • To list all windows use the command CTRL+a followed by " key (first hit CTRL+a, releases both keys and press " ).
  • To switch to window by number use the command CTRL+a followed by ' (first hit CTRL+a, releases both keys and press ' it will prompt for window number).

Common screen commands

screen commandTask
Ctrl+a cCreate new window
Ctrl+a kKill the current window / session
Ctrl+a wList all windows
Ctrl+a 0-9Go to a window numbered 0 9, use Ctrl+a w to see number
Ctrl+a Ctrl+aToggle / switch between the current and previous window
Ctrl+a SSplit terminal horizontally into regions and press Ctrl+a c to create new window there
Ctrl+a :resizeResize region
Ctrl+a :fitFit screen size to new terminal size. You can also hit Ctrl+a F for the the same task
Ctrl+a :removeRemove / delete region. You can also hit Ctrl+a X for the same taks
Ctrl+a tabMove to next region
Ctrl+a D (Shift-d)Power detach and logout
Ctrl+a dDetach but keep shell window open
Ctrl-a Ctrl-\Quit screen
Ctrl-a ?Display help screen i.e. display a list of commands

Suggested readings:
See screen command man page for further details:
man screen

Continue Reading...

Thursday, August 19, 2010

Simple Ad Rotator PHP script

Overview: Creating a simple ad-rotator, the ads are stored in a text file and picked randomly by this PHP code.

Most of the webmaster use banner ads, we will be creating a very simple banner rotator, which picks up randomly one ad from the banner file and displays it, this file can be called in any other page to display the banners.

We will be storing banner ads in a text file banner_ads.txt

banner_ads.txt

Note that the banners are seperated by ~ in our banner file.










ad_rotator.php

The above 'ad_rotator.php' can be included in any PHP page to display a banner ad by using include 'ad_rotator.php'; tag wherever banner is required.

The above concept can be also be used to display random quotes etc, just modify the banners_ads.txt with the random content you want.


Continue Reading...

Sunday, August 8, 2010

How to setup a VPN server on a CentOS VPS instantly

Source : http://vpsnoc.com/blog/how-to-setup-a-vpn-server-on-a-centos-vps-instantly/

We have made a small and dirty bash script which installs and configures OpenVPN on CentOS 5 32bit. The VPN server’s primary (and only) use is for safe browsing i.e. tunneling all your traffic through your VPS. The script also generates your client configuration file along with the necessary keys for authentication.

Requirements
1. CentOS 5 32bit minimal OS template
2. TUN/TAP device enabled on your VPS
3. iptables NAT support
You will have to open a ticket to request a TUN/TAP device to be enabled on your VPS. If you’re not a customer of ours and your host’s support staff doesn’t know how to do this, you may tell them to execute the following commands on the hardware node where your VPS is hosted.

vzctl stop YOUR_VEID
vzctl set YOUR_VEID --devices c:10:200:rw --save
vzctl set YOUR_VEID --capability net_admin:on --save
vzctl start YOUR_VEID
vzctl exec YOUR_VEID "mkdir -p /dev/net; mknod /dev/net/tun c 10 200; chmod 600 /dev/net/tun"
# iptables support
vzctl stop YOUR_VEID
vzctl set YOUR_VEID --iptables ipt_REJECT --iptables ipt_tos --iptables ipt_TOS --iptables ipt_LOG --iptables ip_conntrack --iptables ipt_limit --iptables ipt_multiport --iptables iptable_filter --iptables iptable_mangle --iptables ipt_TCPMSS --iptables ipt_tcpmss --iptables ipt_ttl --iptables ipt_length --iptables ipt_state --iptables iptable_nat --iptables ip_nat_ftp --save
vzctl start YOUR_VEID

Make sure they will replace ‘YOUR_VEID’ with your VPS’s VEID and you will be ready to roll
Login to your VPS as root and execute the following commands

wget http://vpsnoc.com/scripts/install-openvpn.sh
chmod +x install-openvpn.sh
./install-openvpn.sh

You will be prompted to enter values for your server and client certificate, feel free to accept (hit enter) the default values. Its not recommended to setup a password for your server certificate as you will have to type in the password each time you wish to start/restart the openvpn daemon.
You can however set a password for your client’s certificate since it offers extra level of protection in case your certificate and key files are compromised. You will be prompted for that password each time you connect on your VPS’s VPN.
After the script finished installing openvpn (should be very quick) the client keys and the openvpn clientconfiguration file will be archived in /root/keys.tgz
You may use a sftp/scp client such as winscp or filezilla to download the archive on your computer.
If you already haven’t installed openvpn for windows you may do so now.
You may use winrar or 7zip to extract the content of keys.tgz in C:\Program Files\OpenVPN\config\VPN (create a folder named VPN there)
After you have extracted the files from keys.tgz in the above folder, you may start openvpn-gui from the start menu, right click the tray icon, go to VPN and click connect. After the icon turns green all your traffic will be forwarded through your VPS, no extra configuration on your browser/IM client/email client is required.
If you’re facing issues make sure that your computer clock is synchronized, if so make sure that your VPS’s clock is correct as well. If it’s not you will have to ask your host to sync it.
For any other issues and feedback please e-mail us at support@vpsnoc.com
You may use and modify this script however you see fit, provided that you do not edit the original copyright.

#!/bin/bash
# Quick and dirty OpenVPN install script
# Tested on Centos 5.x 32bit, openvz minimal CentOS OS templates
# Please submit feedback and questions at support@vpsnoc.com
# John Malkowski vpsnoc.com 01/04/2010
ip=`grep IPADDR /etc/sysconfig/network-scripts/ifcfg-venet0:0 | awk -F= '{print $2}'`
wget http://packages.sw.be/rpmforge-release/rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rpm -iv rpmforge-release-0.3.6-1.el5.rf.i386.rpm
rm -rf rpmforge-release-0.3.6-1.el5.rf.i386.rpm
yum -y install openvpn openssl openssl-devel
cd /etc/openvpn/
cp -R /usr/share/doc/openvpn-2.0.9/easy-rsa/ /etc/openvpn/
cd /etc/openvpn/easy-rsa/2.0/
chmod +rwx *
. ../vars
./clean-all
source ./vars
echo -e "\n\n\n\n\n\n\n" | ./build-ca
clear
echo "####################################"
echo "Feel free to accept default values"
echo "Wouldn't recommend setting a password here"
echo "Then you'd have to type in the password each time openVPN starts/restarts"
echo "####################################"
./build-key-server server
./build-dh
cp keys/{ca.crt,ca.key,server.crt,server.key,dh1024.pem} /etc/openvpn/
clear
echo "####################################"
echo "Feel free to accept default values"
echo "This is your client key, you may set a password here but it's not required"
echo "####################################"
./build-key client1
cd keys/
client="
client
remote $ip 1194
dev tun
comp-lzo
ca ca.crt
cert client1.crt
key client1.key
route-delay 2
route-method exe
redirect-gateway def1
dhcp-option DNS 10.8.0.1
verb 3"

echo "$client" > $HOSTNAME.ovpn
tar czf keys.tgz ca.crt ca.key client1.crt client1.csr client1.key $HOSTNAME.ovpn
mv keys.tgz /root
opvpn='
dev tun
server 10.8.0.0 255.255.255.0
ifconfig-pool-persist ipp.txt
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
push "route 10.8.0.0 255.255.255.0"
push "redirect-gateway"
comp-lzo
keepalive 10 60
ping-timer-rem
persist-tun
persist-key
group nobody
daemon'
echo "$opvpn" > /etc/openvpn/openvpn.conf
echo 1 > /proc/sys/net/ipv4/ip_forward
iptables -t nat -A POSTROUTING -s 10.8.0.0/24 -o venet0 -j MASQUERADE
iptables-save > /etc/sysconfig/iptables
sed -i 's/eth0/venet0/g' /etc/sysconfig/iptables # dirty vz fix for iptables-save
echo "net.ipv4.ip_forward=1" >> /etc/sysctl.conf
/etc/init.d/openvpn start
clear
echo "OpenVPN has been installed
Download /root/keys.tgz using winscp or other sftp/scp client such as filezilla
Create a directory named vpn at C:\Program Files\OpenVPN\config\ and untar the content of keys.tgz there
Start openvpn-gui, right click the tray icon go to vpn and click connect
For support/bug reports email us at support@vpsnoc.com"
Continue Reading...

How to enable IP forwarding in linux?

How to enable IP Forwarding in Linux

By default any modern Linux distributions will have IP Forwarding disabled. This is normally a good idea, as most peoples will not need IP Forwarding, but if we are setting up a Linux router/gateway or maybe a VPN server (pptp or ipsec) or just a plain dial-in server then we will need to enable forwarding. This can be done in several ways that I will present bellow.

Check if IP Forwarding is enabled

We have to query the sysctl kernel value net.ipv4.ip_forward to see if forwarding is enabled or not:
Using sysctl:




sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 0

or just checking out the value in the /proc system:




cat /proc/sys/net/ipv4/ip_forward
0

As we can see in both the above examples this was disabled (as show by the value 0).

Enable IP Forwarding on the fly

As with any sysctl kernel parameters we can change the value of net.ipv4.ip_forward on the fly (without rebooting the system):




sysctl -w net.ipv4.ip_forward=1

or




echo 1 > /proc/sys/net/ipv4/ip_forward

the setting is changed instantly; the result will not be preserved after rebooting the system.

Permanent setting using /etc/sysctl.conf

If we want to make this configuration permanent the best way to do it is using the file/etc/sysctl.conf where we can add a line containing net.ipv4.ip_forward = 1




/etc/sysctl.conf:
net.ipv4.ip_forward = 1

if you already have an entry net.ipv4.ip_forward with the value 0 you can change that 1.
To enable the changes made in sysctl.conf you will need to run the command:




sysctl -p /etc/sysctl.conf

On RedHat based systems this is also enabled when restarting the network service:




service network restart

and on Debian/Ubuntu systems this can be also done restarting the procps service:




/etc/init.d/procps.sh restart

Using distribution specific init scripts

Although the methods presented above should work just fine and you would not need any other method of doing this, I just wanted to note that there are also other methods to enable IP Forwarding specific to some Linux distributions.
For example Debian based distributions might use the setting:




/etc/network/options:
ip_forward=no

set it to yes and restart the network service.
Also RedHat distributions might set this using:




/etc/sysconfig/network:
FORWARD_IPV4=true

and again restart the network service.
Regardless the method you have used once you have completed this you can check it out using the same method shown above:




sysctl net.ipv4.ip_forward
net.ipv4.ip_forward = 1




cat /proc/sys/net/ipv4/ip_forward
1

If the result is 1 then the Linux system will start forwarding IP packets even if they are not destined to any of its own network interfaces.
ps. I was setting up a VPN  server when I wrote this post.
Continue Reading...