An Uber driver put his concealed carry permit to use Friday night when he pulled a gun and opened fire on a man he saw firing a pistol into a group of people on a Logan Square sidewalk, according to prosecutors.

Six blasts from his gun injured a 22-year-old man identified as Everardo Custodio.

Custodio suffered wounds to his shin, knee and lower back and was still in Advocate Illinois Masonic Medical Center on Sunday, when Cook County Judge Peggy Chiampas refused to grant bail on charges of aggravated battery with a firearm and illegal possession of a firearm.

The 47-year-old Uber driver “was acting in self-defense and in the defense of others,” Assistant State’s Attorney Barry Quinn said.

Custodio, who lives about a block from the site of the shooting, was the only person injured in the confrontation that happened about 11:50 p.m. in the 2900 block of North Milwaukee Avenue.

The Uber driver had dropped off a passenger minutes before the shooting occurred, said Uber spokeswoman Jen Mullin. She had no comment on the driver’s actions other than to say the company requires all its drivers to abide by local, state and federal laws pertaining to transporting firearms in vehicles.

Quinn said the Uber driver, who could not be reached Sunday, was parked in his car when Custodio began firing in his direction, aiming at the nearby group of people.

Police patrolling the area heard the shots and arrived to find Custodio on the ground and bleeding. Police also recovered a handgun found near Custodio, Quinn said.

The Uber driver, who’s from the Near South Side, stayed on the scene and provided documentation of gun ownership to police. He’s a registered gun owner who has a concealed carry license. He doesn’t face any charges.

Uber plans to interview the driver and the passenger he dropped off before the shooting, said Mullin, who did not know where the driver stowed his gun.

The driver was still an active driver for Uber as of Sunday night, Mullin said.