Characters come into their own when I first hear them speak. And that's how I primarily write dialogue - it bubbles up from the unconscious part of my brain that is always at work. I may be crap at finding endings but putting words in characters' mouths has always felt natural.
But like any other part of the craft, there is some element of science here too. Here are some technical suggestions:
1. Don't rely too heavily on dialogue to carry plot or develop character.
2. Less is more. Three lines of dialogue? Odds are you need only one. Remember: what is left unsaid is often more powerful than what is said.
3. Dialogue gets good when it isn't straight forward. When characters lie or hold back or speak at cross purposes. This is how you bake in irony, double meanings, and conflict, thereby making the scene more layered and interesting.
4. Don't underestimate the power of indirect speech. It proceeds at a swifter pace - helpful if your characters have a lot of talking to do - and is easier to nail than direct dialogue.
5. Dialogue should multi-task. If dialogue reveals character and ratchets up tension, if it propels the plot forward and makes you laugh, then it's all much more interesting.
6. Read the work of other writers and see how they go about it.
7. Listen closely to how real people speak. Listen to rhythm and cadence, how thoughts are phrased, the way people of different ages and backgrounds sound. Pay enough attention and you'll develop an ear for dialogue and an instinct for crafting it. Also, you can straight up just steal things you overheard friends and strangers saying.
8. Which is not to say that your characters should speak the way real people do. For one thing, we talk way too much in real life. Fiction has to seem realistic without actually being realistic. Allow a sentence to stand in for a monologue. Sure, in the first draft, write all the pauses and ums and uhs and verbal ticks and quirks of accent into a character's speech. But then later, when you're revising, delete, delete, delete and just leave a few things behind, a little bit of seasoning to give the reader a taste.