Rock surfaces are unique terrestrial habitats in which rapid changes in the intensity of radiation, temperature, water supply and nutrient availability challenge the survival of microbes. A specialised, but diverse group of free-living, melanised fungi are amongst the persistent settlers of bare rocks. Multigene phylogenetic analyses were used to study relationships of ascomycetes from a variety of substrates, with a dataset including a broad sampling of rock dwellers from different geographical locations. Rock-inhabiting fungi appear particularly diverse in the early diverging lineages of the orders Chaetothyriales and Verrucariales. Although these orders share a most recent common ancestor, their lifestyles are strikingly different. Verrucariales are mostly lichen-forming fungi, while Chaetothyriales, by contrast, are best known as opportunistic pathogens of vertebrates (e.g. Cladophialophora bantiana and Exophiala dermatitidis, both agents of fatal brain infections) and saprophytes. The rock-dwelling habit is shown here to be key to the evolution of these two ecologically disparate orders. The most recent common ancestor of Verrucariales and Chaetothyriales is reconstructed as a non-lichenised rock-inhabitant. Ancestral state reconstructions suggest Verrucariales as one of the independent ascomycetes group where lichenisation has evolved on a hostile rock surface that might have favored this shift to a symbiotic lifestyle. Rock-inhabiting fungi are also ancestral to opportunistic pathogens, as they are found in the early diverging lineages of Chaetothyriales. In Chaetothyriales and Verrucariales, specific morphological and physiological traits (here referred to as extremotolerance) evolved in response to stresses in extreme conditions prevailing on rock surfaces. These factors facilitated colonisation of various substrates including the brains of vertebrates by opportunistic fungal pathogens, as well as helped establishment of a stable lichen symbiosis.