President Reagan, proclaiming "good news for farming," signed legislation yesterday that would allow the financially troubled Farm Credit System, the nation's largest agricultural lender, to sell up to $4 billion in government guaranteed bonds.

But the president's renewed appeal to Congress to overturn key provisions of the legislation found little support among two backers of the legislation who attended the White House ceremony.

Sen. Richard G. Lugar (Ind.), the ranking Republican on the Senate Agriculture Committee who was singled out for praise by the president, and Sen. Patrick J. Leahy (D-Vt.), chairman of the panel, said afterward they saw no chance that Congress would attempt to rewrite the legislation this year in response to Reagan's plea.

Both men said that after the intense battle the measure provoked last month there was no inclination on Capitol Hill to fight some of the same battles this year.

"It saves the system and is also humane to farmers," said Lugar. "And that was the intent of the legislation."

The president signed the legislation in a Roosevelt Room ceremony yesterday morning, despite his objections to provisions that may add "new and unnecessary spending in this time of deficits." The provisions, which he urged Congress to remove "as soon as possible," included a new secondary market for farm real estate loans and another that would require the Farmers Home Administration to weigh the costs of refinancing loans at lower rates before foreclosing on any farm.

For the most part, the president was upbeat about the state of the nation's farm economy, noting that agricultural exports jumped by 18 percent last year, that surplus stocks have fallen, prices increased and overall farm income reached record levels.

" . . . That doesn't paint a completely rosy picture for agriculture, however," he said, conceding that "pockets of financial stress" remain in farm communities across the country."

Plunging farm prices during the past two years left the farmer-owned Farm Credit System and its network of regional banks with severe losses. Since 1985, the system has recorded losses totaling $4.8 billion and it has projected a loss of $1.4 billion in 1987, a spokesman said.

It initially appealed to Congress for $6 billion in aid to save the lending network from collapse. While the legislation Reagan signed provides $2 billion less, it may be enough to save the system "if it is used right," a spokesman said yesterday.

Since the height of the system's troubles, there has been a sharp decline in farm debt, some of it a result of "borrower flight," as fewer farmers are willing to go into debt to finance their operations. A spokesman for the Farm Credit System said the system's loan portfolio has dropped to $50 billion from a high of $80 billion in 1982-83.

Under the legislation, federal funds can to used to guarantee up to $4 billion in farm loans with the approval of a three-member committee that includes the secretaries of agriculture, the treasury and a farmer with financial experience.

The law also creates a secondary market for sale of farm loans, called "Farmer Mac," patterned after other government sales mechanisms such as Ginnie Mae, which provide for sales of other government-backed loan portfolios.

In return for the government support, the law contains several provisions designed to pressure the farm system to consolidate its 12 regional banks into six, a measure that the spokesman said was prompted by congressional concern about the salaries, some between $100,000 and $200,000, that have been paid to some of the system's top regional bankers.