我读了这个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
答案 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
找到正确的路径。