Zhu, Justin

Tue, Jan 8, 2019

I want to stop carrying my laptop with me all the time. SSH helps me do this. Currently, I SSH from Mac to Mac. I will write another post once I find myself needing to SSH from Windows to Mac.


My local computer, the computer I am trying to SSH into, is the server. It cannot sleep in order for me to SSH. Therefore, I make sure that the computer never sleeps (as I do with myself). This drains battery life but nonetheless lets me continue working with SSH.

System Preferences

I will need to connect my local computer to a power outlet all the time: go to System Preferences > Energy Saver > Never Sleep.

Additionally, I must also allow Remote Login. This is under System Preferences > Sharing > Remote Login.

System files

To prevent a session from becoming inactive, I need to continually send packets from servers to clients and vice versa.

The server must have the following contents modified in /etc/sshd_config:

ClientAliveInterval 120
ClientAliveCountMax 720

The first one configures the server to send null packets to clients each 120 seconds and the second one configures the server to close the connection if the client has been inactive for 720 intervals that is 720*120 = 86400 seconds = 24 hours



This is the more important section. I will need to adhere to the following protocol for every new remote computer that I am trying to access to my local computer.

System files

To keep the server alive for an hour from the client side, we modify ~/.ssh/config:

  ServerAliveInterval 120

Now we can SSH anywhere, anytime!

Moving files between Server and Client

This is best achieved with iTerm. Download iTerm on the Server and the Client.


Shell integration makes it so much easier to scp files between the server and client. Easier as in I don’t have to type in scp server@server_host:/path/to/server/file /path/to/client/file:

Client runs the following command:

curl -L | bash

Download files from server to client

Download files from remote hosts with a click.

You can right click on a filename (e.g., in the output of ls) to download it.

Upload files from client to server

Drag-drop files to upload with scp.

Hold down option and drag-drop a file from Finder into iTerm2 to upload it.