Defense Department officials yesterday angrily denied charges that they have been indifferent to the homeless, saying that they offered military facilities as shelters in 600 communities but were rebuffed in almost every instance.

But a Montgomery County official said yesterday that high-ranking Army officials for 18 months refused his request to set up a shelter for the homeless at the Walter Reed Army Medical Center annex in the Forest Glen section of the county. Charles L. Short, who oversees Montgomery's shelter program, finally won agreement yesterday to create a 20-bed shelter in former military police barracks at the annex.

The county plans to spend $20,000 refurbishing the barracks after it negotiates a lease with the Army Corps of Engineers, which will probably call for no rent or only a token amount. The shelter could open as early as Nov. 15.

A local Catholic charities group plans to operate the Forest Glen site and three other shelters at an annual cost to Montgomery of $140,000, Short said.

A Defense Department official in charge of the homeless program, Gerald B. Kauvar, last night acknowledged that some Walter Reed officials who negotiated with Short "were not as forthcoming as they might have been." But he said that such disputes and delays were rare nationwide.

The General Accounting Office reported on Wednesday that the Defense Department was given $8 million to spend on shelters for the homeless during the last fiscal year, but instead spent almost all of it on routine maintenance. Rep. Ted S. Weiss (D-N.Y.), who chairs a subcommittee that held hearings on the government's aid to the homeless, called the situation "just shocking."

Pentagon officials yesterday agreed that they spent $7.1 million of the $8 million on routine maintenance. But they said they did so with congressional approval and after trying unsuccessfully to find communities wanting help.

"Of all the programs we have in the Department of Defense, none has received a higher priority from me, or the secretary of defense, or the president," Lawrence J. Korb, assistant secretary of defense for manpower, installations and logistics, said. "I know of no case where we have been asked and have not been able to provide our facilities."

Kauvar said that the military identified 600 unused barracks, chapels, garages and other buildings that could be converted into shelters and then wrote to local authorities in all 600 communities. He said most rejected the department's offer, with local officials saying either that they had no need or did not have enough funds to operate a shelter.

In a few cases, Kauvar added, local communities refused because they feared shelters would attract homeless people to their towns.

Korb and Kauvar both attacked Weiss for holding a hearing without inviting the Pentagon to testify, with Korb saying he was "outraged." The hearing was before the intergovernmental relations and human resources subcommittee of the House Committee on Governmental Relations.

Weiss explained yesterday that his main complaint was against President Reagan and the Department of Health and Human Services, not the Pentagon. But he also said that many local base commanders were unenthusiastic about sheltering the homeless and set conditions that local groups could not meet.

Kauvar, who said six shelters have now been created, also said he thought most local base commanders embraced the program. But he acknowledged problems in two cases, including Montgomery County.

In Montgomery's case, Walter Reed's commanding general rejected the county's proposal twice during the past 18 months, Short said.

"The first time, the Army said it wouldn't be appropriate," Short said.

He said the Army rejected the shelter conversion as too costly and said it would threaten the building's historic value and security at the annex.

Short responded early this year by pointing to the county's success with a similar shelter that opened last November in downtown Bethesda. "We went back to Walter Reed, requested the shelter again, and asked them to reconsider," Short said.

Walter Reed's Maj. Gen. Lewis A. Mologne rejected that request, according to Short, saying the Army was considering tearing down the barracks.

Then, on Sept. 11, after appeals by Rep. Michael D. Barnes (D-Md.) and Sen. Paul S. Sarbanes (D-Md.), the Washington-based National Citizens Committee on Food and Shelter and others, the Army and the county reached an accord that was finalized yesterday morning.

"The Army is very clearly behind this now," said Short. "The building is just perfect for a shelter."