If you are a visiting student and study for more than one year, you are entitled to the same medical benefits as Swedish citizens. However, you must first register with the tax bureau and obtain a personal social security number (Swedish name is "personnummer"). Please apply as soon as you arrive in Sweden.
2. Medical insurance for non-EU/EEA students: the residence period shall not exceed one year.
If the residence permit is valid for less than one year, you can't get a personal social security number (Swedish name is "personnummer"), and you can't get Swedish medical security services for free. However, Sweden has reciprocal agreements with some countries on public medical benefits. To find out whether your country has this agreement with Sweden, please contact your social insurance department.
Further reading: How to buy insurance, which is good, and teach you how to avoid these "pits" of insurance.