Sayyiduna Abdullah bin Abbas (may Allah be pleased with them both) narrates: One day I was riding behind the Messenger of Allah (peace and blessings be upon him) on his mount. He (peace and blessings be upon him) placed his hand behind me and said: "O boy! Shall I not teach you some words by which Allah will benefit you? 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 seek help, seek help from Allah alone, and when you ask, ask Allah alone. The pens have been lifted and the pages have dried. If all the nations were to strive together to benefit you, they could benefit you only with what Allah has written for you; and if all the nations were to strive together to harm you, they could harm you only with what Allah has written for you."
And Ibn Wahb (may Allah have mercy on him) reported this addition from the narration of others: "Seek nearness to Allah in times of ease, and He will grant you His nearness in times of hardship. And know that in being patient over what you dislike there is much good, and that victory comes with patience, relief comes with distress, and that indeed with hardship there is ease."