recipes/default.rb
def create_user(user_name, full_user)

  # Create the user's account.
  user user_name do
    comment full_user['comment']
    password full_user['password']
    shell full_user['shell']
    group 'staff'
    home "/home/#{user_name}"
  end

  # Create the user's home directory if it doesn't exist.
  # This is necessary on Ubuntu and some other distros.
  directory "/home/#{user_name}" do
    owner user_name
    group 'staff'
    mode '0755'
    action :create
  end

  # Create the ssh directory.
  directory "/home/#{user_name}/.ssh" do
    owner user_name
    group 'staff'
    mode '0755'
    action :create
  end

  # Add our public key to the user's authorized keys.
  file "/home/#{user_name}/.ssh/authorized_keys" do
    content full_user['ssh_keys'].join("\n")
    mode '0644'
    owner user_name
    group 'staff'
  end
end
# Function for creating users and their SSH keys.
Function for creating users and their SSH keys.
Function for creating users and their SSH keys .
def create_user(user_name, full_user)
  user user_name do
    comment full_user['comment']
    password full_user['password']
    shell full_user['shell']
    group 'staff'
    home "/home/#{user_name}"
  end
  directory "/home/#{user_name}" do
    owner user_name
    group 'staff'
    mode '0755'
    action :create
  end
  directory "/home/#{user_name}/.ssh" do
    owner user_name
    group 'staff'
    mode '0755'
    action :create
  end
  file "/home/#{user_name}/.ssh/authorized_keys" do
    content full_user['ssh_keys'].join("\n")
    mode '0644'
    owner user_name
    group 'staff'
  end
end
def create_user ( user_name , full_user ) user user_name do comment full_user [ 'comment' ] password full_user [ 'password' ] shell full_user [ 'shell' ] group 'staff' home "/home/#{user_name}" end directory "/home/#{user_name}" do owner user_name group 'staff' mode '0755' action :create end directory "/home/#{user_name}/.ssh" do owner user_name group 'staff' mode '0755' action :create end file "/home/#{user_name}/.ssh/authorized_keys" do content full_user [ 'ssh_keys' ] . join ( "\n" ) mode '0644' owner user_name group 'staff' end end
Function for creating users and their SSH keys.
Function for creating users and their SSH keys .
# Create the user's account. # Create the user's home directory if it doesn't exist. # This is necessary on Ubuntu and some other distros. # Create the ssh directory. # Add our public key to the user's authorized keys.
user_name
full_user