Surgeon General C. Everett Koop, in his most explicit public comments on the prevention of AIDS, has asked the nation's physicians to recommend condom use for all sexually active patients unless they are certain their sex partners are free of the infection.

"My moral and religious background has made it difficult for me, as it may be for you, to discuss sexual issues in public," Dr. Koop wrote in an editorial to be published in this week's Journal of the American Medical Association.

He added, however, that unusual frankness is necessary because the "alternative is almost-certain death."

Koop has been the Reagan administration's most vocal and persistant advocate of condom use to prevent transmission of AIDS. In his editorial he writes, as he has in the past, that condoms are not 100 percent effective, but "if correctly used they can dramatically reduce one's risk of exposure."

For the first time, he advises physicians to recommend that condom use be supplemented with a lubricating cream that contains at least 65 milligrams of nonoxynol 9, a spermicide that also destroys the virus. He also urges that doctors teach proper condom use, and, saying that it is "simply too dangerous," Koop suggests that all individuals refrain from practicing anal sex.

"The editorial is a very courageous, forthright attempt to keep the country's doctors up to date on the transmission of a deadly disease," said Cecil H. Fox, an AIDS researcher at the National Institutes of Health. "It's not the type of thing he feels comfortable doing. But he knows there is such an enormous danger that he has no choice."

Koop urged doctors to speak openly with their sexually active patients no matter what their age.

"Some of you find it unpleasant to recommend condoms to young people," he wrote. "So do I. Acquired immunodeficiency syndrome is an unpleasant disease and recommending condoms to those who need protection is preferable to treating AIDS."

Koop wrote that doctors should tell patients that if they have doubts about their sexual partner, they should require the use of a condom. Patients should have doubts about anyone who has had sex with any other partners, he said.

Koop has been strongly attacked by conservatives both within and outside the Reagan administration for his public support of wide use of condoms to prevent AIDS transmission. Critics argue that abstinence is the only sure way of preventing the disease and that condoms can have a high failure rate.

Koop, who has frequently opposed widespread mandatory testing for AIDS infection, instructed physicians to encourage blood tests for anyone whose sexual history makes them concerned that they may have AIDS.

He also wrote that "patients should be informed that physicians are required to keep results in confidence, sharing the information only with professionals who need to know. The physicians should discuss the advisability of notifying a spouse or other sexual contacts."

Koop also urged physicians to remind any woman who tests positive for antibodies to the AIDS virus, HIV, that AIDS may be passed to any child she conceives.

Koop included in his editorial the suggestion that doctors warn their patients to beware of people who belong to organizations that offer "sexual safety because they issue a health card." Such cards are always out of date and such people usually have a reason for being tested, he said.

As of last week, the federal Centers for Disease Control had received reports of 41,770 cases of AIDS in the United States. The Public Health Service estimates that at least 1.5 million other people have been infected with HIV but have shown no symptoms of the disease.