macos 来自命令行的 Mac OS X 新用户
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/855786/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Mac OS X New Users From Command Line
提问by Collin Klopfenstein
I need to add a new user via the command line in single-user mode. I reinstalled OS X earlier, and for some reason, it didn't create my user account properly. Now I can't log in. So I'm wondering how exactly I can go about creating a new user account without reinstalling everything.
我需要在单用户模式下通过命令行添加一个新用户。我早些时候重新安装了 OS X,但由于某种原因,它没有正确创建我的用户帐户。现在我无法登录。所以我想知道如何在不重新安装所有内容的情况下创建新用户帐户。
I tried this, but it didn't work: http://osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with-leopard/
我试过了,但没有用:http: //osxdaily.com/2007/10/29/how-to-add-a-user-from-the-os-x-command-line-works-with -豹/
Thanks in advance.
提前致谢。
回答by Gordon Davisson
rm /var/db/.AppleSetupDone
...and then reboot normally. With that file gone, OS X launches its first-run Setup Assistant and (among other things) lets you create a new account.
...然后正常重启。该文件消失后,OS X 会启动其首次运行的设置助手,并且(除其他外)让您创建一个新帐户。
BTW, the reason niutil
isn't there has nothing to do with whether it's a server or not -- it's because Apple got rid of NetInfo (its old database for storing local users) in 10.5, and replaced it with a new XML-based system. If you want to do niutil
-ish things in 10.5, you can either use dscl
(this is actually a bit complicated in single-user mode because directory services aren't running) or create/edit the XML files by hand.
顺便说一句,原因niutil
不是与它是否是服务器无关——这是因为苹果在 10.5 中摆脱了 NetInfo(用于存储本地用户的旧数据库),并用新的基于 XML 的系统取而代之. 如果您想niutil
在 10.5 中执行-ish 操作,您可以使用dscl
(这在单用户模式下实际上有点复杂,因为目录服务未运行)或手动创建/编辑 XML 文件。
回答by MacManager
As of 10.10 you can use the sysadminctl command to add a user, in this case prompting for the password and adding them to the admin group:
从 10.10 开始,您可以使用 sysadminctl 命令添加用户,在这种情况下,提示输入密码并将其添加到 admin 组:
sudo sysadminctl -addUser collin -password - -admin
回答by David Kay
I know it's a bad idea to install Puppet just for this task, but if you're a puppet user and you want a cross-platform solution:
我知道仅为此任务安装 Puppet 是个坏主意,但如果您是 Puppet 用户并且想要跨平台解决方案:
Create the file, user.pp
, containing:
创建文件,user.pp
,包含:
group { 'jenkins':
gid => '507',
}
user { 'jenkins':
ensure => present,
uid => '507',
gid => '507',
shell => '/bin/zsh',
home => '/Users/jenkins',
}
file { '/Users/jenkins':
ensure => directory,
before => User['jenkins'],
}
and then execute it with: puppet apply user.pp
.
然后用执行:puppet apply user.pp
。
Note that you should change the username (jenkins) and gid/uid as necessary.
请注意,您应该根据需要更改用户名 (jenkins) 和 gid/uid。
回答by Evansbee
回答by Hardwareguy
Seems like if it didn't create your user account correctly you probably need to reinstall again in case other things didn't get set up correctly.
似乎如果它没有正确创建您的用户帐户,您可能需要重新安装,以防其他事情没有正确设置。