I have these bumps on my face from shaving years back. They are hard but painless. How can I get rid of them?

Pseudofolliculitis. Sounds like pseudofolliculitis barbae which is caused by ingrown hairs from shaving. This condition can be helped with laser hair removal.
Steroid injections. Razor bumps are produced by ingrown hairs that produce a foreign body inflammatory reaction followed by severe scarring. Steroid injections can sometimes reduce hypertrophic scarring. If the scarring is extensive, you may require surgical excision.
Facial lesions. The answer depends a lot on the nature and cause of the "bumps". Without examining you it's difficult to recommend the best solution, but multiple treatment possibilities exist, including: steroid injections to soften/flatten the bumps, surgical excision of the masses, or possibly even resurfacing procedures with derm abrasion or an ablative laser.