Apple requires that all code on an iOS device is signed. This is mostly to make it impossible for programs running through Apple's App Store to download more software and run it (so no competition for App Store).
To get around this (and thereby to install our own code onto the device), jailbreaks patch the signature verification out of the kernel. However, another half of the codesign problem is that the binary contains a number of SHA1 verification hashes that are checked in numerous locations throughout the kernel. Patching this out is difficult (especially to track as Apple makes changes) and of marginal benefit as adding these hashes is easy. There are currently three viable options.
Option #1: Self-Signing
This method is the simplest to understand: using Apple's codesign tool to sign the binary. Because the signature verification checks have been removed from the kernel, any signature, including those not authorized by Apple, can do this. For instructions on how to make a self-signing certificate you can read this article from Apple's website: Obtaining a Signing Identity.
From your desktop Mac:
codesign -fs "Name" Program
scp Program mobile@iphone:
Where Name is the name on the certificate you created and Program is the name of the program. Be sure to be in the program's directory before executing.
Option #2: Pseudo-Signing
If you do not use a Mac, the previous option just doesn't work. The entire codesign path requires not only a Mac but desktop access because codesign is, at some level, a graphical utility (the way it uses Keychain to get the signatures may prompt, with dialogs, for passwords). To get around this, saurik wrote a tool called ldid that, among other things, can generate the SHA1 hashes that are checked by Apple's iOS kernel. This tool is easily installed on the iPhone using Cydia or APT.
From your iPhone terminal:
apt-get install ldid
scp user@desktop:Program .
ldid -S Program
Option #3: Disable Checks
Finally, an option that is convenient for development purposes. This disables more than just the codesign check, and it is also more disabling the penalty than the check itself. In some cases, this may cause problems: being unable to connect to insecure Wi-Fi networks being the largest. This is done by using sysctl to deactivate the enforcement and can be undone either by resetting the variables back on or by rebooting.
From your iPhone terminal:
sysctl -w security.mac.proc_enforce=0 security.mac.vnode_enforce=0
(to undo, either use =1's or reboot)
This method no longer works for iOS 4.3 and newer, due to the settings being read-only.