The mastermind behind a notorious US spy ring which passed secrets to the Soviet Union during the Cold War has died in jail.

Former sailor John Anthony Walker Jr, who sold classified information to Moscow for nearly two decades and recruited his brother, son, and friend in his espionage work, passed away at a prison hospital in Butner, North Carolina, according to federal authorities.

The 77-year-old was just months away from possible release, being eligible for parole in 2015.

Walker was sentenced to life in prison after pleading guilty in 1985 to passing secrets to the Soviets while he was a shipboard communications officer, and after his retirement.

After leaving the service in 1976, he enlisted the help of family members and a Navy friend to keep furnishing the Kremlin with secrets.

Robert Hunter, the FBI agent who arrested Walker, described him as one of the most treacherous men he had ever met.

The security breach was then considered among the largest and most devastating leaks of military secrets in the nation's history.

His spying career started in 1967 when he stole and sold to the Soviets "key cards", which helped the Soviets decipher more than one million encrypted naval messages.

The information Walker passed on was considered invaluable to Moscow, with claims his activities enabled the Soviets to know where US submarines were at all times.

After Walker's arrest, Caspar Weinberger, President Ronald Reagan's Secretary of Defense, said the secrets Walker betrayed gave America's Cold War foe "access to weapons and sensor data and naval tactics, terrorist threats, and surface, submarine, and airborne training, readiness and tactics".

The discovery of his treachery shook the military, and led to the introduction of tougher security measures.

It is estimated Walker earned more than $1m for his work with the Soviets.