I'm new to chef. Kindly help! I have tried this
user "newuser" do
password: xyz
end
and
user 'newuser' do
comment 'A random user'
uid '1234567'
gid '1234567'
home '/home/saxuser'
shell '/bin/bash'
password 'newpassword'
end
I'm new to chef. Kindly help! I have tried this
user "newuser" do
password: xyz
end
and
user 'newuser' do
comment 'A random user'
uid '1234567'
gid '1234567'
home '/home/saxuser'
shell '/bin/bash'
password 'newpassword'
end
The correct format for the user
resource is the following:
user "newuser" do
password crypt_password
end
Keep in mind that the password must be in shadow format:
The password shadow hash. This property requires that ruby-shadow be installed. This is part of the Debian package: libshadow-ruby1.8.
See the Password Shadow Hash section to see how to generate the shadow password:
$ openssl passwd -1 "theplaintextpassword"
To generate the shadow password from the cookbook, you can use the openssl
cookbook helpers to generate the salt:
Chef::Recipe.send(:include, OpenSSLCookbook::RandomPassword)
password = 'xyz'
salt = random_password(length: 10)
crypt_password = password.crypt("$6$#{salt}")
user 'newuser' do
password crypt_password
end
Don't forget to include the openssl
cookbook in your run list.
Anyway, keep in mind that this will generate a different salt in each chef run, so maybe it's not the best approach to use.
I also encourage you to read Noah's post about secrets management to learn appropriate ways to manage passwords with Chef.