Allah says, in the Qur’an:
Translation: When a (courteous) greeting is offered you, meet it with a greeting still more courteous, or (at least) of equal courtesy. Allah takes careful account of all things (Surah Nisaa, 4:86)1
If your brother or sister in Islam gives you salaams, return it. So respond to “as-salaamu ‘alikum” with “wa’alikum as-salaam wa rahmatullah” and “as-salaamu ‘alikum wa rahmatullah” with “wa’alikum as-salaam wa rahmatullah wa barakatuh” (but don’t go beyond that).
The Prophet (peace be upon him) said (to the meaning of) “Give salaam, for it spreads the love between you.”
But what about if non-Muslims give you salaams?
Among the mufasireen, there are two opinions. One opinion (you can find it in books of tafseer by Mawdudi) is that you return their salaam, with something better. The other opinion (you can find it in books of tafseer by Ibn Kathir) is that you return to non-Muslims the same greeting (“wa’alikum”, which means, literally, “and the same to you”).
What about brothers giving salaam to sisters, and vice-versa, when you pass by each other? The answer is “yes, if it’s not fitnah”. You must be humble and keep your discussions, if any, within the allowed limts. (More on how to do that here.)
Islam-QA that outlines it nicely in a fatwa. They say: “It is also permissible for men to greet women with salaam and vice versa, according to the most correct opinion, but this greeting must be free of anything that may provoke desire in the person in whose heart is a disease, so as to be safe from fitnah […]” It boils down to comfort level, and what’s fitnah for you. Read the whole fatwa, it covers a lot of details.
May Allah protect us from fitnah and allow us to be revivers of the sunnah. Ameen!
(1) Shaykh Muhammad Salih Al-Munajjid, Islam Question and Answer Website. 2 Mar. 2006 <http://63.175.194.25/index.php?ln=eng&ds=qa&lv=browse&QR=1121&dgn=4>.