Yunus bin ‘Abdul A‘laa (rahimahullah) mentions the following:
Hazrat Imaam Shaafi‘ee (rahimahullah) once said to me, “O Yunus! Staying away from people and totally refraining from interacting with them will create enmity in their hearts for you. On the other hand, associating with people too much will cause you to fall into bad company. You should thus adopt the path of moderation by neither associating with people too much, nor completely cutting yourself off from them.”
(Siyar A’laam min Nubalaa 10/89)