VNC useful commands

Below is a list of vnc commands I often use to manage vnc sessions on my ubuntu linux box.

# start a session
vncserver -geometry 1600x1200 -depth 24 -alwaysshared

# specific display numbers
## sublime ##
vncserver -geometry 1600x1000 -depth 24 -alwaysshared :200
## eclipse ##
vncserver -geometry 1600x1000 -depth 24 -alwaysshared :300

# see what sessions are active
ls ~/.vnc/*.pid

# kill a session
vncserver -kill :[session_num]

# help
vncserver -h

Here is more online references for more options you can set.

For osx (as my client box), I use Chicken of the VNC. It gets the job done. 😉

Setting up a VPN server on a Mountain Lion Server

This is a guide to set up a simple L2TP VPN connection.

My mac mini server has mountain lion osx v. 10.8.2. I have also signed up for a “domain” at You may want to make sure you can ssh to your server first from the outside network before moving forward.

I have my server behind a linksys router so I need to set up the router first. Bring up the router page, mine is at Then click Security -> Firewall. Then uncheck the Block anonymous Internet Request. Yea, sounds scary isn’t it? Then click Save Settings, the router blacks out, then comes back.


Next, click Applications & Gaming -> Single Port Forward. This is where you put in all the port forwarding info for our VPN service. The port you will need to forward are: 500, 1701, 4500, and 50. They will need to get forwarded to your server IP.


Then open up your Server Application. Go to the VPN window. Pick L2TP. The host name is how you refer to your server in your local network, could be anything. The Shared Secret is important, and you will be handing this out to your users later. After filling out all these, switch on the VPN server on the top right.


Your VPN server is now setup.

Now on the client side. Open up System Preferences, then click Network. Create a VPN, L2TP over IPSec connection profile. Then start filling in the fields. The Service Address is, for example, the one I get from The Account Name is a valid username on your server.


Then click on the Authentication Settings… button. This is where you put in the user’s password, and the Shared Secret that we put in earlier on the server. When done, click ok.


Then click the Connect button. Cross your fingers…

Hopefully you will see the green light for your VPN connection! If you want to double check whether you are on your private network, you can try ssh to one of your machines in the 192.168.1.x address range and see how it goes.


Happy VPN’ing!

splitting and joining huge files

Today I wanted to sftp a 10Gb file over the wire. Knowing that the transfer would fail in the middle of it, I decided to split this file into small pieces beforehand. Below I think is the easiest way on osx.

// to split my huge file into 100mb files, having the prefix "bak_"
split -b 100m my_huge_file.ext bak_

// to re-construct my huge file
cat `ls bak_*` > my_huge_file2.ext

After running the split command, you will see some files named bak_aa, bak_ab, etc in your directory. These are the chucks of your original huge file. So just transfer these small bak_* files over the wire.

sftp doesn’t have mput… sigh…

Also the original file name is gone missing in the process… sigh… That’s unfortunate. What I decided to do is to write up a small readme file to store the above two commands, so later on I know what output filename to use when running the second command.

DNS flush

Sometimes you may need to do a DNS flush, say after a mysterious DNS network issue. Here are the commands.

Mountain Lion / Lion
sudo killall -HUP mDNSResponder

sudo dscacheutil -flushcache

lookupd -flushcache

ipconfig /flushdns

Run a nslookup or ping to check if you are indeed getting the correct IP(s) from the DNS server(s).

Installing mysql on osx

I often need to do this so I figure I will write it down to remind myself later.

First, download the mysql installation dmg file (version 5.5.20 as of now). osx already comes with mysql but I like the extra System Pref icon after the manual install. You can download at Pick Mac OS X 10.6 (x86, 64-bit), DMG Archive. Once you have the dmg file, open and install all three files (mysql-5.5.20-osx10.6-x86_64.pkg, MySQL.prefPane, MySQLStartupItem.pkg) in there.

Then in your ~/.bash_rc file, put in the following to save typing.

alias mysql=/usr/local/mysql-5.5.20-osx10.6-x86_64/bin/mysql
alias mysqladmin=/usr/local/mysql-5.5.20-osx10.6-x86_64/bin/mysqladmin

You can surely add /usr/local/mysql-5.5.20-osx10.6-x86_64/bin/ to the $PATH variable in your ~/.bash_profile file. Yea, whatever works.


Then turn on your MySQL daemon. An easy way is to open up System Preferences, then find the MySQL icon, open it. Then start the server and check the auto-start option below. If everything goes well, you will see the green running text.

Then set the root password for this database. The following set the root password to my_secret_password

$ mysqladmin -u root password my_secret_password

To change your root password, say from my_secret_password to abc123, do the following.

$ mysqladmin -u root -p 'my_secret_password' password 'abc123'

Alright, mysql is now up and running!

Bonus: To make your life a little easier, download Sequel Pro. It’s a free osx mysql gui.

Installing memcache on osx for php

Finally got memcache working!

I am compiling the steps here in case I need to do it again.

First install libevent. This is a dependency to memcached, so need to get it.

cd /tmp
curl -OL
tar -xvzf libevent-2.0.17-stable.tar.gz
cd libevent-2.0.17-stable*
sudo make install

Then install memcached.

# Compile memcached utility
cd /tmp
curl -O
tar -xvzf memcached-1.4.13.tar.gz
cd memcached-1.4.13*
sudo make install

At this point, if everything goes well, the memcache daemon should be ready to run. You can try the following to see if memcached returns anything to you.

memcached -d -m 24 -p 11211
telnet localhost 11211

When you run memcached -d -m 24 -p 11211, you are assigning 24Mb ram for memcache to use, and using the port 11211, which is the default port for memcache. The -d runs memcache as a daemon.

After you run stats, you should see some stats returned on your screen. If so, that means memcache is running fine now.

Next step is to make sure php can talk to memcache.

Download the php extension to memcached from this link: I recommend getting the stable version, 2.2.6 as of June 2012.

After uncompressing it, do phpize. If you get an error on not having autoconf, install it with brew. See my other tutorial on how to do that.

gzip -d < memcache-2.2.6.tgz | tar -xvf -
cd memcache-2.2.6

After phpize gives you your php version info, do the usual compile and install:

sudo make install

Double check that the file is in your php include directory.

ls /usr/lib/php/extensions/no-debug-non-zts-20090626/

It should be there… if not, you can manually copy the file yourself. It’s located under the “modules” folder.

Now, modify your /etc/php.ini file to include this extension.

extension =

Then finally, restart apache.

sudo apachectl restart

If everything goes well, your phpinfo() should give you a section on memcached, indicating memcached is loaded properly.

Congratulation! At this point php is ready to interact with memcache. But just how to do that in code? Let’s wait for my part 2 of this tutorial. 😉

Ref link:

“You have new mail” on osx

Sometimes when I open up a new terminal I see the following, notifying me there are new mails in my system mail box.

Last login: Tue Feb 28 18:57:43 on ttys006
You have new mail.

Just how to read those emails?

You can use “mailx”.

my_osx_box:~ birdchan$ mailx

This is a very linux like mail program, so don’t expect fancy controls. Below are some commands that are enough to get you through.

  • h: lists the current emails in your mailbox, notice there is an ID before each email.
  • NUMBER: Just type in the email ID and press enter, you will enter the reading mode. Then ENTER gets you to the next line, SPACE next page. Just like in MORE.
  • d <num>: deletes the corresponding email.
  • ?: Shows you all the commands