在 macOS 上禁用屏幕锁

在 macOS 上禁用屏幕锁

有没有办法禁用 macOS(10.13/10.14)在屏幕保护程序或睡眠开始后锁定屏幕 x 时间的默认行为?

我的计算机实验室里有几台 Mac Mini。人们登录、使用计算机,然后就走开了。MacOS 会在一小时后锁定屏幕,此时电源设置会关闭显示器。下一个用户无法登录,因为屏幕已锁定,并且没有选项可以输入用户名进行切换或用于其他目的。只有一个密码对话框。唯一的办法是强制重启 Mac。

最终的解决方案是有一个强制注销空闲用户的应用程序,但我找不到。

MacOS 似乎有这样的规定,但实际上似乎什么也没做:如果用户打开了任何应用程序,在终止时提示输入保存命令,则不会发生注销,并且用户总是会打开提示保存的程序。如果我有技能,我会编写这样的应用程序,但我没有。

我尝试过跑步:sudo defaults write com.apple.loginwindow DisableScreenLockImmediate -bool TRUE

不执行任何操作。没有任何变化。默认屏幕锁仍处于活动状态并启用,并且 Apple 菜单上仍提供锁定屏幕菜单选项。

答案1

sysadminctl我们现在必须使用它来配置屏幕锁,而不是写入首选项。

sysadminctl -screenLock off -password <my password>

或者如果你希望输入密码

sysadminctl -screenLock off -password -

我在 macOS Catalina10.15.7和 Big Sur上测试了这个11.4

在 macOS Catalina 上,我们只能将屏幕锁定设置为offimmediate

$ sysadminctl
2021-08-23 11:00:29.685 sysadminctl[63828:9180002] Usage: sysadminctl
    -deleteUser <user name> [-secure || -keepHome] (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -newPassword <new password> -oldPassword <old password> [-passwordHint <password hint>]
    -resetPasswordFor <local user name> -newPassword <new password> [-passwordHint <password hint>] (interactive] || -adminUser <administrator user name> -adminPassword <administrator password>)
    -addUser <user name> [-fullName <full name>] [-UID <user ID>] [-shell <path to shell>] [-password <user password>] [-hint <user hint>] [-home <full path to home>] [-admin] [-picture <full path to user image>] (interactive] || -adminUser <administrator user name> -adminPassword <administrator password>)
    -secureTokenStatus <user name>
    -secureTokenOn <user name> -password <password> (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -secureTokenOff <user name> -password <password> (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -guestAccount <on || off || status>
    -afpGuestAccess <on || off || status>
    -smbGuestAccess <on || off || status>
    -automaticTime <on || off || status>
    -filesystem status
    -screenLock <immediate || off> -password <password>

Pass '-' instead of password in commands above to request prompt.
'-adminPassword' used mostly for scripted operation. Use '-' or 'interactive' to get the authentication string interactively. This preferred for security reasons

但在 Big Sur 上,我们可以设置延迟并查询屏幕锁定状态:

$ sysadminctl
2021-08-23 16:01:00.636 sysadminctl[26772:2610970] Usage: sysadminctl
    -deleteUser <user name> [-secure || -keepHome] (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -newPassword <new password> -oldPassword <old password> [-passwordHint <password hint>]
    -resetPasswordFor <local user name> -newPassword <new password> [-passwordHint <password hint>] (interactive] || -adminUser <administrator user name> -adminPassword <administrator password>)
    -addUser <user name> [-fullName <full name>] [-UID <user ID>] [-GID <group ID>] [-shell <path to shell>] [-password <user password>] [-hint <user hint>] [-home <full path to home>] [-admin] [-roleAccount] [-picture <full path to user image>] (interactive] || -adminUser <administrator user name> -adminPassword <administrator password>)
    -secureTokenStatus <user name>
    -secureTokenOn <user name> -password <password> (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -secureTokenOff <user name> -password <password> (interactive || -adminUser <administrator user name> -adminPassword <administrator password>)
    -guestAccount <on || off || status>
    -afpGuestAccess <on || off || status>
    -smbGuestAccess <on || off || status>
    -automaticTime <on || off || status>
    -filesystem status
    -screenLock <status || immediate || off || seconds> -password <password>

Pass '-' instead of password in commands above to request prompt.
'-adminPassword' used mostly for scripted operation. Use '-' or 'interactive' to get the authentication string interactively. This preferred for security reasons

    *Role accounts require name starting with _ and UID in 200-400 range.

https://blog.kolide.com/checking-macos-screenlock-remotely-62ab056274f0进行详细分析。

答案2

Security and Privacy超时时间在面板中控制System Preferences。您要查找的内容位于General选项卡上,并设置屏幕保护程序启动后需要输入密码之前的时间。

答案3

我遇到了同样的问题,似乎所有以前的技巧在 Mojave 上都不再起作用。

至于 X 分钟后自动注销,我相信您仍然可以使用下面的脚本来做到这一点(尽管我不确定我是否真的在 Mojave 上测试过它)。您可以使用任何您喜欢的方法推出脚本,然后运行一次。(或者您可以打开终端窗口,或 ssh 进入,然后手动运行命令。)

自动注销

#!/bin/bash

# I think this this turns on the feature
defaults write /Library/Preferences/.GlobalPreferences com.apple.securitypref.logoutvalue -int 1800

# and that this sets the delay
defaults write /Library/Preferences/.GlobalPreferences com.apple.autologout.AutoLogOutDelay -int 3600

# 3600 = 60 minutes
# 1200 = 20 minutes
#   750 = 12 minutes
#   600 = 10 minutes
#   500 = 8 minutes
#   etc 

# (I suspect one of these can simply be a non-zero value,
# and that the Apple OS programmers just plugged in
# the value given by the user instead of making it a
# binary 0 or 1 value, but I’m not sure.

相关内容