President Barack Obama early on Thursday signed legislation that ends a US government shutdown and raises the US debt ceiling, the White House said.