(CNN) A man has confessed to an attack near a German synagogue in which two people died.

Named as Stephan B, the man appeared before an investigative judge at the Federal Court of Justice in Karlsruhe, Germany. Markus Schmitt, press officer of the prosecutor at the court, said: "Stephan B. has admitted to the accusations and specifically to his anti-Semitic as well as right-wing extremist motives."

A gunman killed two people in the German town of Halle , one directly outside a synagogue and one at a nearby kebab shop. The attack happened on Wednesday, Yom Kippur, the holiest day in the Jewish calendar.

Streaming live from a camera mounted on his helmet, he pushed on the doors of the synagogue, fired several shots at a lock on the door, stuck an explosive in a door jam and lit it but could not get in -- a fact that likely spared dozens of lives.

Watching it unfold on the synagogue's security cameras were 51 people barricaded inside, Max Privorozky, the head of Halle's Jewish community, told CNN.

An image of the alleged synagogue shooter shared on social media.