Alan Wadi Okengo alias Liutenant Wadi was handed down the prison term after pleading guilty on two counts of hate speech and abusing the Head of State.
The court ruled that he undermined the authority of a public officer by posting the insults against President Kenyatta.
He was also accused of stating that a particular ethnic group should be “deported”, contrary to the National Cohesion and Integration Act.
Milimani Law Courts resident magistrate Ann Kaguru said the harsh penalty would serve as a deterrent measure to others with a similar motive.
Mr Wadi, 25, was accused of posting the messages on his Facebook account on December 18 and 19 at an unknown place within Kenya.
He was arrested while trying to flee the country at the Busia border on December 31, 2014. He was repatriated to Nairobi by the police.