SOKOTO, Nigeria (Reuters) - Nigeria's battle against Boko Haram will only succeed if it tackles the reasons why people join Islamist militant groups and if the government and its military gain people's trust, U.S. Secretary of State John Kerry said on Tuesday.

"We also know that beating Boko Haram on the battlefield is only the beginning of what we must do," Kerry said in a speech in the northern Nigerian city of Sokoto at the start of a visit to the West African nation.

"Building public trust in government also requires cooperation from the military and law enforcement. Extremism can't be defeated through repression or fear."

(Reporting by Lesley Wroughton; Writing by Ulf Laessing; Editing by Robin Pomeroy)