1827406 Members
5351 Online
109965 Solutions
New Discussion

Re: useradd

 
SOLVED
Go to solution
Sean Gay
New Member

useradd

I am using the useradd to add users but I keep running into problems. When I try to add user JOE it assigns a UID number of 102 and I need it to assign a UID number of 1001. According to the man pages for 11.0...uid defaults to the next available unique number above the maximum currently assigned number...The max UID number I am using is 1000, but this wants to add the user to 102...I really need it to add above 1000 so it does not interfere with other added clients.
11 REPLIES 11
Marco Paganini
Respected Contributor

Re: useradd

Hello Sean,

You can try to specify the uid with:

useradd -u 1001 newuser

That will create a new user called "newuser" with uid=1001

Regards,
Paga
Keeping alive, until I die.
James R. Ferguson
Acclaimed Contributor

Re: useradd

Hi Sean:

# usradd -u uid ...

...specifies the uid of the new user.

Regards!

...JRF...
Craig Rants
Honored Contributor

Re: useradd

Also, make sure that you don't use capital letters such as JOE, this may result in sendmail problems down the line.

Just saw the example and I thought I would throw in my two cents.

C
"In theory, there is no difference between theory and practice. But, in practice, there is. " Jan L.A. van de Snepscheut
Sean Gay
New Member

Re: useradd

That would be fine with the exception that I am calling the useradd from samba where the maxuid is not known. I need the uid to be assigned automaticly.
Alan Riggs
Honored Contributor

Re: useradd

((MAX=`cut -d: -f3 /etc/passwd|sort -rn|head -1`+1))
useradd -u $MAX . . .
Marco Paganini
Respected Contributor
Solution

Re: useradd

Hello.

In this case, rename useradd to useradd.original (or even better, take it out of samba's PATH) and add a script called "useradd" like that:

#/bin/sh
lastuid=`cat /etc/passwd | awk 'BEGIN {FS=":"} ($3 < 65000) { print $3 }'| sort -n| tail -1`
useradd.original -u $lastuid $*

That should do the trick for you.

Regards,
Paga
Keeping alive, until I die.
Sanjay_6
Honored Contributor

Re: useradd

Hi Sean,

It will be difficult to assign user id's 1000+ by default. There is no file in which the default is stored. you have to specify the userid manually if you want to set them to 1000+.

Hope this helps.

Regds
Rob Galloway_1
Frequent Advisor

Re: useradd

Sean,
useradd will assign the next free user id above 100. So if you have removed a user with uid 102 useradd will default to use that uid.
If after this you add a user and all uids are in use up to 200 useradd will default to 201.

If you really need to use 1001 you can use
useradd -u 1001 newuser.

Hope this helps
R.
Experience is a hard teacher. It tests first and teaches afterward.
Sean Gay
New Member

Re: useradd

Marco,

I like your idea of the script but could not get it to run when called from samba. Didn't look like it was running. I have all permissions set correctly but will have to look at it more tomorrow.
Marco Paganini
Respected Contributor

Re: useradd

Hello Sean,

Things to verify:

1) make sure the script is in the PATH! (you can put it in the same place as useradd for testing purposes. If it can run from there you can later move it to a place where only samba will find it.

2) Make sure it's chmod 755

3) Make sure useradd.original can be found by the script

Let me know what happens (the script runs but doesn't work, etc). Also, you can add

echo [$*] >>/tmp/temp.log

as the second line in the script (right after /bin/sh) This will create an output in /tmp/temp.log with the arguments passed to 'useradd'.

Hope it helps.

Regards,
Paga
Keeping alive, until I die.
Sean Gay
New Member

Re: useradd

Thanks to all...I got it working. Momentary lapse of thinking for a minute...wasn't working at first until I stopped and restarted samba. Here is what I did...I created the following in a files called useradd.script...

#!/bin/sh
lastuid=`cat /etc/passwd | awk 'BEGIN {FS=":"} ($3 < 65000) { print $3 }'| sort -n| tail -1`
((lastuid = lastuid +1))
useradd -u $lastuid $*

Call script as so ... useradd.script username

It searches the passwd file, returns the highest uid value and then adds user to /etc/passwd file.

thanks to Alan and Marco for their assistance