NAIROBI (Reuters) - A South Sudanese general has resigned, citing abuses by the security forces against civilians and what he called increasing ethnic favoritism in the military, according to a letter seen by Reuters on Saturday.

Lieutenant General Thomas Cirillo Swaka, the deputy head of logistics, is the highest-ranking officer to resign since former Vice President Riek Machar fled after his supporters clashed in Juba in July with soldiers loyal to President Salva Kiir.

Swaka, widely known as Cirillo, is respected by the international community and Western governments would see his resignation and the charges he has leveled as an indictment of the government, one security expert in Nairobi said.

South Sudan has been riven by conflict since 2013, two years after seceding from North Sudan. Fighting broke out a few months after Kiir, from the Dinka tribe, sacked Machar, a Nuer. His reinstatement in 2016 lasted just weeks before violence erupted again.

The conflict has increasingly followed ethnic lines, forcing three million people to flee their homes, bringing the nation of 11 million close to famine and leading the United Nations to say South Sudan was on the brink of genocide.

Swaka's letter reinforced those warnings.

"President Kiir and his Dinka leadership clique have tactically and systematically transformed the SPLA into a partisan and tribal army," it read, using the acronym for the government Sudan People's Liberation Army.

"Terrorizing their opponents, real or perceived, has become a preoccupation of the government."

Swaka said the military, police and other security branches systematically recruited Dinka from the president and chief of army staff's home region. Non-Dinkas and Dinkas who disagreed with the president's agenda were given remote postings or sidelined, he said.

He also said "soldiers from the Dinka ethnic group have been strategically deployed and posted in non-Dinka areas to support the policy of land occupation."

Swaka said the military raped and killed civilians and allowed tribal militias to commit the same abuses as well as running a network of secret prisons where torture was endemic.

The government routinely dismisses charges of ethnic bias and blames rebels for stoking trouble. Officials say any soldier committing abuses will be held to account and the president said on Monday any soldier committing rape should be shot.

Military spokesman Brigadier General Lul Ruai Koang did not return calls seeking comment about Swaka's letter. The presidential spokesman also could not immediately be reached.

U.N. officials and Western governments have accused both sides in the conflict of abuses.