Facebook and Twitter are siding with Apple in its fight against a court order requiring the company to help investigators break into an iPhone used by one of the San Bernardino mass shooters.

A US magistrate has ordered Apple to produce software that would give investigators access to the iPhone at issue.

Apple has until Tuesday to challenge the order, setting the stage for a legal clash that experts say could change the relationship between tech companies and government authorities in the US and around the world.

Syed Farook and his wife Tashfeen Malik killed 14 people in a December 2 shooting at a holiday lunch for Farook's co-workers.

The couple later died in a gun battle with police in San Bernardino, California.

Twitter's chief executive Jack Dorsey tweeted that the microblogging site stands with Apple and its chief executive Tim Cook and thanked Mr Cook for his leadership.

Facebook said it condemns terrorism and also appreciates the essential work of law enforcement in keeping people safe.

But it said it will "fight aggressively" against requirements for companies to weaken the security of their systems.

"These demands would create a chilling precedent and obstruct companies' efforts to secure their products," it said.

The government is not asking Apple to help break the iPhone's encryption directly, but to disable other security measures that prevent attempts to guess the phone's passcode.

Mr Cook argues once such a tool is available, "the technique could be used over and over again, on any number of devices," even as law enforcement insists that safeguards could be employed to limit its use to that particular phone.

He has posted a 1,117-word open letter on how the FBI's request might have implications "far beyond the legal case at hand".

Civil liberties groups warned the fallout from the San Bernardino dispute could extend beyond Apple.

"This is asking a company to build a digital defect, a design flaw, into their products," said Nuala O'Connor of the Centre for Democracy and Technology, a group that has criticised government surveillance.

The Washington-based centre warned that other companies could face similar orders in the future.

Others said a government victory could encourage regimes in China and other countries to make similar requests for access to smartphone data.

Apple sells millions of iPhones in China, which has become the company's second-largest market.

Sign up to our free newsletters

Get the best updates straight to your inbox:
Please select at least one mailing list.

You can unsubscribe at any time by clicking the link in the footer of our emails. We use Mailchimp as our marketing platform. By subscribing, you acknowledge that your information will be transferred to Mailchimp for processing.