Reuters

FOR all its paradisal waters, golden dunes and swanky “eco-lodges”, life in Kenya's coastal district of Kiunga, just a few miles from the border with Somalia, is hard. The place is remote, hungry and thirsty. The harvest and the wells have failed again. Fishermen have no boats, only frayed nets cast from shore. Their catch rots for want of refrigeration. But what makes the village elders more nervous than anything is their proximity to Somalia.

During a war in the 1960s between Kenya and Somali bandits, known as “shifta”, who were egged on by Somalia, Kiunga was evacuated. These days a rough track, impassable during the rains, barely connects the two countries. The border has been closed since December 2006, when jihadist fighters in Somalia retreated headlong from Mogadishu, the capital, and Kismayo, a southern port, into the mangrove swamps around Ras Kamboni, just inside Somalia. There they were shredded by Ethiopian artillery and American air raids.

An attack on Kenya by Somali jihadists based near the border is unlikely. Resurgent fighters still train there but look north. They belong to the Shabab (Youth), the armed wing of the former Islamic Courts Union that was all but wiped out two years ago. The presence of hated Ethiopian troops in Somalia, together with a corrupt and hapless transitional Somali government, gave the Shabab a chance to regroup.

Money and arms from Eritrea, which wants to use Somalia to hurt Ethiopia, as well as from some Arab countries, enabled it to recruit. Several thousand have signed up in the past year. They attend large training camps in southern Somalia where one of the instructors is said to be a white American mujahideen. They are expected to disavow music, videos, cigarettes and qat, the leaf Somali men chew most afternoons to get mildly high. Thus resolved, they wrap their faces in scarves and seek to fight the infidel. In return, they get $100 a month, are fed, and can expect medical treatment and payments if they are wounded, as well as burial costs and cash for their families if they are killed.

The Shabab now controls much of south Somalia and chunks of Mogadishu. It took Kismayo a few months ago. The port of Marka, which takes in food aid, fell more recently. Many fighters are loosely grouped around two older jihadist commanders with strongholds near Kenya's border, Mukhtar Robow and Hassan Turki.

Mr Robow celebrated the recent festival of Eid al-Adha by hosting prayers in Mogadishu's cattle market. How sweet it would be at Eid, he told the gathering, if instead of slaughtering an animal in praise of Allah, they would slaughter an Ethiopian. On a visit to Marka he was only slightly less belligerent. He urged reconciliation—except with enemies of Islam. There are many of those, it seems. Hundreds of Somali aid workers, human-rights campaigners and journalists have been killed or exiled. Foreigners have been shot and kidnapped, in two cases just across Somalia's border, in Kenya and Ethiopia. Where it cannot exert control, the Shabab excuses banditry. Borrowing tactics from Afghanistan's Taliban, it spreads chaos to build a new order.

The Shabab has learnt from its mistakes in 2006, when it was overwhelmed in a few days by the Ethiopian army. It is now more pragmatic and more aggressive. This time round, it is apparently not picking fights with wealthy qat merchants. Men can chew what they like—but won't be “clean enough” to get a lucrative job in Kismayo's port. Education is encouraged. Girls can go to school. Charcoal burning is forbidden for the sake of the environment.

But the Shabab has also tightened its own security. Alleged spies for the transitional government or for Ethiopia are routinely beheaded with blunt knives. Mr Turki, the jihadist leader who lives mostly in the bush near the Kenyan border, sleeps in different houses when he is in a town. Public floggings and executions strike fear. So do masked faces. “Before, we knew who killed our relatives,” says a Kismayo merchant. “Now we don't even know that.”

Most tellingly, the Shabab has learnt how to get hold of money faster. It concentrates its fighters in towns where there is money to be earned. The aim is to create an army that puts Islamist identity above divisive clan loyalties. Shabab commanders say a pious state will emerge once weaker militias have been disarmed. Some reckon that the Shabab shares some of the ransoms earned by pirates who operate out of the central Somali port of Haradheere. Those in Puntland, farther north, are apparently beyond the Shabab's reach.

Ethiopia says it will withdraw its troops within weeks, once ships evacuate the 3,000 Ugandan and Burundian peacekeepers under the African Union's aegis holed up in Mogadishu. Somalia's transitional government looks even feebler than before. This week the president, Abdullahi Yusuf, an ageing warlord, sacked his prime minister, Nur Hussein, blaming him for what the president called a corrupt, inept and traitorous government. Mr Hussein refused to resign, and won a vote of confidence in parliament. Mr Yusuf went ahead and appointed his own prime minister anyway. More factional fighting beckons.

The UN says Somalia is the world's worst humanitarian emergency. Some 3.2m people are said to need aid. The UN, which says 40,000 Somali children could soon starve to death, expects fighting over food to break out, another reason the Shabab wants to control the ports. Pirates make it hard to deliver aid. Their activities may be curtailed after the UN Security Council this week let foreign governments chase pirates in Somalia itself as well as at sea. But the piracy will probably continue as long as the catastrophe on land does.

George Bush's administration backed some of Mogadishu's worst warlords as part of its war on terror. President Obama will have to take a new tack. The AU force has proved ineffective but a bigger or more robust intervention, by America or any other country, is not expected; this week Condoleezza Rice, America's secretary of state, called in vain for UN peacekeepers to be sent. A new American administration is unlikely to urge negotiation any time soon with the Shabab; it is still listed as a terrorist group by the Americans and may indeed shelter al-Qaeda people. It may have sleeper agents in Kenya and even in Britain. It has certainly become stronger.