如何从Mac OS X Server的CLI中禁用用户帐户?

有没有任何可能的解决scheme,例如通过SSH禁用CLI的用户? 必须有一个dscl命令。 还是有一个dsAttrTypeStandard属性,我可以相应地设置?

任何指针?

这在LDAP和OD帐户的10.5和10.6中工作:

pwpolicy -a diradmin -u ajohnson -setpolicy "isDisabled=1" 

或为本地帐户:

 sudo dscl . -create /Users/ajohnson UserShell /usr/bin/false 

将ajohnsonreplace为您希望禁用的用户的简短用户名。

要重新启用只需设置“isDisabled = 0”而不是1.或者在本地帐户的情况下,在/etc/shells shell中的任何shell

pwpolicy示例来自用户pipe理文档(Snow Leopard)的第62页或命令行pipe理Leopard手册的第106页。

对于所有OS X帐户

pwpolicy用于OS X客户端上的本地帐户。 但是可以使用dscl命令直接编辑这些authentication设置。 此方法可以保证适用于用户级OS X帐户(访客,pipe理员和其他常规帐户,您将在login窗口中看到这些帐户)。 使用这种方法,帐户是否使用OS-X服务器/ LDAP帐户进行pipe理并不重要。 此方法也适用于所有OSX系统帐户(否则,您将禁用其loginshell)。

就是这样:

 # Read the AuthenticationAuthority key dscl . -read /Users/username AuthenticationAuthority AuthenticationAuthority: ;Kerberosv5;; \ username@LKDC:SHA1.41BE28E3B64EB62A42D0673968B9591DE18210F5; \ LKDC:SHA1.07264456235E49D45C4B99FC9549FC366CE32343; ; \ ShadowHash;HASHLIST:<SALTED-SHA1> 

禁用

如果尚未禁用,则将DisabledUser附加到该键的值。 用字段分隔符分号。 过量/空白; ; ; ; 字段被忽略。

 dscl . -append /Users/username AuthenticationAuthority ";DisabledUser;" 

检查

要检查帐户的启用/禁用状态:

 dscl . -read /Users/username AuthenticationAuthority | grep DisabledUser 

对于OSX系统帐户:这些帐户没有开头的AuthenticationAuthority密钥。 因此,检查其启用/禁用状态取决于UserShell属性是否具有有效的loginshell。 所以当AuthenticationAuthority不存在时,请检查shell。

启用

要重新启用用户帐户,我们只需从AuthenticationAuthority条目中删除DisabledUser子string。 然后我们使用dscl . -create dscl . -create cmd并回写整个事情。

 dscl . -read /Users/username AuthenticationAuthority | \ sed 's/AuthenticationAuthority: //;s/DisabledUser//g;s/[; ]*$//' | \ xargs dscl . -create /Users/username AuthenticationAuthority 

获取所有用户的AuthenticationAuthority凭证:

 dscl . -list /Users AuthenticationAuthority 

系统帐户:只要记住一个系统帐户也必须有一个有效的loginshell。

我们有一些OSX客户端从Linux LDAP服务器进行authentication。 我的工作是将用户的loginShell属性设置为/ usr / bin / false。 这似乎阻止了SSH和graphicslogin。