Outbreak-control experts are working to trace the source of the potentially deadly infection, caused by legionella longbeachae - a form of the bacteria more commonly found in Australia.
The four patients affected, who are in the NHS Lothian area, are aged between 62 and 84. The two who are seriously ill attended hospital but have been discharged. Symptoms include headache, diarrhoea and a dry cough followed by pneumonia.
It is particularly common in Australia, where bags of compost carry warnings about the bug, but cases have also been identified in the UK, the US, Greece and Japan.
Most victims recover after treatment with antibiotics, but those with underlying medical problems are more vulnerable.
It is distinct from legionella pneumophila, the bacteria that causes legionnaires' disease.
The exact way that legionella longbeachae infection is passed from compost to people is not yet known, but is assumed to be through breathing in dust particles from contaminated soil or spread from hand to mouth.
It is not transmitted from person to person or animal to human and, unlike the legionnaires bug, has not been traced to water vapour from cooling towers or ventilation systems.
The bacteria can remain on hands contaminated by handling potting mix for periods of up to one hour, but can be easily removed by washing.
Dr Richard Othieno, Consultant in Public Health and Chair of the Incident Management Team for NHS Lothian, said: "This type of legionella is quite rare in that unlike other strains it has never been identified in man-made water systems, like cooling towers.
"We are working with experts to trace the source of the infection and samples of the compost have been sent for testing.
"We know that each of the four cases are keen gardeners who had purchased different products containing compost prior to acquiring the infection.
"Gardening is a healthy hobby but there are risks and it is important that people take some simple precautions when working with gardening products.
"I would like to add further reassurance that the risk to the wider public is low."
Anyone handling garden mixes such as potting mix, mulches, composts or garden soils, whether bagged or unbagged, is being urged to follow instructions.
Gardeners should open compost or potting mix bags carefully, preferably with a blade, and wear gloves when handling compost.
If gardeners are in greenhouses or sheds, keep the door open when potting-up plants or filling hanging baskets and wear a mask if the air is dusty.
They should also wash their hands immediately after handling compost or before smoking while gardening, as this is also believed to increase the risk of infection.
While a statement by NHS Lothian said the risk of infection is not limited to gardeners, the use of potting mixes, composts and other soils puts them at greater risk.
However, the health board added that the numbers infected to date compared to the area's likely population of gardeners suggests the chances of becoming infected is not high.
There is no link between the current legionella outbreak and the outbreak of legionnaires' disease in Edinburgh last year, which killed four people and infected almost 100.