To follow these instructions you must have already jailbroken your iPhone. You can do this using one of the tutorials found here.
Press to launch Cydia from your Springboard.
Press to select the Sections tab at the bottom of the screen.
Press to select Networking from the list of Sections.
Press to select OpenSSH from the list of Packages.
Press the Install button at the top right of the screen.
Press the Confirm button at the top right of the screen.
Once OpenSSH has installed successfully click the large Return to Cydia button.
You may now use ssh to access your iPhone filesystem with the username: root and the password: alpine.