使用厨师创建用户,这样我就可以进入盒子

时间:2015-02-02 12:33:51

标签: linux ssh chef

我们使用厨师来配置我们的盒子,但我们的大部分部署都在窗户上,因为我们的linux盒子的基础设施并非全部;因此,我无法使用自己的用户/密码登录。

允许登录的机制仅适用于Windows(目前它并不是优先考虑在Linux上执行此操作)而且我们只有root密码而且我无法访问它(理所当然)左右)。

然而,我可以在厨师运行期间创建一个用户,我看过但说实话他们有点混乱,所以我想我会问并希望有经验的人可能有更好的解决方案。

如何创建具有管理员访问权限的用户,以便我可以通过厨师进行操作并执行需要在框中完成的操作?

1 个答案:

答案 0 :(得分:2)

我能给出的最佳指导:

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

User resource documentation

A stackoverflow 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

属性/ 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.

配方/ 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.