使用chef创建无登录用户

时间:2015-10-27 15:25:08

标签: chef

我读了这个https://docs.chef.io/resource_user.html,看起来这是用于创建系统帐户。但我想创建一个用户运行进程没有登录选项。现在,我在我的厨师食谱中使用了执行块。但我不是执行块的忠实粉丝。有什么方法可以替换这段代码吗?

execute 'create user for service' do
   command -c "This account is for testing something" -s /sbin/nologin -G 'myGroup' -r my_user'
end

1 个答案:

答案 0 :(得分:5)

您的命令上的

-s /sbin/nologin与在用户资源中指定shell "/sbin/nologin"相同。

user资源用于创建用户,如果您将system属性设置为true,则会创建系统用户。

所以命令行的Chef user资源是:

user 'my_user' do # the user name in your command
  action :create # default action, could be omitted, but better to precise it
  shell '/sbin/nologin'
  gid 'myGroup' # the -G in your execute
  comment 'This account is for testing somethin' # the -c in your execute
  system true # to match your -r in execute
  manage_home false # to avoid creating a home directory, omit if you wish it anyway
end

nologin可执行文件可以替换为false。要为发行版which nologin找到正确的路径。