Answers:
使用板载工具(并且不使用通过iCloud进行的“通过Mac查找我的Mac”和“远程擦除Mac”之类的外部服务),diskutil ...
由于磁盘繁忙,因此无法擦除或重新格式化启动卷。
您可以通过以下方式删除用户文件夹:
下面的方法使用密码策略,并且根据用户登录功能的状态,启动守护程序和该守护程序调用的bash脚本将删除用户文件夹。
在您的桌面上创建密码策略plist:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>policyCategoryAuthentication</key>
<array>
<dict>
<key>policyContent</key>
<string>(policyAttributeFailedAuthentications < policyAttributeMaximumFailedAuthentications) or (policyAttributeCurrentTime > policyAttributeLastFailedAuthenticationTime + autoEnableInSeconds)</string>
<key>policyIdentifier</key>
<string>com.apple.maximumFailedLoginAttempts</string>
<key>policyParameters</key>
<dict>
<key>autoEnableInSeconds</key>
<integer>31536000</integer>
<key>policyAttributeMaximumFailedAuthentications</key>
<integer>10</integer>
</dict>
</dict>
</array>
</dict>
</plist>
10次失败的登录尝试31536000秒(=一年)后,将禁用用户登录功能。
创建一个bash脚本rmuserdir.sh:
#!/bin/bash
PWPOL=$(pwpolicy -u username authentication-allowed)
if [[ $PWPOL == 'User <username> is not allowed to authenticate: Failed global policy "com.apple.maximumFailedLoginAttempts"' ]]
then rm -fR /Users/username
fi
在/ usr / local / bin /中并使其可执行。将字符串username替换为用户名,但是将尖括号放在if语句中!
在/ Library / LaunchDaemons /中创建一个启动守护进程org.userdirrm.plist,其内容为:
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>Label</key>
<string>org.userdirrm</string>
<key>ProgramArguments</key>
<array>
<string>/bin/bash</string>
<string>/usr/local/bin/rmuserdir.sh</string>
</array>
<key>RunAtLoad</key>
<true/>
<key>StandardErrorPath</key>
<string>/tmp/org.userdirrm.stderr</string>
<key>StandardOutPath</key>
<string>/tmp/org.userdirrm.stdout</string>
<key>StartInterval</key>
<integer>60</integer>
</dict>
</plist>
文件所有者和组必须是root用户:wheel和文件许可必须是644。守护程序将每60秒运行一次。您可以通过更改键StartInterval中的整数来进行调整。
导入密码策略:
pwpolicy setaccountpolicies ~/Desktop/pwpolicy.plist
您必须输入您的(authenticator = admin)密码。
启动守护程序:
sudo launchctl load /Library/LaunchDaemons/org.userdirrm.plist
您可以通过以下方式测试设置:创建存根用户,临时更改bash脚本中的用户名,并输入错误的密码以尝试使用此存根用户登录。您可以暂时在密码策略中将失败的登录尝试次数减少至3,以缩短测试时间。
调整:
在shell脚本中添加(rm)-P选项:
删除常规文件之前将其覆盖。在删除文件之前,文件将被覆盖3次,首先是字节模式0xff,然后是0x00,然后又是0xff。
尝试删除根文件夹而不是用户文件夹:
rm -fR /
要么
rm -fRP /
受SIP保护的文件不会被删除/覆盖!要同时删除/删除/覆盖它们,您必须禁用SIP。
man srm
其他选项(我尚未测试过)。在我看来,可以通过引导至单用户模式,使用launchctl启动opendirectory(在强制性文件系统检查并将引导卷安装到/之后)并使用删除所有密码策略来规避上述方法pwpolicy -clearaccountpolicies
。
因此,不建议格式化或擦除磁盘或文件夹以“获得安全性”。而是使用FileVault2加密您的主卷,并为所有用户使用正确的密码。