If you can't exploit it, you can't secure it. I don't know if that quote has been said before, but if you are deeply interested about computer security or ethical hacking, that should be your main mantra.
To fully learn how to secure a computer program, you must know how to break it and find vulnerabilities. In relation to this, there is a unique Linux distribution that is primarily created to help teach you about software security, its name is Damn Vulnerable Linux (DVL).

Damn Vulnerable Linux is a Slackware-based distro that is intentionally loaded with broken, ill-configured, outdated, and exploitable software for educational purposes. It is a 1.8GB live DVD that features easily breakable versions of Apache, MySQL, PHP, and FTP and SSH daemons. It also includes a good number of tools to help users compile, debug, and break applications running on these services such as GCC, GDB, NASM, strace, ELF Shell, DDD, LDasm, LIDa, etc. You can install Damn Vulnerable Linux natively on a PC, boot it from a USB flash drive, or install it using any virtualization software.

The link for this article located at Junauza is no longer available.