1) Go into System Preferences→Sharing and enable Remote Login:
2) Verify SSH server is working on the mac using Terminal.
Type the command: ssh username@localhost
You will then be asked to verify a server key. Type yes , hit return and then type in your password.
You can then test commands as below:
3) Connect to the Mac, remotely.
You can either connect via Terminal from another Mac, or if connecting via a Windows machine, I would recommend using Putty:
Note: The first time you log in remotely, you may be prompted aboout the server key again. Just click on yes.