A U.S. District Court judge ruled yesterday that the government can end its costly 24-hour protection of Joseph Teitelbaum, a key government witness in the FBI's "Unirac" investigation of Florida crime, because Teitelbaum can afford to pay for his own protection.

Teitelbaum, who since 1977 has been protected by the U.S. Marshals Service and government-financed private guards at a cost of about $3 million, had sought a temporary restraining order to prevent the Justice Department from withdrawing his around-the-clock bodyguards.

However, U.S. District Court Judge Aubrey E. Robinson Jr. denied the request, saying Teitelbaum, who works in the shipping business, "is a man of very substantial means" and "is capable of securing physical protection for himself and for his family pending resolution of this case on the merits . . . . "

A number of shipping officials and union officials from the International Longshoreman's Association were convicted of racketeering in 1979 as a result of Teitelbaum's testimony. Several are still free on bond pending their appeals.

The government had offered to place Teitelbaum and his family under the federal witness protection progam, where they would be moved to a different locations, given new identities and jobs. But Teitelbaum refused, saying he did not want to move away from his community and assume a new identity.

Hamilton P. Fox, Teitelbaum's lawyer, said that although Teitelbaum could pay for protection for a while, it could take weeks before his case is finally resolved, and his client could be in physical jeopardy if he runs out of money to pay bodyguards.

"He may make $85,000 a year [but] the cost of protection is about $200,000" annually, Fox said.