Seifeddine Rezgui came from the town of Gaafour in the Siliana region, the country’s prime minister, Habib Essid, said yesterday.
He had been a student at the University of Kairouan and had never travelled abroad.
Rezgui’s uncle said that he was “just like the other young men” who liked to play football or go to a cafe after praying in the local mosque.
He liked breakdancing and was well known for entering competitions in the capital Tunis, Ali Al-Rezgui said.
Referring to the practice of devout Muslim men not shaving their beards, Al-Rezgui said: “He didn’t even have a beard.”
He added: “We were all shocked when we heard the news and saw his picture, and his mother was devastated.”
Neighbours suggested the gunman may have been brainwashed.
Monia Riahi, 50, who is a neighbour and family friend, described him as “good, good, good”.
She said: “I’ve known him since he was small. He was never in trouble with anyone ever. Maybe he was brainwashed or something.”
It was reported that Rezgui’s father, who is a day labourer working on farms or the nearby railway line, had been taken to the Tunisian capital for police questioning.
Neighbour Ammar Fazai, 64, said: “I think maybe, just maybe, it was poverty that did it.”
However, other reports said that Rezgui had posted extremist messages on social media, praising jihad.
Kairouan resident Salah Korbia said that Rezgui and his four flatmates, thought to be students, were not welcome in the town due to their conservative ideology.
Images have emerged of the gunman standing barefoot on the beach dressed in a black T-shirt and shorts, with a gun in his hand.
Photographs taken after the attack appeared to show Rezgui’s body after he was shot by police.