Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save djvdorp/fbf926d8118e78b02439a89422e38bed to your computer and use it in GitHub Desktop.
Save djvdorp/fbf926d8118e78b02439a89422e38bed to your computer and use it in GitHub Desktop.
Keep Your MacBook Network Connections Alive As It Sleeps!

MacBookNetworkAliveOnSleep

As someone that regularly has multiple SSH/VPN sessions open, it can be a huge inconvience to lose all the connections when I lock my screen to get up to go to a meeting, lunch, etc. This is especially true for those connections that require two factor authentication. So, how can I tell my MacBook to keep those connections alive, even though my screen is locked?

Well, turns out that it is pretty simple. All that is needed is to run the following command.

cd /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources
sudo ./airport en0 prefs DisconnectOnLogout=NO

NOTE: It's a good idea to run ifconfig to check which network interface you are currently using. en0 is more times than not the correct one, but you might be on a different interface.

To verify that your command options took effect, you can run the following command

./airport en0 prefs

This should give you a printout with information similar to the following:

AirPort preferences for en0:
DisconnectOnLogout=NO
Unable to retrieve JoinMode
JoinModeFallback=DoNothing
RememberRecentNetworks=YES
RequireAdminIBSS=NO
RequireAdminNetworkChange=NO
RequireAdminPowerToggle=NO
WoWEnabled=YES

The DisconnectOnLogout option should be set to NO.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment