Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get unique `uid`?

Tags:

linux

bash

I'm making a bash script which should create an ftp user.

ftpasswd --passwd --file=/usr/local/etc/ftpd/passwd --name=$USER --uid=[xxx]
     --home=/media/part1/ftp/users/$USER --shell=/bin/false

The only supplied argument to script is user name. But ftpasswd also requires uid. How do I get this number? Is there an easy way to scan passwd file and get the max number, increment it and use it? Maybe it's possible to obtain that number from the system?

like image 341
Pablo Avatar asked Dec 13 '25 04:12

Pablo


1 Answers

Instead of reading /etc/passwd, you can also do it in a more nsswitch-friendly way:

getent passwd

Also don't forget that there isn't any guarantee that this sequence of UIDs will be already sorted.

like image 90
bhdnx Avatar answered Dec 14 '25 20:12

bhdnx