命令行-启用远程登录和远程管理


11

对于我的工作,在部署新的Mac笔记本电脑之前,需要启用以下两个设置:

  1. 系统偏好设置-共享-远程登录。启用后,我还需要添加以前创建的管理员帐户,方法是在“仅这些用户”下选择“ +”号:

  2. 系统偏好设置-共享-远程管理-(会弹出小的弹出窗口),然后选择所有功能

如何通过命令行实现以上两个过程?


您使用哪种部署解决方案?DeployStudio,Casper还是脚本?
klanomath '17

都不是。我只是ssh到机器里做东西。但是出于不同的原因,我需要启用上述两个步骤。
Fabio Viola

Answers:


17

修改远程登录和远程管理设置是通过两个不同的命令完成的-都以root身份执行:

  • 系统设置
  • 启动

要为管理组的成员启用远程登录,请输入:

sudo systemsetup -setremotelogin on

限制访问使用dseditgroup。首先检查它是否存在,并在必要时添加它:

dseditgroup com.apple.access_ssh
dseditgroup -o create -q com.apple.access_ssh

并添加一个用户组:

sudo dseditgroup -o edit -a admin -t group com.apple.access_ssh

要为管理员用户启用远程管理,请输入:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart -activate -configure -access -on -users admin -privs -all -restart -agent -menu

要检查其他选项,请输入:

sudo /System/Library/CoreServices/RemoteManagement/ARDAgent.app/Contents/Resources/kickstart --help

从10.14开始,您无法通过ssh启用。如果Yo通过ssh连接,您将收到:警告:macos 10.14和更高版本仅允许控制是否通过“系统偏好设置”启用了“屏幕共享”。
ingconti

5

启用S​​SH:

$ sudo launchctl load -w /System/Library/LaunchDaemons/ssh.plist

禁用SSH:

$ sudo launchctl unload /System/Library/LaunchDaemons/ssh.plist

(已替代,systemsetup已弃用)

This command still works, but it is deprecated. Please use launchctl(8) instead.
By using our site, you acknowledge that you have read and understand our Cookie Policy and Privacy Policy.
Licensed under cc by-sa 3.0 with attribution required.