Anas (radi Allahu anhu) said: When the companions of the Prophet (sal Allahu alaihi wa sallam) met they would shake hands with one another, and if they came from a journey they would embrace one another.
[Al-Tabaraani in al-Awsat (1/37); classed as Sahih by Shaykh al-Albaani in al-Silsilah al-Saheehah, 2647]
We benefit from the above narration that embracing (i.e. hugging) is permissible when someone comes from a journey or after a long absence, or to express one’s deep love for the sake of Allah and so on.
It was also narrated from Awn ibn Abi Juhayfah that his father said: When Jafar (radi Allahu anhu) came after he had migrated to Abyssinia, the Prophet (sal Allahu alaihi wa sallam) embraced him and kissed him between the eyes. [Al-Tabaraani in al-Kabeer (2/108); there are many corroborating reports which were mentioned by al-Haafiz ibn Hajar in al-Talkhees al-Habeer, 4/96/ it was classed as Sahih by Shaykh al-Albaani in al-Silsilah al-Saheehah, 2657]
Shaykh Muhammad Naasir al-Deen al-Albaani (may Allah have mercy upon him) said: “This indicates that the Sahaabah differentiated between whether a person was present or travelling in the manner in which they greeted him. In the first case (when a person was a resident) they shook hands, and in the second case (when a person had come from travelling) they embraced him.” [Al-Silsilah al-Saheeh, vol. 6, section 1 (305-307)]
And Allah knows best!