Samura bin Jundab reported,

The Prophet ﷺ said, "When one of you comes upon a flock, if its owner is present, let him ask his permission. If permission is granted, let him milk and drink. If no one is with the flock, let him call out three times. If anyone answers, let him ask permission. If no one answers, let him milk and drink, but he must not carry any away."

Azami 5481

Sahih

عن سمرة بن جندب

أن النبي ﷺ قال: إذا أتى أحدكم على ماشية، فإن كان فيها صاحبها فليستأذنه، فإن أذن له فليحتلب وليشرب. وإن لم يكن فيها أحد فليصوت ثلاثا فإن أجابه أحد فليستأذنه، فإن لم يجبه أحد فليحتلب وليشرب، ولا يحمل.

الأعظمي 5481صحيح
Contents
Reference
Commentary
Ayat
Collection
Jami al-Kamil
Book
Sales
Chapter
Rulings on sales and trade
Section
It is permissible for the wayfarer to eat dates and drink milk when passing by them
Numbering
Jami al-Kamil 5481 (2nd edition)
Azami 5481