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

Edit crontab with nano in centos the easyway

source :

Edit crontab with NANO on centos (crontab -e)
Posted September 25th, 2013 by Ben & filed under CentOS.

Problem: I don’t know where my root users crontab file is, and this doesn’t usually matter because using the command ‘crontab -e’ opens it for editing anyway… but it opens in VI and I am too stupid / lazy / in a rush to use VI.

Solution: The -e switch makes the file open in whatever the default editor for the environment is. To override this, pass the EDITOR environment var to the command when it’s run:

sudo env EDITOR=nano crontab -e
Continue Reading...

Mount HFS+ (apple) file system in ubuntu

Mount HFS+ apples file system in ubuntu

sudo apt-get install hfsplus hfsutils hfsprogs

Mount as usual.

Note: HFS file system by default will be read only to enable write mode journal has to be disabled first before removing the drive.

Continue Reading...

Find WAN / public IP from command line

There are many websites and web scripts available to know your external (WAN/INTERNET/PUBLIC) IP address. To find out the wan IP address from command line below are two simple methods

The below two methods rely on external services to detect the IP address. Any one of the listed service can be used

1) curl :

Can be installed by running command "sudo apt-get install curl". To know the IP run command

my preferred url is  a service by opendns and can be replaced with any one of the above urls.

2) wget :

By default wget would be installed on most of the system if not can be installed with command "sudo apt-get install wget". To know the IP run command
wget -O - -q ; echo 
Continue Reading...

Hide post time stamp blogger homepage

Post status : incomplete

How to hide post date, time stamp and author from blogger home page only.

This can be done using conditional tags to
<span class='post-author vcard'>
<span class='post-timestamp'>

Conditional tag syntax

<b:if cond='PUT_CONDITION_HERE'>
It is made up of a <b:if> tag, with a  cond attribute added. Condition is entered as the value of the cond attribute. Each (opening) <b:if> tag need to be closed with a closing </b:if> tag.

The below conditional tag is specific to homepage. I only list the opening tags here. Just make sure you include the closing </b:if> tag when applying a conditional in your template. (More list of conditional tags -- todo)
<b:if cond='data:blog.url == data:blog.homepageUrl'>

Applying conditional tag

To apply a conditional tag to a content, simply put the content between the opening <b:if cond…> and the closing </b:if>, like so:
<b:if cond='data:blog.pageType == "item"'>
In the example above, the content will only appear on post pages.
If you want to specify a alternate content (when the condition is false), you need to insert a <b:else/> tag followed by the content, like this:
<b:if cond='data:blog.pageType == "item"'>
You can place the conditional anywhere in your template HTML, except inside a section or inside a widget content box. The content can be a div, a section, a style tag, another conditional tag etc.

Reversing a condition
A condition can be reversed simply by replacing the comparison operator from == (is equal to) to != (is not equal to), like so:
<b:if cond='data:blog.pageType != "item"'>
In the example above, the content will only appear on pages other than post pages (i.e. removed/hidden from post pages). This method is not applicable to Label-search and First Post conditionals.

Editing the template

Go to Dashboard > Template > edit HTML
Make sure to backup a copy before you make changes.

Search for <span class='post-timestamp'>
<span class='post-timestamp'>
                <b:if cond='data:top.showTimestamp'>
                  <b:if cond='data:post.url'>
                    <meta expr:content='data:post.canonicalUrl' itemprop='url'/>
                    <a class='timestamp-link' expr:href='data:post.url' rel='bookmark' title='permanent link'><abbr class='published' expr:title='data:post.timestampISO8601' itemprop='datePublished'><data:post.timestamp/></abbr></a>
Modifiy the code as below

<span class='post-timestamp'>
                <b:if cond='data:top.showTimestamp'>

                  <b:if cond='data:blog.url != data:blog.homepageUrl'>
                    <meta expr:content='data:post.canonicalUrl' itemprop='url'/>
                    <a class='timestamp-link' expr:href='data:post.url' rel='bookmark' title='permanent link'><abbr class='published' expr:title='data:post.timestampISO8601' itemprop='datePublished'><data:post.timestamp/></abbr></a>
Search for <span class='post-author vcard'>
<div class='post-footer-line post-footer-line-1'>
              <span class='post-author vcard'>
 <b:if cond='data:blog.url != data:blog.homepageUrl'>
                <b:if cond='data:top.showAuthor'>
                  <b:if cond='data:post.authorProfileUrl'>
                    <span class='fn' itemprop='author' itemscope='itemscope' itemtype=''>
                      <meta expr:content='data:post.authorProfileUrl' itemprop='url'/>
                      <a expr:href='data:post.authorProfileUrl' rel='author' title='author profile'>
                        <span itemprop='name'><></span>
Modify the code as below
<div class='post-footer-line post-footer-line-1'>              <span class='post-author vcard'> <b:if cond='data:blog.url != data:blog.homepageUrl'>                <b:if cond='data:top.showAuthor'>                  <b:if cond='data:post.authorProfileUrl'>                    <span class='fn' itemprop='author' itemscope='itemscope' itemtype=''>                      <meta expr:content='data:post.authorProfileUrl' itemprop='url'/>                      <a expr:href='data:post.authorProfileUrl' rel='author' title='author profile'>                        <span itemprop='name'><></span>                      </a>                    </span>

Search for data:post.dateHeader

To remove the date stamp above your post and only from home page, edit the template, find the below code
<b:if cond='data:post.dateHeader'>
          <h2 class='date-header'><span><data:post.dateHeader/></span></h2>

 Modify it to

<b:if cond='data:blog.url != data:blog.homepageUrl'>
<b:if cond='data:post.dateHeader'>
          <h2 class='date-header'><span><data:post.dateHeader/></span></h2>
Continue Reading...

Remove offending RSA key in ~/.ssh/known_hosts file with one line command

When you ssh to a server where the host key (RSA) has changed then you will get an error message as shown in the image:

The error in the above example :
Offending RSA key in /home/username/.ssh/known_hosts:8

Looking in to the error message, we can find the offending RSA key and its position in the known_hosts file. In the above example image the offending key is at  line 8. (marked with red line). This can be fixed by deleting the offending key so that ssh lets you to connect after accepting the new key. This offending RSA key from the known_hosts file can be removed using `sed` with the following parameters:

$ sed -i '8d' ~/.ssh/known_hosts

The parameters
-i   :  For inplace editing
8d : Offending RSA key at line no 8
~/.ssh/known_hosts : path to and file known_hosts.
Continue Reading...

Remote shutdown one line ssh command

Q.) How to shut down / restart  a remote linux server from ssh ?

A.)  ssh -t user@hostname 'sudo shutdown -P now'

In the above example
-t  : forces the allocation of a tty for the command.
-P : stands for power off.
-r  : to reboot.
-h : to halt. 

Also all the shutdown arguments can be passed along. To know more about shutdown options run command.
shutdown --help

Continue Reading...

How to show / hide uvnc tray icon with registry method

UVNC release 1.1.8 november 2012.

We prefer to install uvnc as a service, disable tray icon and store the settings in registry rather than ultravnc.ini file.  The admin properties is accessed by right click on the uvnc tray icon. All the settings in the admin properties window can be edited in the registry. But for new sys-admins or support engineers who are not familiar with the registry properties prefer to edit the admin properties by the gui method. This post will help to enable/disable the tray icon by registry method.

1. Stop uvnc service
Right click taskbar > start task manager > goto services tab > Right click uvnc_service and click stop service

2. Regedit 
Open regedit by go to start > run > regedit 

3. Editing the WinVNC3

If you are  not able to locate WinVNC3 at the above path then perform a search for WinVNC3. To perform search go to edit and click find.

Right click on DisableTrayIcon and click on modify
Change the value to 1 to remove tray icon
Change the value to 0 to show tray icon

4. Start uvnc_service
Right click taskbar> start taskmanger> goto services tab> Right click uvnc_service and click start service

5. Tray icon

6. Admin properties window
Right click on the tray icon > select the admin properties

Continue Reading...

EasyPHP error cannot run specified program

EasyPHP is a COMPLETE WAMP package and READY-TO-USE ENVIRONMENT for PHP DEVELOPERS including the server-side scripting language PHP, the web server Apache, the SQL server MySQL, as well as development tools such as the database manager PhpMyAdmin, the debugger Xdebug and many others. Nothing to configure. It's already done! You just need to download, intall ... and code. The administration page allows you to list the docroot, extensions,change the Apache port, the timezone, max execution time, error reporting,upload max filesize, add/remove alias, manage modules.

After installing and running the easyphp I got an error 
"The system cannot execute the specified program" 

You are trying to run some program on Windows (such as apache.exe or htpasswd.exe) and you are getting "The system cannot execute the specified program" error. This usually means that the program you are trying to run was compiled against DLLs that are not on your system.

The Apache 2.x binary windows distribution, specifically, was compiled against the Visual Studio 2008 re-distributable package, which you can download from microsoft.

Download link:
Microsoft Visual C++ 2008 SP1 Redistributable package (x86)

Microsoft Visual C++ 2008 SP1 Redistributable package (x64)

Microsoft Visual C++ 2008 Redistributable package (choose from the list of downloads accordingly)

Continue Reading...

Install openvpn on ubuntu VPS in less than 10 minutes


If all that you want is just a openvpn server without the hassle of compiling, I recommend a debian / ubuntu system with a minimum of 64mb RAM. The below instructions would let you connect to your own openvpn (openvz VPS) server in less than 10 minutes.


Before we install openvpn, check if tun/tap is enable for your vps:
cat /dev/net/tun 
In the above image "File descriptor in bad state"  means  tun/tap enabled. If not, contact your vps provider to activate tun/tap. Without tun/tap vpn connection cannot be established.


To install openvpn in a terminal enter:
sudo apt-get install openvpn

Server Certificates

Now that the openvpn package is installed, the certificates for the VPN server need to be created. 
First, copy the easy-rsa directory to /etc/openvpn. This will ensure that any changes to the scripts will not be lost when the package is updated. You will also need to adjust permissions in the easy-rsa directory to allow the current user permission to create files. From a terminal enter:

sudo mkdir /etc/openvpn/easy-rsa/
sudo cp -r /usr/share/doc/openvpn/examples/easy-rsa/2.0/* /etc/openvpn/easy-rsa/
sudo chown -R $USER /etc/openvpn/easy-rsa/
Next, edit /etc/openvpn/easy-rsa/vars adjusting the following to your environment:

export KEY_CITY="Winston-Salem"
export KEY_ORG="Example Company"
export KEY_EMAIL=""
Enter the following to create the server certificates:

cd /etc/openvpn/easy-rsa/
source vars
./pkitool --initca
./pkitool --server server
cd keys
openvpn --genkey --secret ta.key
sudo cp server.crt server.key ca.crt dh1024.pem ta.key /etc/openvpn/

Client Certificates

The VPN client will also need a certificate to authenticate itself to the server. To create the certificate, enter the following in a terminal:

cd /etc/openvpn/easy-rsa/
source vars
./pkitool hostname
Replace hostname with the actual hostname of the machine connecting to the VPN.
Copy the following files to the client:

Remember to adjust the above file names for your client machine's hostname.
It is best to use a secure method to copy the certificate and key files. The scp utility is a good choice, but copying the files to removable media then to the client, also works well.


Server Configuration

Now configure the openvpn server by creating /etc/openvpn/server.conf from the example file. In a terminal enter:

sudo cp /usr/share/doc/openvpn/examples/sample-config-files/server.conf.gz /etc/openvpn/
sudo gzip -d /etc/openvpn/server.conf.gz
Edit /etc/openvpn/server.conf changing the following options to:

push "redirect-gateway defi by-pass-dhcp" ; uncomment this line
push "dhcp-option DNS"; add this line
script-security 3 ; add this line
push: are directives to add networking options for clients.

After configuring the server, restart openvpn by entering:
sudo /etc/init.d/openvpn restart

Network Configuration

This network configuration is for openvz virtualization only, This guide is not related to dedicated or xen server.

Edit  /etc/sysctl.conf file and uncomment the following line:
We want the ipv4 forward to be persistent even on reboot:
sudo echo 1 > /proc/sys/net/ipv4/ip_forward

Firewall / iptables Configuration

Setup iptables to allow vpn connection
iptables -A FORWARD -m state --state RELATED,ESTABLISHED -j ACCEPT
iptables -A FORWARD -s -j ACCEPT
iptables -A FORWARD -j REJECT
iptables -t nat -A POSTROUTING -s -j SNAT --to-source
Replace with the actual ip address.

Saving iptables

You may want to have your iptables saved everytime you reboot. You could add a line like this one in /etc/network/interfaces

pre-up iptables-restore < /etc/iptables.rules
post-down iptables-save > /etc/iptables.rules
The line "post-down iptables-save > /etc/iptables.rules" will save the rules to be used on the next boot.

Manage users

You may want to add multiple users to your vpn server with the command:

useradd username -s /bin/false
passwd username
You may want to delete a user with the command
userdel username 
Finally, restart openvpn:
sudo /etc/init.d/openvpn restart 
You should now be able to connect to the remote LAN through the VPN..

Client Configuration 

First, install openvpn on the client:
sudo apt-get install openvpn
Then with the server configured and the client certificates copied to the /etc/openvpn/ directory, create a client configuration file by copying the example. In a terminal on the client machine enter:
sudo cp /usr/share/doc/openvpn/examples/sample-config-files/client.conf /etc/openvpn
Now edit /etc/openvpn/client.conf changing the following options:

remote 1194
cert hostname.crt
key hostname.key
ca ca.crt
tls-auth ta.key 1
script-security 3
Replace with the hostname of your VPN server, and hostname.* with the actual certificate and key filenames.

Windows Client Configuration 

  • Download and install openvpn-gui stable
  • copy client.conf file to c:\program files\openvpn\config\ rename client.conf to client.ovpn
  • copy ca.crt, hostname.crt, hostname.key, ta.key to c:\program files\openvpn\config\
  • Right click openvpn tray icon and connect

Sample server configuration

port 1194
proto udp
dev tun
ca ca.crt
cert server.crt
key server.key
dh dh1024.pem
ifconfig-pool-persist ipp.txt
push "redirect-gateway def1 bypass-dhcp"
push "dhcp-option DNS"
keepalive 10 120
status openvpn-status.log
verb 3
script-security 3

Sample client configuration

dev tun
proto udp
remote 1194
resolv-retry infinite
script-security 3
ca ca.crt
ns-cert-type server
verb 3

Continue Reading...

Setup ramdisk with ramfs or tmpfs

Using ramfs or tmpfs you can allocate part of the physical memory to be used as a partition. You can mount this partition and start writing and reading files like a hard disk partition. Since you’ll be reading and writing to the RAM, it will be faster.

When a vital process becomes drastically slow because of disk writes, you can choose either ramfs or tmpfs file systems for writing files to the RAM.

Both tmpfs and ramfs mount will give you the power of fast reading and writing files from and to the primary memory. When you test this on a small file, you may not see a huge difference. You’ll notice the difference only when you write large amount of data to a file with some other processing overhead such as network.

 How to mount Tmpfs
# mkdir -p /mnt/tmp
# mount -t tmpfs -o size=20m tmpfs /mnt/tmp

The last line in the following df -k shows the above mounted /mnt/tmp tmpfs file system.

# df -k
Filesystem      1K-blocks  Used     Available Use%  Mounted on
/dev/sda2       32705400   5002488  26041576  17%   /
/dev/sda1       194442     18567    165836    11%   /boot
tmpfs           517320     0        517320    0%    /dev/shm
tmpfs           20480      0        20480     0%    /mnt/tmp

How to mount Ramfs

# mkdir -p /mnt/ram
# mount -t ramfs -o size=20m ramfs /mnt/ram

The last line in the following mount command shows the above mounted /mnt/ram ramfs file system.

# mount
/dev/sda2 on / type ext3 (rw)
proc on /proc type proc (rw)
sysfs on /sys type sysfs (rw)
devpts on /dev/pts type devpts (rw,gid=5,mode=620)
/dev/sda1 on /boot type ext3 (rw)
tmpfs on /dev/shm type tmpfs (rw)
none on /proc/sys/fs/binfmt_misc type binfmt_misc (rw)
sunrpc on /var/lib/nfs/rpc_pipefs type rpc_pipefs (rw)
fusectl on /sys/fs/fuse/connections type fusectl (rw)
tmpfs on /mnt/tmp type tmpfs (rw,size=20m)
ramfs on /mnt/ram type ramfs (rw,size=20m)

You can mount ramfs and tmpfs during boot time by adding an entry to the /etc/fstab

Ramfs vs TmpfsPrimarily both ramfs and tmpfs does the same thing with few minor differences.
  •  Ramfs will grow dynamically.  So, you need control the process that writes the data to make sure ramfs doesn’t go above the available RAM size in the system. Let us say you have 2GB of RAM on your system and created a 1 GB ramfs and mounted as /tmp/ram. When the total size of the /tmp/ram crosses 1GB, you can still write data to it.  System will not stop you from writing data more than 1GB. However, when it goes above total RAM size of 2GB, the system may hang, as there is no place in the RAM to keep the data.
  • Tmpfs will not grow dynamically. It would not allow you to write more than the size you’ve specified while mounting the tmpfs. So, you don’t need to worry about controlling the process that writes the data to make sure tmpfs doesn’t go above the specified limit. It may give errors similar to “No space left on device”.
  • Tmpfs uses swap.
  • Ramfs does not use swap.
Disadvantages of Ramfs and Tmpfs
Since both ramfs and tmpfs is writing to the system RAM, it would get deleted once the system gets rebooted, or crashed. So, you should write a process to pick up the data from ramfs/tmpfs to disk in periodic intervals. You can also write a process to write down the data from ramfs/tmpfs to disk while the system is shutting down. But, this will not help you in the time of system crash.

Table: Comparison of ramfs and tmpfs
Experimentation Tmpfs Ramfs
Fill maximum space and continue writing Will display error Will continue writing
Fixed Size Yes No
Uses Swap Yes No
Volatile Storage Yes Yes

If you want your process to write faster, opting for tmpfs is a better choice with precautions about the system crash.
Continue Reading...