Skip to content

Instantly share code, notes, and snippets.

@shinyay
Created June 17, 2013 10:04
Show Gist options
  • Select an option

  • Save shinyay/5795911 to your computer and use it in GitHub Desktop.

Select an option

Save shinyay/5795911 to your computer and use it in GitHub Desktop.
my-users default recipe
user = Chef::EncryptedDataBagItem.load("users", 'deploy')
user_name = user['name']
password = user['password']
ssh_key = user['ssh_key']
home = "/home/#{user_name}"
# Create a User [deploy]
user user_name do
password password
home home
shell "/bin/bash"
supports :manage_home => true # Manage home directory
end
# Add [deploy] to [wheel]group
group "wheel" do
action [:modify]
members [user_name]
append true
end
# Create .ssh directory
directory "#{home}/.ssh" do
owner user_name
group user_name
end
# create an authorized_keys file
authorized_keys_file ="#{home}/.ssh/authorized_keys"
file authorized_keys_file do
owner user_name
mode 0600
content "#{ssh_key} #{user_name}"
not_if { ::File.exists?("#{authorized_keys_file}")}
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment