At least four people were killed in a gun attack by suspected militants on a checkpoint east of the Libyan capital Tripoli on Thursday, a local official and a resident said.