IPA user-add multiple users via script

by | Oct 6, 2016 | Red Hat IDM

When adding multiple users in IDM/freeIPA its a pain inputting each user and its time consuming. This script/one liner allows you to enter multiple users at one go and it includes non-interactively specifying a password. The following script allows creating multipe users in IPA and then adding the required attributes as well.

First create a txt file with the Login ID’s, first and lastname and email id. Once created the below script will read that file and then create a new file “add-user-idm.sh” from the output and then run the file as a script.

# vi excel_imported_userlist.txt

farooq.ahmed    farooq  ahmed   [email protected]
faizan.ahmed    faizan  ahmed   [email protected]
baseer.ahmed    baseer  ahmed   [email protected]
asif.ahmed      asif    ahmed   [email protected]
yaseer.ahmed    yaseer  ahmed   [email protected]

To explain further about the script, I will divide that into parts. First it will fetch the usernames file “excel_imported_userlist” and then cat the output to a file “add-user-idm.sh” with the required parameters and values. And then runs “add-user-idm.sh” as a script.

Below command is for reading the usernames file “excel_imported_userlist” and converting it to IPA understandable format (RAW output)

# awk '{print "ipa user-add",$1," --first",$2," --last",$3," --email",$4,"--random --shell=/bin/bash"}' excel_imported_userlist.txt

ipa user-add farooq.ahmed  --first farooq  --last ahmed  --email [email protected] --random --shell=/bin/bash
ipa user-add faizan.ahmed  --first faizan  --last ahmed  --email [email protected] --random --shell=/bin/bash
ipa user-add baseer.ahmed  --first baseer  --last ahmed  --email [email protected] --random --shell=/bin/bash
ipa user-add asif.ahmed  --first asif  --last ahmed  --email [email protected] --random --shell=/bin/bash
ipa user-add yaseer.ahmed  --first yaseer  --last ahmed  --email [email protected] --random --shell=/bin/bash

Run this command for adding multiple users

# awk '{print "ipa user-add",$1," --first",$2," --last",$3," --email",$4,"--random --shell=/bin/bash"}' excel_imported_userlist.txt > /home/admin/add-user-idm.sh && /bin/chmod +x /home/admin/add-user-idm.sh && /bin/bash /home/admin/add-user-idm.sh

Output:

-------------------------
Added user "farooq.ahmed"
-------------------------
  User login: farooq.ahmed
  First name: farooq
  Last name: ahmed
  Full name: farooq ahmed
  Display name: farooq ahmed
  Initials: fa
  Home directory: /home/farooq.ahmed
  GECOS field: farooq ahmed
  Login shell: /bin/bash
  Kerberos principal: [email protected]
  Email address: [email protected]
  Random password: 8D2q_TOgdM40
  UID: 1461600243
  GID: 1461600243
  Password: True
  Kerberos keys available: True
-------------------------
Added user "faizan.ahmed"
-------------------------
  User login: faizan.ahmed
  First name: faizan
  Last name: ahmed
  Full name: faizan ahmed
  Display name: faizan ahmed
  Initials: fa
  Home directory: /home/faizan.ahmed
  GECOS field: faizan ahmed
  Login shell: /bin/bash
  Kerberos principal: [email protected]
  Email address: [email protected]
  Random password: ASf,sUXVI5ZA
  UID: 1461600244
  GID: 1461600244
  Password: True
  Kerberos keys available: True
-------------------------
Added user "baseer.ahmed"
-------------------------
  User login: baseer.ahmed
  First name: baseer
  Last name: ahmed
  Full name: baseer ahmed
  Display name: baseer ahmed
  Initials: ba
  Home directory: /home/baseer.ahmed
  GECOS field: baseer ahmed
  Login shell: /bin/bash
  Kerberos principal: [email protected]
  Email address: [email protected]
  Random password: 4LQRl.5X6F=D
  UID: 1461600245
  GID: 1461600245
  Password: True
  Kerberos keys available: True
-----------------------
Added user "asif.ahmed"
-----------------------
  User login: asif.ahmed
  First name: asif
  Last name: ahmed
  Full name: asif ahmed
  Display name: asif ahmed
  Initials: aa
  Home directory: /home/asif.ahmed
  GECOS field: asif ahmed
  Login shell: /bin/bash
  Kerberos principal: [email protected]
  Email address: [email protected]
  Random password: 9PUBvKmp2x,2
  UID: 1461600246
  GID: 1461600246
  Password: True
  Kerberos keys available: True
-------------------------
Added user "yaseer.ahmed"
-------------------------
  User login: yaseer.ahmed
  First name: yaseer
  Last name: ahmed
  Full name: yaseer ahmed
  Display name: yaseer ahmed
  Initials: ya
  Home directory: /home/yaseer.ahmed
  GECOS field: yaseer ahmed
  Login shell: /bin/bash
  Kerberos principal: [email protected]
  Email address: [email protected]
  Random password: Ggfkdh,O15x.
  UID: 1461600247
  GID: 1461600247
  Password: True
  Kerberos keys available: True

Related Articles….