使用 chef 创建用户,这样我就可以通过 ssh 进入 box

Use chef to create user so I can ssh into box

我们使用 Chef 来配置我们的盒子,但我们的大部分部署都在 windows 上,因为我们的 linux 盒子的基础设施并不全都在那里;因此,我无法使用自己的 user/password 登录。

允许登录的机制仅在 windows 上有效(目前这不是在 linux 上执行的优先事项)而且我们只有 root 密码,我没有访问权限对此(理所当然)。

不过我可以在 chef 运行 期间创建用户更好的解决方案。

如何创建具有管理员访问权限的用户,以便我可以通过 ssh 登录并通过 chef 在盒子上执行需要完成的操作?

我能给出的最佳指导:

使用用户资源创建用户,然后使用 sudo cookbook 将此用户添加到 sudoers 列表中。

User resource documentation

A Whosebug question on the password attribute

Sudo cookbook

所以你最终应该得到一本包含以下内容的食谱:

metadata.rb

[...] # stripped usual lines for cookbook name version
depends 'sudo' # add the dependency to use only one cookbook

attributes/default.rb:

default['user_to_create'] = "user3536548" # took you SO account here
default['authorization']['sudo']['users'] << node['user_to_create'] # Add the defined user in the array (using attribute to avoid duplication of user name), this avoid overwriting entries from other recipes and as the attribute is initialized as an empty array it will be ok anyway.

recipes/default.rb

user node['user_to_create'] # create the user, see the doc for details
include_recipe 'sudo' # include the sudo recipe to take advantages of the atrtibutes above.