Part of it is pure luck - being at the right place at the right time. An on site internship gave me a foot in the door for my first remote job. After that, I had experience in a certain niche and a couple of open source contributions under my belt.
Another part is just having the guts to ask for a remote job straight away and accept getting turned down dozens of times.
Another part is just having the guts to ask for a remote job straight away and accept getting turned down dozens of times.