This dusty desert capital that was once a backware of the Spanish empire is now a command center for the bitter war Moroccan forces are waging against Saharan guerillas.

Spain relinquished Spanish Sahara, its last major African territory, to Morocco and Mauritania in November, 1975, in a controversial pact that revoked earlier Spanish promise to hold a United Nations-supervised election in the colony. Under terms of the still-secret agreement, called the Madrid Accord, Morocco got the northern two-thirds of Western Sahara and Spain retained a 35 per cent share in the rich phosphate mines at Bou Craa.

Morocco views the agreement as a righting of historic wrongs. "The Sahara is Moroccan," said Brahim Ben Abdallah, an Information Ministry official here. "It has always been Moroccan, and it will stay Moroccan."

Indeed, El Aaiun has become a Moroccan town. In the past 18 months, Morocco has brought in more than 16,000 settlers to replace some 20,000 Saharans who left when Spain pulled out its Foreign Legion.

Moroccan soldiers outnumber civilians in El Aaiun - visible testimony to the war's existence, despite official Moroccan claims that there is no military problem. A third of Morocco's 95,000-man army is deployed in this Colorado-sized territory, and local sources say the bulk of the troops are in and around the capital and the nearby port installations.

A longtime Spanish resident of El Aaiun estimates that only 3,000 to 5,000 native Saharans, mostly old persons and children, remain in the town, the others having fled to refugee camps across the border in Algeria, or retreated to the desert to join guerrillas of the Polisario independence movement.

Heavy security precautions are visible everywhere.Airplanes approaching the capital at night turn off their running lights before coming in overland from the Atlantic. Armed soldiers at street corners caution a visiting journalist against taking photographs.

The town itself is surrounded, and military officials require government permission from anyone wanting to enter or leave. Several times a day conversation stops while jet bombers roar overhead on missions over the interior.

Despite the evidence of a conflict, Moroccan officials insist that all is normal. "The Saharan provinces do have problems," said Hassan Ouchen, the No. 2 Moroccan official in the province. "But they are economic, not military.

A different story was told by three Moroccan soldiers during an interview. The three, who declined to be identified or photographed, said the situation in Western Sahara was all out war.

"I was in Sahara for two months," said one. "It is often bombarded. The guerillas hide in the hills and shell us. We fire back, but they can see us and we can't see them. What can we do?"

All these soldiers said it was impossible to leave the El Aaiun area except by air or armed convoy. They also disputed Moroccan charges that Polisario units are composed mostly of soldiers from neighboring Algeria, whose socialist government supplies the guerrillas with Soviet-made arms. "We have seen only Saharan," said one. "They say this is their country and they want it back.

Ouchen said the Moroccan government has committed itself to ambitious development projects, including the construction of a trans-Saharan highway scheduled to connect Saharan towns with major points in Morrocco. He said an airport large enough for Concorde airplanes has recently been completed in the town of Smara, and denied the necessity for special territory.

The number of casualties in this war is impossible to determine, because figures from both sides are unreliable. None of the soldiers would venture a guess, saying only that death rates were "high."

Morocco has released no official statistics for more than a year, admits to no casualties, and takes its time about informing next of kin. Polisario says its forces have killed, wounded, or captured 14,000 Moroccans and Mauritanians. Front official admit privately, however, that Polisario figures are often guesses base on bombardments from afar.

A Moroccan sutdent group that claudestively opposes the war says that at least 50 Morrocans a month have died in the Sahara in the last year. Journalists who have traveled with guerrillas generally believe that Polisario losses are far lower - perhaps five to 10 a month on the average.

The increasing boldness of the guerrillas, who are outnumbered 5 to 1, is a major embarrassment, both to King Hassan 11 of Morocco and to President Moktar Ould Daddah of Mauritania. The king has staked the reputation of his throne on a successful conquest of what he calls "Le Grand Maroc." To insure support from Morocco's political parties, who have long chafed under his authoritarian power, the king has scheduled the first elections for a National Assembly since 1972.

But retaining support at home for the Saharan annexation may prove difficult if the ar drags on, according to diplomatic sources in Rabat. A third of last year's budget went for military expenditures, a fact that was partically responsible for the king's decision to reduce by 1975 per cent a longstanding subsidy of food staples. The decision provoked strikes and protests throughout Morocco.

This year, military spending is scheduled to be $733 million, a further 50 per cent increase over 1976. Inflation is 12.5 per cent and rising.

"We talk to people in the countryside," said a Western diplomat. "They find their lives growing more difficult, and they're losing their sons in an underclared war."

Mauritanian concern is even more intense. Travelers arriving from Mauritania's capital of Nouakchott report an air of near-panic among the local population following Polisario's May Day raid on the iron mining center of Zouerate - one of the most heavily fortified spots in Mauritania. The attack left two French and a Mauritanian captives.

In recent months, Mauritania has been force to rely increasingly on Moroccan air and ground support, a fact that is disturbing to many Mauritanians, who remember that only recently Morocco's claims to "Le Grand Maroc" included all of Mauritania as well as Western Sahara.

For all sides in this war the stakes are high. Algeria could expect a friendly government in Western Sahara to allow it access to the Atlantic to export iron ore from Algeria's southern desert.

Morocco is counting on the territory's economic resources to boost its own growth. Already the world's foremost exporter of phosphates. Morocco hopes with the addition of the Saharan reserves to be able to force world prices up. The deposits at Bu Craa contain some 1.7 billion tons of exceptionally pure phospates - at least another century and to give the Sahara a per capital income better than many industrial nations.

So far, the mineral has been of little value to Morocco. Polisario attacks have stoped the 60-mile-long convey or belt that carries phosphates to port, and have hampered Moroccan attempts to move them by convoy.

It is difficult to find anyone familiar with the region who believes the tensions will abate soon, and many express fears that the Saharan war will ignite a conflict that could engulf northwestern Africa.

Both the United Nations and the Organization of African Unity have found the dispute too hot to handle. The U.N. has passed contradictory resolutions concerning the territory's future, and the OAU has postponed a scheduled special summit to consider the problem. African diplomats say privately they fear a summit would split the organization, nine of whose members have already recognized Polisario as Western Sahara's legitimate government.

Meanwhile, the little-understood war continues, with none of the combatants showing any intention of compromise. "We are here now where we belong, and we will never leave," said Brahim Ben Abdallah. "Of that you can be sure."