How to change baud rate of ttyS0 in Ubuntu 14.04?

The stty command handles that:

sudo stty -F /dev/ttyS0 9600

You can confirm that you succeeded in changing the baud rate by asking stty to print out the current settings with:

sudo stty -F /dev/ttyS0 -a

See man stty for more details.