Abu Saeed Khudri reported,

The Prophet ﷺ said, "When you come upon a shepherd, call out to him three times. If he answers you, well and good. Otherwise, drink without causing any damage. And when you come upon the wall of an orchard, call out to its owner three times. If he answers you, well and good. Otherwise, eat without causing any damage."

Azami 5483

Sahih

عن أبي سعيد

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

الأعظمي 5483صحيح
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 5483 (2nd edition)
Azami 5483