As you possess a student visa at the current time, it would be advisable for you to ask for a residence permit for students at SEF (Portuguese Foreigners and Border Services), as it will guarantee your stay in Portugal for as long as your degree extends, provided you deliver the proof of the service of enrollment in an educational establishment at the time of applying. Once you graduate, you are given a one-year job search permit to find paid employment in Portugal. If you get employed, you can change your student residence permit to a worker status which allows you to live and work in Portugal. In any of the abovementioned cases, once you complete a five-year residence in Portugal, you will be eligible for applying for a permanent residence permit at SEF.
You can apply for the permanent residency after five years in Portugal. At that time you will need to show some knowledge of the Portuguese language (A2 level) and if you pass the exam, you will be able to obtain the permanent resident card.
Yes, you can apply for permanent residency after holding a student visa for six years in Portugal.