Since I upgraded to Mountain Lion, i've the feeling my Mac (early 2008 iMac) goes to sleep randomly when i'm connected through SSH.
It's there a way I can prevent my Mac to go to sleep when i'm connected over SSH ?
Caffeine prevents your Mac from falling asleep. Maybe, it can help you out with your issue too. The sleep isn't at all random, but in fact is set in the Energy Saver system preference as well from the terminal using
You could use
pmset to inspect and change the sleep settings if you have admin rights on the remote.
You can manage your computer's power settings through
System Preferences -> Energy Saver
Within this pane, click on the
Power Adapter tab, and drag the
Computer Sleep slider all the way to the right, so that it is set to "Never." This will force the computer to stay awake 24/7. I have a laptop running 10.5 at my house that I have running as a file/web/home media server configured using these settings (though the preferences nomenclature is different on 10.5, the functionality is the same) and enjoy uninterrupted access - that is unless there's a problem with the node, but that's out of our control. Caffeine and caffeinate will also work as other users have noted, but this is the most up-front and user-friendly way to get this done as it involves a GUI interface and no third-party application.