Once every other month, journalist Hassan Dahir, 28, leaves his hostel in central Mogadishu under the cover of darkness to visit his mother in Yaqshid district, north-east of the capital.

He will spend the night with her and return to his rented room before dawn.

For the past eight years, Dahir has had to sneak such night time visits to his family for fear of al-Shabaab, who he says have already killed at least five of his close friends.

The city has become so dangerous for Dahir that he could not even attend his younger brother’s funeral last month.

“He was killed in the Bakara market end of last month by unknown gunmen. I really wanted to join my family during the burial but they advised me not go to the site. Al-Shabaab had in the past targeted journalists who went to this cemetery,” says Dahir.

Such is the life of not only journalists but also aid workers, government employees and youth leaders working in Mogadishu. Faced with constant risk of violence and targeted killings, many are forced to leave their childhood neighbourhoods and settle in the city centre and around the “green zone” area near the airport, which is deemed safer.

“The number of journalists who were killed here is uncountable. I have lost five close friends and I think my time is yet to come,” Dahir says. “There is nowhere to escape, the best you can do is to hide within the town and stay vigilant.”

According to the Committee to Protect Journalists (CPJ), Somalia is one of the most dangerous places to be a journalist. In the past four years, the Horn of Africa country has topped CPJ’s impunity index, which ranks states with the worst records for prosecuting those who murder journalists.

Mourners gather at the grave of radio producer Abdihared Osman Aden, who was shot while walking to work in 2013. Photograph: Farah Abdi Warsameh/AP

Al-Shabaab was driven out of Mogadishu in 2011 but still carry out deadly car-bomb attacks and assassinations. The group, which is fighting to overthrow the internationally backed government, sees anyone working with the government, the UN or NGOs as an enemy.

Last month, gunmen shot Sakariye Hadaafow, chairman of Hodan district youth group. Witnesses said he was leaving the mosque after Friday prayers when he was attacked. He died in hospital later that day.

Mogadishu is in the hands of Somali security forces supported by African Union peacekeepers. But al-Shabaab still has indirect control of the city, and has been able to limit people in various ways, from shutting down football pitches to extorting money from local businesses in the form of “tax”.

Cabinet ministers and government officials use bulletproof vehicles and armed security. But civil servants and local staff who work with the UN and other aid agencies have no special protection and are targets.

Last May, local World Health Organization worker Maryan Abdullahi was shot dead by unknown gunmen after she went to Bakara market to do some shopping for her wedding.

“Al-Shabaab targets everyone regardless of their work or affiliation, they are a threat to the existence of the Somali people. That is why they kill innocent people every day,” says Abdifatah Ali Hassan, director of security of Banadir regional administration.

“We are committed to protecting the public from the merciless terrorists and we are confident that we will eliminate their threat from the city and the country at large.

“However, we advise the public and particularly those working with the government and NGOs to take personal safety precautions to avoid being targeted.”

In early February, a car bomb exploded at a busy shopping centre, killing 11 people and injuring 10 others. In such a violent city, Dahir calls his mother twice daily to update her on his safety and whereabouts.

“I have to call her every morning before I get to work and every night before I go to bed,” he says. “During weekends I call her on video via WhatsApp; it feels like we are in two different countries, I never imagined this would happen in Mogadishu.”

It is not always easy to connect with his mother on the phone, especially in the aftermath of big explosions around the area in which he lives. “Whenever there is a blast, everyone is on the phone; sometimes the network is down, so my mother would keep calling me and if my line fails to go through she would assume I am dead,” he says.

Somalia “is particularly dangerous for locals who work for foreign organisations,” says a senior Somali official working with the UN in Mogadishu, who has himself had to live apart from his wife and children for the past six years.

A female African Union soldier conducts a security check on a woman at a food distribution centre in Afgoye, Somalia. Photograph: Tobin Jones/AU-UN/AFP/Getty Images

“Experts and international staff live in heavily fortified places such as the airport and other well-guarded guest houses, but for locals like me there are no such protection measures in place,” he says.

He now lives near the airport, which is home to the AU forces, UN agencies and embassies including the British high commission – and as such one of the most protected zones in the capital.

“As a parent, I feel helpless. If my child falls sick in the middle of the night, there is no way I can go out to see and cuddle him,” he says.

“It is painful to live in fear, I cannot explain to my children why I am not able to stay with them, even though I live in the same city. This sometimes leads to depression and psychological problems not only for me but also for my fellow Somali colleagues working with the UN and other international organisations in Mogadishu.”

Mohamed Mukhtar, 31, left his family in Hamar-Jadid neighbourhood, south-east of Mogadishu, as soon as he started working with the ministry of education in 2014. He now lives in the city centre. “Every time I visit my mother, I receive mixed reaction from her, she feels both happy and worried,” he says. “Happy that she could touch and feel her son but also worried that I might be attacked in the area, so she advises me not to stay long with her.”

It has been almost three months since he last saw his mother. “A government employee was shot in the area a few days after my last visit, about three months ago. So my mother would not allow me to go there anytime soon, but we always keep in touch on the phone and sometimes my sisters come to visit me in my area.”

Al-Shabaab militants detonated two bombs outside the education ministry and then fought their way into the building. Photograph: Nour Gelle Gedi/Anadolu Agency/Getty Images

Mukhtar survived a deadly al-Shabaab attack at the ministry building in April 2015 in which three colleagues died. “Gunmen stormed the offices and made their way up to the top floor where we were hiding,” he recalls. “I jumped from the third floor and fell on the ground and suffered a back injury. Three of my colleagues died in the attack.”

Most Somalians are desperate to rebuild a country plagued by decades of war – and now by multiple terror groups – and are ready to make sacrifices to do so.

“We are trying our best to make sure Mogadishu is safe for everyone, the police are now spread over all the districts and we have a good relationship with the public. It is actually getting better; there were times when the city was divided and al-Shabaab used to control half of it, but they are now defeated and all they can do is to terrorise the people,” says Hassan.

In the meantime, Dahir keeps a low profile and waits for the day when he can go home.

“I feel like I am under a house arrest, I cannot walk freely and I cannot live with my family,” he says. “But I still have hope that things will change in the future.”