It is narrated from Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) that the Messenger of Allah (peace and blessings be upon him), while he was riding behind him (peace and blessings be upon him) on his mount, said: "O boy! I am going to tell you a few words: Be mindful of Allah, and Allah will protect you. Take care of the rights of Allah, and you will find Him before you. When you ask, ask Allah alone, and when you seek help, seek help from Allah alone. The pens have dried and the pages have been lifted. By the One in whose hand is my soul! If the entire Ummah wanted to benefit you, it could benefit you only with what Allah has written for you; and if it wanted to harm you, it could harm you only with what Allah has written for you."
The name of Abu Shurayh is Abd al-Rahman bin Shurayh al-Misri al-Ma'afiri al-Iskandarani, and he is one of the narrators of the Sahih (al-Bukhari and Muslim).
Imam Ahmad (may Allah have mercy on him) narrated this hadith via Yunus from Layth, like the hadith of Abu Shurayh.
Also via Yahya bin Ishaq from Ibn Lahi'ah, from Nafi' bin Yazid, and via Abdullah bin Yazid al-Muqri from Ibn Lahi'ah, from Nafi' bin Yazid, from Qays bin al-Hajjaj, with the like of it.
And Imam al-Tirmidhi (may Allah have mercy on him) also narrated it.
His narration is abridged, along the same lines, via Ahmad bin Muhammad bin Musa from Abdullah bin al-Mubarak, from al-Layth and Ibn Lahi'ah.
And via Abdullah bin Abd al-Rahman from Abu al-Walid, from al-Layth bin Sa'd; and Imam al-Tirmidhi (may Allah have mercy on him) said: "This hadith is hasan sahih."