Install openssh server on machine B.
$ sudo apt-get install openssh-server
In Ubuntu ssh server will be started automatically. If not start it
$ sudo /etc/init.d/sshd start
Now you can connect to B from A$ssh username@b.b.b.b
username will be user of system B.
When you do this for the first time , you may be asked to type yes/no to add the finger print of the remote machine. Now enter the password and you are done.
You can execute normal shell commands on machine B now.
$ssh -X username@b.b.b.b
will also allow you to take GUI control.
Try running gedit on the remote machine. The GUI will come on your local machine.