Is there a way to automatically format/delete my SSD after x failed login attempts? On iOS there is the option to have the device delete all data after 10 failed login attempts. How can I have the same option on macOS so that my SSD gets deleted/reformated after x failed attemps to log into my user account?
With on-board tools (and without using external services like "Find my Mac" &amp; "Erase my Mac remotely" via iCloud) it's impossible to erase or reformat the boot volume with diskutil ... because the disk is busy.



You can remove your user folder though:

The method below uses a password policy and depending on the state of the user login capabilities, a launch daemon and a bash script invoked by the daemon will remove the user folder.


Create a password policy plist on your desktop:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;policyCategoryAuthentication&lt;/key&gt;
    &lt;array&gt;
        &lt;dict&gt;
            &lt;key&gt;policyContent&lt;/key&gt;
            &lt;string&gt;(policyAttributeFailedAuthentications &amp;lt; policyAttributeMaximumFailedAuthentications) or (policyAttributeCurrentTime &amp;gt; policyAttributeLastFailedAuthenticationTime + autoEnableInSeconds)&lt;/string&gt;
            &lt;key&gt;policyIdentifier&lt;/key&gt;
            &lt;string&gt;com.apple.maximumFailedLoginAttempts&lt;/string&gt;
            &lt;key&gt;policyParameters&lt;/key&gt;
            &lt;dict&gt;
                &lt;key&gt;autoEnableInSeconds&lt;/key&gt;
                &lt;integer&gt;31536000&lt;/integer&gt;
                &lt;key&gt;policyAttributeMaximumFailedAuthentications&lt;/key&gt;
                &lt;integer&gt;10&lt;/integer&gt;
            &lt;/dict&gt;
        &lt;/dict&gt;
    &lt;/array&gt;
&lt;/dict&gt;
&lt;/plist&gt;


The user login capabilities will be disabled after 10 failed login attempts for 31536000 seconds (=one year). 
Create a bash script rmuserdir.sh:

#!/bin/bash

PWPOL=$(pwpolicy -u username authentication-allowed)

if [[ $PWPOL == 'User &lt;username&gt; is not allowed to authenticate: Failed global policy "com.apple.maximumFailedLoginAttempts"'  ]]

then rm -fR /Users/username

fi


in /usr/local/bin/ and make it executable. Replace the string username with your user's name but keep the angle brackets in the if statement!
Create a launch daemon org.userdirrm.plist in /Library/LaunchDaemons/ with the content:

&lt;?xml version="1.0" encoding="UTF-8"?&gt;
&lt;!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd"&gt;
&lt;plist version="1.0"&gt;
&lt;dict&gt;
    &lt;key&gt;Label&lt;/key&gt;
    &lt;string&gt;org.userdirrm&lt;/string&gt;
    &lt;key&gt;ProgramArguments&lt;/key&gt;
    &lt;array&gt;
        &lt;string&gt;/bin/bash&lt;/string&gt;
        &lt;string&gt;/usr/local/bin/rmuserdir.sh&lt;/string&gt;
    &lt;/array&gt;
    &lt;key&gt;RunAtLoad&lt;/key&gt;
    &lt;true/&gt;
    &lt;key&gt;StandardErrorPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.userdirrm.stderr&lt;/string&gt;
    &lt;key&gt;StandardOutPath&lt;/key&gt;
    &lt;string&gt;/tmp/org.userdirrm.stdout&lt;/string&gt;
    &lt;key&gt;StartInterval&lt;/key&gt;
    &lt;integer&gt;60&lt;/integer&gt;
&lt;/dict&gt;
&lt;/plist&gt;


File owner and group has to be root:wheel and file permissions have to be 644. The daemon will run every 60 seconds. You can tweak this by changing the integer in the key StartInterval.
Import the password policy:

pwpolicy setaccountpolicies ~/Desktop/pwpolicy.plist


You have to enter your (authenticator=admin) password.
Launch the daemon:

sudo launchctl load /Library/LaunchDaemons/org.userdirrm.plist



You can test the set-up by creating a stub user, changing the username in the bash script temporarily and entering wrong passwords trying to login with this stub user. You can lower the number of failed login attempts to 3 in the password policy temporarily to shorten the test.

Tweaks:


adding the (rm) -P option in the shell script:


  Overwrite regular files before deleting them.  Files are overwritten three times, first with the byte pattern 0xff, then 0x00, and then 0xff again, before they are deleted.

trying to remove the root folder instead of your user folder:

rm -fR /


or

rm -fRP /


SIP protected files won't be removed/overwritten! To remove/delete/overwrite them also, you have to disable SIP.
try to get the binary srm from an older OS X install, add it to High Sierra and use it in the bash script instead of rm. The binary srm securely removes files or directories. Check man srm for further options (I haven't tested this).




In my opinion the method outlined above can be circumvented by booting to Single User Mode, launching the opendirectoryd with launchctl (after the obligatory file system check and mounting the boot volume to /) and removing all password policies with pwpolicy -clearaccountpolicies.

Therefore formatting or erasing disks or folders to "gain security" isn't recommended. Instead encrypt your main volume with FileVault2 and use good passwords for all users.