Create an unlocked user for public key only login
Users are locked if they do not have a password. This generates a random password for a user so SSH public key logins work. It is written for Ansible, but the same process will work in a Bash script.
- name: Users | Generate password for example user
  # Use creates to only run makepasswd once.
  shell: makepasswd --chars=20 creates=/home/example/.ssh/id_rsa
  register: make_password
- name: Users | Create user
  user: name=example createhome=yes home=/home/example generate_ssh_key=yes shell=/bin/bash password=${make_password.stdout}Written by Brad Erickson
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
 #Ansible 
Authors
 
Misha Behersky
79.79K
 
tartansandal
73.67K
Related Tags
#ansible
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#

 
 
