legendary shards in destiny 2 replace Strange Coins from the original Destiny as the currency used by Xur, the exotic Vendor. During gameplay you will encounter lots of opportunities to earn these precious trinkets but the most common and consistent way to get them is by breaking down Legendary Weapons, Armour, or by completing weekly activities.
Another way you can get legendary shards is by completing the Lost Sectors on all four planets and although the loot will not refresh you will want to complete all the Lost Sectors in every area with all three of your characters to collect the extra one-time-only Shards on offer.
If you find yourself really desperate for legendary shards you can grind Strike Bosses and Planetary Chests for them but this should only be a last resort as they are hard to come by using these methods.
The best method of getting legendary shards is to keep earning Legendary gear from Crucible matches, Legendary Engrams, and any of the end-game activities. Legendary Weapons and Armour always give 2 Legendary Shards.
Below is a a legendary shards farming guide:
Break Down Legendary Weapons / Armour: 2 Shards
Break Down exotic Weapons / Armour: 10 Shards
nightfall strikes, Flashpoints, Lost Sector Chests, Raid Chests, Raid Encounters, Strike Bosses, Planetary Chests: Random