The Prophet ﷺ said, "When one of you marries a woman or buys a servant, let him say, 'O Allah, I ask You for her good and the good of the disposition You have given her, and I seek refuge in You from her evil and the evil of the disposition You have given her.' And when he buys a camel, let him take hold of the top of its hump and say the same."In another wording, "When one of you acquires a woman, a servant, or a riding animal, let him take hold of its forelock and say," then he mentioned the rest of the hadith.
عن النبي ﷺ قال: إذا تزوج أحدكم امرأة، أو اشترى خادما فليقل: اللهم إني أسألك خيرها، وخير ما جبلتها عليه، وأعوذ بك من شرها ومن شر ما جبلتها عليه، وإذا اشترى بعيرا فليأخذ بذروة سنانه وليقل مثل ذلك. وفي لفظ: إذا أفاد أحدكم امرأة، أو خادما، أو دابة، فليأخذ بناصيتها، وليقل: فذكر الحديث.
Abu Dawud (2160), Ibn Majah (1918), Ibn Sunni (100), Hakim (2/185), and Bayhaqi (7/148) all narrated it, all of them through the hadith of Muhammad bin Ajlan, from Amr bin Shuayb, with his chain of transmission, in like manner. Hakim said, "This is a sahih hadith based on what we have mentioned regarding the narration of the trustworthy imams from Amr bin Shuayb, though the two of them [Bukhari and Muslim] did not include a narration from Amr in their two books." Its chain is hasan due to what has been said about Muhammad bin Ajlan and about his teacher Amr, though both of them graded the hadith hasan.