Creating a new user with SSH rights on OS X

33 views
Skip to first unread message

Anthony Green

unread,
Aug 19, 2015, 3:32:37 AM8/19/15
to Ansible Project
I've been trying to use the group and user module to create a user account that has SSH rights.

the tasks i'm running are:

- name: Add jenkins user
  user: name=jenkins comment=Jenkins password=foobar system=yes
  sudo: yes

and although the user is created SSH isn't set up properly: If I try to connect as the user jenkins I get authenticated but the connection immediately closes.

previously I'd used a sequence of shell commands:

- name: Create Jenkins user
  shell: "{{item}}"
  with_items:
    - "dscl . -create /Users/jenkins"
    - "dscl . -create /Users/jenkins UserShell /bin/bash"
    - "dscl . -create /Users/jenkins RealName 'Jenkins'"
    - "dscl . -create /Users/jenkins UniqueID {{unique_id_generator.stdout}}"
    - "dscl . -create /Users/jenkins PrimaryGroupID 20"
    - "dscl . -create /Users/jenkins NFSHomeDirectory /Users/jenkins"
    - "createhomedir -c > /dev/null"
    - "dscl . append /Groups/com.apple.access_ssh user jenkins"
    - "dscl . append /Groups/com.apple.access_ssh groupmembers `dscl . read /Users/jenkins GeneratedUID | cut -d ' ' -f 2`"
    - "dscl . -passwd /Users/jenkins foobar"
  sudo: yes

and this does work

Any ideas or is this a bug in the user module?

Anthony Green

unread,
Aug 19, 2015, 5:55:03 AM8/19/15
to Ansible Project
the answer was to add the user to the ssh group and set the shell


- name: Add jenkins user
  user: name=jenkins comment=Jenkins password=foobar groups=com.apple.access_ssh shell=/bin/bash
  sudo: yes

Reply all
Reply to author
Forward
0 new messages