You can train your ears to give you the skills needed to easily play songs by ear.
Exactly how you should train your ears for playing guitar by ear will depend on quite how you want to play. The ear training needed if you want to play pop and rock chords by ear will be different from the ear training suitable for a lead metal guitarist, for example.
Here are some starting points in learning to play guitar by ear using ear training exercises:
1. Develop your relative pitch
Relative pitch is your ability