Hajjaj bin Farafisa reported,

Abu Abdul-Rahman is Abdullah bin Yazid. I myself saw him on the road, and he greeted me when I was a boy. He traced this report back to Ibn Abbas.He said, Hammam bin Yahya Abu Abdullah, the companion of Basri, also narrated it to me, tracing it back to Ibn Abbas. And Abdullah bin Lahiah and Nafi bin Yazid, both Egyptians, narrated to me from Qays bin Hajjaj, from Hanash Sanani, from Ibn Abbas, though I do not remember precisely which wording belongs to which narrator.Ibn Abbas said, "I was riding behind the Prophet ﷺ when he said, 'Young man,' or 'Little lad, shall I teach you some words by which Allah will benefit you?'I replied, 'Yes.'He said, 'Be mindful of Allah, and He will protect you. Be mindful of Allah, and you will find Him before you. Acknowledge Him in times of ease, and He will know you in times of hardship. When you ask, ask Allah. When you seek help, seek help from Allah. The pen has already dried regarding all that will be. If all of creation joined together to benefit you with something Allah has not decreed for you, they would not be able to do so, and if they joined together to harm you with something Allah has not decreed for you, they would not be able to do so. Know that there is great good in being patient with what you dislike, that victory comes with patience, that relief comes with distress, and that with hardship comes ease.'"

Ahmad 2803

Sahih

حدثنا عبد الله بن يزيد حدثنا كهمس بن الحسن

عن الحجاج بن الفرافصة قال

أبو عبد الرحمن هو عبد الله بن يزيد وأنا قد رأيته في طريق فسلم علي وأنا صبي رفعه إلى ابن عباس أو أسنده إلى ابن عباس قال وحدثني همام بن يحيى أبو عبد الله صاحب البصري أسنده إلى ابن عباس وحدثني عبد الله بن لهيعة ونافع بن يزيد المصريان عن قيس بن الحجاج عن حنش الصنعاني عن ابن عباس ولا أحفظ حديث بعضهم عن بعض أنه قال كنت رديف النبي ﷺ فقال يا غلام أو يا غليم ألا أعلمك كلمات ينفعك الله بهن فقلت بلى فقال احفظ الله يحفظك احفظ الله تجده أمامك تعرف إليه في الرخاء يعرفك في الشدة وإذا سألت فاسأل الله وإذا استعنت فاستعن بالله قد جف القلم بما هو كائن فلو أن الخلق كلهم جميعا أرادوا أن ينفعوك بشيء لم يكتبه الله عليك لم يقدروا عليه وإن أرادوا أن يضروك بشيء لم يكتبه الله عليك لم يقدروا عليه واعلم أن في الصبر على ما تكره خيرا كثيرا وأن النصر مع الصبر وأن الفرج مع الكرب وأن مع العسر يسرا

أحمد 2803صحيح
Contents
Reference
Commentary
Ayat
Collection
Musnad Ahmad
Book
Abdullah bin Abbas bin Abdul-Muttalib
Numbering
Darussalam 2803
Ahmad 2803