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
.
Oneliner that will get the correct
Wi-Fi
entry fromnetworksetup
as input:sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport $(networksetup -listallhardwareports | grep -C 3 Wi-Fi | grep Device: | sed 's/Device: //g') prefs DisconnectOnLogout=NO