LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Home Forums Tutorials Articles Register
Go Back   LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie
User Name
Password
Linux - Newbie This Linux forum is for members that are new to Linux.
Just starting out and have a question? If it is not in the man pages or the how-to's this is the place!

Notices


Reply
  Search this Thread
Old 09-03-2020, 07:35 PM   #1
r34per
LQ Newbie
 
Registered: Nov 2017
Posts: 14

Rep: Reputation: Disabled
Assign UID from a specific range via bash script - RHEL7


Hi all,

Hoping someone can help or point me in the right direction

I am looking to create a bash script to create local users using the ‘useradd’ command, however I need the accounts to be given a UID only from a certain range, so let’s say 1000-2000 and the UID also needs to be assigned backwards and counting down, so..

2000
1999
1998
etc..

Does anyone know a how I can achieve this?

I am running RHEL 7

Any help will be appreciated
 
Old 09-03-2020, 09:55 PM   #2
berndbausch
LQ Addict
 
Registered: Nov 2013
Location: Tokyo
Distribution: Mostly Ubuntu and Centos
Posts: 6,316

Rep: Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002Reputation: 2002
The useradd command has the --uid option which allows you to create a new account with a specific ID.

You then need a while loop like this:
Code:
low=1000
uid=2000
while ((uid>low))
do
    useradd --uid $uid user$uid
    uid=$((uid-1))
done
Not tested.
 
  


Reply

Tags
bash, rhel, script, uid, useradd



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
Attempting RHEL7.6 and connecting via ssh -X, VNC, RDP...from rhel7/6 or fedora30 aalinare Linux - Server 3 10-10-2019 05:02 PM
Bash script to ping a range or own IP-range ugurgazi Programming 13 05-02-2016 09:08 AM
Unable to install RHEL7 KVM onto RHEL7 desktop redhatprat Red Hat 10 02-18-2015 03:44 AM
Prevent programs from creating users within a specific UID range martindl Linux - Security 2 07-22-2011 09:07 PM
Changing the UID of a Physical Volume to a specific UID jambraun Linux - Newbie 2 02-09-2006 02:34 PM

LinuxQuestions.org > Forums > Linux Forums > Linux - Newbie

All times are GMT -5. The time now is 01:46 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration