IPA user-add multiple users via script

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   farooq.ahmed@off.local
faizan.ahmed    faizan  ahmed   faizan.ahmed@off.local
baseer.ahmed    baseer  ahmed   baseer.ahmed@off.local
asif.ahmed      asif    ahmed   asif.ahmed@off.local
yaseer.ahmed    yaseer  ahmed   yaseer.ahmed@off.local

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 farooq.ahmed@off.local --random --shell=/bin/bash
ipa user-add faizan.ahmed  --first faizan  --last ahmed  --email faizan.ahmed@off.local --random --shell=/bin/bash
ipa user-add baseer.ahmed  --first baseer  --last ahmed  --email baseer.ahmed@off.local --random --shell=/bin/bash
ipa user-add asif.ahmed  --first asif  --last ahmed  --email asif.ahmed@off.local --random --shell=/bin/bash
ipa user-add yaseer.ahmed  --first yaseer  --last ahmed  --email yaseer.ahmed@off.local --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: farooq.ahmed@OFF.LOCAL
  Email address: farooq.ahmed@off.local
  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: faizan.ahmed@OFF.LOCAL
  Email address: faizan.ahmed@off.local
  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: baseer.ahmed@OFF.LOCAL
  Email address: baseer.ahmed@off.local
  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: asif.ahmed@OFF.LOCAL
  Email address: asif.ahmed@off.local
  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: yaseer.ahmed@OFF.LOCAL
  Email address: yaseer.ahmed@off.local
  Random password: Ggfkdh,O15x.
  UID: 1461600247
  GID: 1461600247
  Password: True
  Kerberos keys available: True

Infra Related Articles....

It's now possible to install both Puppet Master and Agent on the same host with different certs for each, to...
This article shows you how to Automate iptables for the whole infrastructure (linux/unix) and maintain the state during the lifecycle...
When adding multiple users in IDM/freeIPA its a pain inputting each user and its time consuming. This script/one liner allows...
This article covers the setup and configuration of PuppetDB and Puppetmaster on separate nodes/hosts. I have used PostgreSQL as PuppetDB...
The process of upgrading Red Hat Satellite 5.6 to 5.7 is fairly simple if you follow the steps properly and...
Joomla! Україна