Your TouchID equipped Mac can easily be configured to use your fingerprint to approve sudo commands.
Use your favorite text editor and open the file
/etc/pam.d/sudo
and add the following line
auth sufficient pam_tid.so
below the pam_smartcard.so line as shown below and then save (Ctrl+O for pico) the file.
$ sudo pico /etc/pam.d/sudo
UW PICO 5.09 File: /etc/pam.d/sudo
# sudo: auth account password session
auth sufficient pam_smartcard.so
auth sufficient pam_tid.so
auth required pam_opendirectory.so
account required pam_permit.so
password required pam_deny.so
session required pam_permit.so
^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text^T To Spell
File Name to write : /etc/pam.d/sudo
^G Get Help ^T To Files
^C Cancel TAB Complete
[ Wrote 7 lines ]
^G Get Help ^O WriteOut ^R Read File ^Y Prev Pg ^K Cut Text ^C Cur Pos
^X Exit ^J Justify ^W Where is ^V Next Pg ^U UnCut Text^T To Spell
That’s it. Now when you open a new Terminal window you can use TouchID to approve sudo commands. If you also have your Apple Watch set to unlock your Mac, you will also be able to approve sudo commands by double-clicking the side button on the watch.
Keep in mind that this file is somewhat protected by macOS so after each OS update you will need to add the line to the file. Other than that, it works perfectly!
EDIT: So it looks like some people are concerned with the sudo requirement. I need AirDrop and other macOS services that rely on WiFi to continue working so I cannot afford to disable the wireless interface. As far as I know there is no way to just disassociate from the network without sudo or turning off the interface. Since I have https://digitaino.com/use-touchid-to-authenticate-sudo-on-macos/ also enabled, it just brings up a Touch ID prompt on my screen whenever it needs to run the sudo command.
After using a Sonnet Solo10G SFP+ network adapter with my 14″ MacBook Pro for a few months it was great but something felt off. I was looking for a way to have wifi automatically disconnect (not turn off) when the SFP adapter established a connection and then reconnect once the SFP adapter was removed.
The issue is that since each network interface gets its own IP from the router’s DHCP, it fails to register the DNS record for the new interface since one already exists with the same name. This causes macOS to throw an error that the hostname is already in use and then appends a number to the hostname as a workaround to resolve the conflict. After a month your mac’s hostname would look something like ”macbook pro-1-5-9” or something weird like that. Not ideal.
So I started looking for ways to interface with airport from the terminal.
#!/bin/sh
WIFI_INTERFACE=en0
WIRED_INTERFACE=en4
DEFAULT_SSID="Your SSID"
TEMP_LOCATION="/Users/YOURUSER/.wifi_ssid"
WIFI_STATUS=$(ifconfig $WIFI_INTERFACE | grep status | awk -F' ' '{ print$2 }')
if [[ ("$(ifconfig $WIRED_INTERFACE | grep status | awk -F' ' '{ print$2 }')" = "active" ) ]]
then
WIRED_STATUS="active"
else
WIRED_STATUS="disconnected"
fi
echo "------------Network Check RUN------------"
echo $(date)
echo "WIFI_STATUS: $WIFI_STATUS"
echo "WIRED_STATUS: $WIRED_STATUS"
if [[ ("$WIRED_STATUS" = "active" ) && ("$WIFI_STATUS" = "active" ) ]]
then
networksetup -getairportnetwork $WIFI_INTERFACE | awk -F':' '{ print$2 }' | cut -c 2- > $TEMP_LOCATION
read WIFI_SSID < $TEMP_LOCATION
sudo /System/Library/PrivateFrameworks/Apple80211.framework/Versions/Current/Resources/airport "$WIFI_INTERFACE" -z
echo "Action: WiFi disconnecting from $WIFI_SSID"
elif [[ ("$WIRED_STATUS" != "active" ) && ("$WIFI_STATUS" != "active" ) ]]; then
read WIFI_SSID < $TEMP_LOCATION
if [[ -z "$WIFI_SSID" ]]; then
WIFI_SSID=$DEFAULT_SSID
echo "No wifi_ssid found in $TEMP_LOCATION. Using default_ssid $DEFAULT_SSID"
fi
networksetup -setairportnetwork $WIFI_INTERFACE "$WIFI_SSID"
echo "Action: WiFi connecting to $WIFI_SSID"
else
echo "Action: NO CHANGE"
fi
Remember to update the WIFI_INTERFACE=en0, WIRED_INTERFACE=en4, DEFAULT_SSID="Your SSID" and TEMP_LOCATION="/Users/YOURUSER/.wifi_ssid" variables for your system.
Saving this to ~/network_check and then running:
sudo chmod u+x ~/network_check
Now we need a way to run this script each time there is a change in the network configuration. Based on some google research it seems like a good file to watch for changes is:
/private/var/run/resolv.conf
Set up a user agent to watch for this file and then run the script.
We use cookies on our website to give you the most relevant experience by remembering your preferences and repeat visits. By clicking “Accept”, you consent to the use of ALL the cookies.
This website uses cookies to improve your experience while you navigate through the website. Out of these, the cookies that are categorized as necessary are stored on your browser as they are essential for the working of basic functionalities of the website. We also use third-party cookies that help us analyze and understand how you use this website. These cookies will be stored in your browser only with your consent. You also have the option to opt-out of these cookies. But opting out of some of these cookies may affect your browsing experience.
Necessary cookies are absolutely essential for the website to function properly. These cookies ensure basic functionalities and security features of the website, anonymously.
Cookie
Duration
Description
cookielawinfo-checkbox-analytics
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Analytics".
cookielawinfo-checkbox-functional
11 months
The cookie is set by GDPR cookie consent to record the user consent for the cookies in the category "Functional".
cookielawinfo-checkbox-necessary
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookies is used to store the user consent for the cookies in the category "Necessary".
cookielawinfo-checkbox-others
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Other.
cookielawinfo-checkbox-performance
11 months
This cookie is set by GDPR Cookie Consent plugin. The cookie is used to store the user consent for the cookies in the category "Performance".
viewed_cookie_policy
11 months
The cookie is set by the GDPR Cookie Consent plugin and is used to store whether or not user has consented to the use of cookies. It does not store any personal data.
Functional cookies help to perform certain functionalities like sharing the content of the website on social media platforms, collect feedbacks, and other third-party features.
Performance cookies are used to understand and analyze the key performance indexes of the website which helps in delivering a better user experience for the visitors.
Analytical cookies are used to understand how visitors interact with the website. These cookies help provide information on metrics the number of visitors, bounce rate, traffic source, etc.
Advertisement cookies are used to provide visitors with relevant ads and marketing campaigns. These cookies track visitors across websites and collect information to provide customized ads.