It's difficult to know if the person you're talking to online is really who they say they are. The only way to be completely sure is if you know the person in question outside of the internet (in real life).
Having said that, there are a few signs to look out for that could mean the person you're talking to isn't really who they say they are, or have questionable motives for speaking to you.
You should always think twice about speaking to strangers on the internet. In particular, those who simply contact you saying "Hi" are ones to look out for.
It may not always be the case, but some people introduce themselves to people on the internet in order to engage in a conversation that will ultimately lead to a scam of some sort. If someone introduces themselves for no apparent reason, be aware of this fact.
This method is only appropriate to social media websites, but can be useful in distinguishing whether or not the person you're talking to is who they say they are.
If they're speaking to you from a social media platform, you can look at their profile to see their other online activity and past history. For example, if their Facebook profile has been active for a long time, and is full of interactions with family members and friends, it's more likely that they're who they say they are than someone with a blank profile.
Check their email address
You can try to verify someones identity if you have their email address.
For example, if they've started chatting with you, and you want to know if the email address they're using is associated with any social profiles, then you can run it through a website called Full Contact (https://www.fullcontact.com/) and it will highlight any Facebook, Twitter or LinkedIn accounts created using that email address.
Other than that, there aren't really any ways to tell if the person you're talking to online is the person they say they are. My advice is to stay vigilant online at all times.
Unfortunately, there are plenty of people out there wanting to take advantage of people over the internet. Never send money to people or give out personal information.