From UFStarfleet Wiki
Saluting is one of the most common and basic forms of military courtesy. It is basically an exchange of greetings between military and/or uniformed services personnel.
Within our United Federation Starfleet “Fleet” group, saluting is not required. The United Federation Starfleet Marine Corps group however salutes at all times as it is deeply imbedded with their customs, traditions and courtesy’s.
The History of saluting has many plausible origins. Some believe that during the "Age of Chivalry" when 2 knights met, they raised their visors to expose their faces. This allowed the Knights to recognize their allies vs. their enemies. The raising of the visor was always performed with the right hand. During the "Middle Ages", men wore heavy capes to conceal their swords. When 2 men would great each other they would raise their right arm to show that it was not on the sword hilt. Greeting someone without raising your right arm could potentially mean that you are about to attack. During the days of the "Borgias", assassination by using a knife or dagger was common. When greeting someone the right hand was raised to show that the person was not concealing a dagger.
The current salute used by naval personnel has its origins from the British Navy who in turn borrowed their hand salute from the British Army. British as well as French soldiers will salute with their right hand turned outward. Some believe that this custom allowed the person being greeted to see there was no weapon in the hand of the person. Since the first days of military organizations, juniors have always uncovered when addressing seniors. This was done by touching the hat or cap with the right hand or taking it off. If the person was not wearing a hat or cover, they would grab a "lock of hair".
In the late 19th century, Queen Victoria decreed that the hand salute was to be used instead of taking your hat or cap off. This decree came about because military members would uncover in the presence of the queen during official ceremonies and this was considered unsatisfactory. Saluting when not in uniform is not usually performed by members of the Naval Services. If you are saluted and you are not in uniform tradition dictates that you do not salute. Instead you may great the person saluting you with "Good Morning", "Good Afternoon", or "Good Evening" depending on the situation. If you approach someone who is senior to you and you are in civilian attire, you do not salute. Instead, you may say "Good Morning Sir or Ma'am" depending on the situation.