Yes babies do surprisingly by instinct know and recognize who their mothers are.
There fathers they don't quite know right away but they begin to eventually recognize them and get used to them.
So if you're a father and your baby acts like it hates you because he or she doesn't want to be held or touched by it's father don't worry or feel bad about it as your baby just hasn't gotten used to you yet and will in time let you hold and touch them.
I'm not sure how they know but I guess it's the sound of the mothers voice that they can hear through the womb.