This question has been asked before in "Words and Wordplay." Run a search for it. Originally in 19th century America, a "dude" was a dandy, a well-dressed, elegant and rather foppish man. They spoke of "getting all duded up" etc. In the 20th century, "dude" was used in the West by real cowboys to make fun of Easterners who were sent out West for their health (often TB or asthmatic type complaints), and would buy the full cowboy rig and wear it, even though they often couldn't ride. Eventually this transferred to the "dude ranch", a sort of adult summer-camp opened by westerners to cater to the Eastern public who wanted the "cowboy experience". The term "dude" became current in the 1950's and 60's among rock musicians, along with "cat" and other such terms, to mean any person. Only in the 1990's did it become current as an expression of surprise by itself.