Ruling on male student shaking hands with a female classmate
Question

What is the ruling on a male student shaking hands with a female classmate? What should he do if she holds out her hand to greet him?
Praise be to Allah.It is not permitted to study in a mixed setting with female students in one place or in one school or on one bench. This is one of the greatest causes of fitnah (temptation) and it is not permissible for a male or female student to take part in this, because of the fitnah involved. The Muslim should not shake hands with a non-mahram female, even if she holds out her hand for him to shake, and he should tell her that shaking hands with a non-mahram man is not permitted, because the Prophet (peace and blessings of Allah be upon him) said, when accepting the allegiance (bay’ah) of women: “I do not shake hands with women.” And it was narrated that ‘Aa’ishah (may Allah be pleased with her) said: “By Allah, the hand of the Messenger of Allah (peace and blessings of Allah be upon him) never touched the hand of any (non-mahram) woman; he used to accept their allegiance in words only.” And Allah says (interpretation of the meaning): 
“Indeed in the Messenger of Allah (Muhammad) you have a good example to follow for him who hopes for (the Meeting with) Allah and the Last Day, and remembers Allah much” [al-Ahzaab 33:21]
For a woman to shake hands with someone who is not her mahram is something that may lead to temptation for both parties, so it must be avoided. 
There is nothing wrong with the shar’i greeting of salaam in which there is no fitnah and no shaking hands, and which does not give rise to doubts and does not involve any softness in speech, and in which hijaab is observed and there is no being alone with a member of the opposite sex, because Allah says (interpretation of the meaning): 
“O wives of the Prophet! You are not like any other women. If you keep your duty (to Allah), then be not soft in speech, lest he in whose heart is a disease (of hypocrisy, or evil desire for adultery) should be moved with desire, but speak in an honourable manner” [al-Ahzaab 33:32]
 At the time of the Prophet (peace and blessings of Allah be upon him), the women used to greet him and ask him questions concerning things they did not understand, and the women also used to ask the companions of the Messenger of Allah (peace and blessings of Allah be upon him) concerning things they did not understand. 
With regard to a woman shaking hands with other women, or shaking hands with men who are her mahrams, such as her brothers, uncles, etc., there is nothing wrong with that.