3

I'm wishing to query the values SYS_UID_MIN,SYS_UID_MAX, SYS_GID_MIN, SYS_GID_MAX from a shell script.

These values appear commented out in /etc/login.defs . Hopefully this reflects the default values, but this is not certain.

Somehow the program useradd and groupadd can determine these values, so it must be possible. (I suppose one could look at their source! :) )

lickdragon
  • 161
  • 2
  • 9

2 Answers2

3

The man page for login.defs documents the default values for these variables. Seems to be consistent across the Ubuntu, Debian and CentOS servers I looked at.

  The default value for SYS_UID_MIN (resp. SYS_UID_MAX) is 101
  (resp. UID_MIN-1).

...

   The default value for UID_MIN (resp.  UID_MAX) is 1000 (resp.
   60000).
Paul Haldane
  • 4,517
  • 1
  • 21
  • 32
  • 1
    That man page is worded oddly, but I'm reading it as: "The default value for SYS_UID_MIN is 101, and the default value for SYS_UID_MAX is [UID_MIN - 1]" (which usually works out to 999). Presumably this means that if you change the value of UID_MIN it will change the default value of SYS_UID_MAX unless you explicitly put a value in login.defs. – klugerama Mar 18 '22 at 17:13
0

Pure Bash solution

  UID_MIN="$(read -d '' <'/etc/login.defs'; [[ "${REPLY}" =~ [^#[^:space:]]*SYS_UID_MIN[[:space:]]+([[:digit:]]+)  ]]; echo -n "${BASH_REMATCH[1]}")";
  # useradd's default is 1000 if no UID_MIN in /etc/login.defs
  UID_MIN="${UID_MIN:=1000}";
Léa Gris
  • 113
  • 4
  • without using cat $([[ "$( – c4f4t0r Sep 06 '18 at 00:06
  • UID_MIN="$(read -d '' <'/etc/login.defs'; [[ "${REPLY}" =~ [^#[^:space:]]*SYS_UID_MIN[[:space:]]+([[:digit:]]+) ]]; echo -n "${BASH_REMATCH[1]}")"; – Léa Gris Sep 06 '18 at 00:13
  • Did you read the whole question? This only returns what the (possibly) commented values are. They already saw those values and wanted to know what the actual default values are if they're commented. This doesn't help. – klugerama Mar 18 '22 at 17:21
  • @klugerama after close to 4 years ago, I don't even remember this topic. If you think my answer is worthless, then down-vote it. I moved-on to many other topics since anyway, and surely learned how to provide better answers as well. You will surely find the answers you need with so many topics in here and all Stack sites. – Léa Gris Mar 18 '22 at 19:58