The simplest and most universal answer is “by changing the size of the thing that produces the sound”.
The shorter the string, the higher the pitch, so moving your finger up the neck of the guitar essentially shortens the vibrating length of the string. Pianos are strung with strings of different sizes. Strings also make it clear that changing tension (tightness of the strings) also adjusts pitch, so the pitch can be adjusted by tightening or loosening the strings.