Monday, May 26, 2008

The mystery of quotes

In linux environment, there are 3 types of quotes as far as i know. Each of the quotes bring different meaning and usage.

  1. ' a.k.a. single quotes - Everything wrapped in this quote won't be changed (Strong quotes)
  2. " a.k.a. double quotes - Quotes that doesn't expand meta-characters like "*" or "?," but does expand variables and does command substitution (Weaker quotes)
  3. ` a.k.a. back quotes - To execute command
Examples of quotes usage (top lines are commands and the output are displayed below the commands):

Example of using back quotes within single quotes. Nothing is changed.
$ echo 'Today is `date`'
Today is `date`

Example of using back quotes within double quotes. The `date` command will be executed
$ echo "Today is `date`"
Today is Mon May 26 09:42:50 MYT 2008

Wednesday, May 14, 2008

Fedora 9 is here

Fedora 9 is already available. Get your copy here. A brief introduction to fedora:

" Fedora is a Linux-based operating system that showcases the latest in free and open source software. Fedora is always free for anyone to use, modify, and distribute. It is built by people across the globe who work together as a community: the Fedora Project. The Fedora Project is open and anyone is welcome to join.

The Fedora Project is out front for you, leading the advancement of free, open software and content. "

Tuesday, May 13, 2008

Replacing words in vi

To replace word in vi, the below steps can be used(replace OLD with NEW). Please make sure you are in command(normal) mode:

  1. to replace first occurrence of OLD to NEW on current line
    • :s/OLD/NEW
  2. to replace all occurrence of OLD to NEW on current line
    • :s/OLD/NEW/g
  3. to replace all occurrence of OLD to NEW between two line numbers (# are the line numbers)
    • :#,#s/OLD/NEW/g
  4. to replace every occurrence of OLD to NEW on current file
    • :%s/OLD/NEW/g

Sunday, May 11, 2008

Creating ssh reverse tunnel

Imagine you are out of the office, but you have an important document that you have to get from your personal computer in your office. Unfortunately your computer is protected behind a firewall, making it impossible to access. But you have a server that you can access and your personal computer also can access this server. This is where ssh reverse tunnel come into action. For easy explanation, we will call your current computer as current, your server as middle and your personal computer at the office as target.

Pre-condition for ssh reverse tunnel

  1. The current computer that you have can connect to port 12000 (or any other) on the middle server.
  2. The middle is running an ssh daemon willing to do port-forwarding (enabled by default in OpenSSH) and the GatewayPorts feature is enabled
  3. You can open an ssh connection from target to the middle in advance and leave it open.
  4. The SSH daemon is running on target on port 22. In fact the port can be arbitrary and the daemon does not have to allow port forwarding. You can even establish your own (not root) ssh daemon.
Below are the steps:
  1. Create a tunnel from middle to target and leave it open when you are still at the office. You cn also ask your colleague at the office to do this. The below command will open port 12000 on middle for listening and forward all request on port 12000 on middle to port 22 of target
    • user@target $ ssh -R 12000:localhost:22 middleuser@middle
  2. Now you can access to port 12000 on middle from current and you will be forwarded to port 22 on target
    • user@current $ ssh targetuser@middle -p 12000
  3. If somehow you cannot access, access middle first, then connect to port 12000 of localhost
    • user@current $ ssh middleuser@middle
    • user@middle $ ssh targetuser@localhost -p 12000
  4. You are now in the target server