I'm trying to create a user with first and last name and home directory in Users/username, with an expiration date, inactive, with a default UID and GID in the DKEL_dir /etc/skel2. This is what I ran on CentOS:

sudo useradd -m -d /Users/username -s /bin/default/useradd -e $(date. -d "2 days ago" "+%Y-%m-%d") -f -k /etc/skel2 Scott walker

The result I got was:

useradd:invalid numeric argument '-k'

2 Answers 2


I don't really know why you would want to have this in /Users which isn't a standard directory. Are you absolutely sure you want that? On Linux systems, home directories are normally under /home, I have only seen /Users on macOS or sometimes in cases where there is a centralized server handling users.

Anyway, assuming you do want it in /Users, the first problem is that -f requires an argument. From man useradd:

       -f, --inactive INACTIVE
           defines the number of days after the password exceeded its maximum
           age where the user is expected to replace this password. The value
           is stored in the shadow password file. An input of 0 will disable
           an expired password with no delay. An input of -1 will blank the
           respective field in the shadow password file. See shadow(5)for
           more information.

           If not specified, useradd will use the default inactivity period
           specified by the INACTIVE variable in /etc/default/useradd, or -1
           by default.

So -f sets the number of days after the end of the password's expiry date that the user will be made inactive. However, the value you are giving it here isn't valid since you have written -f -k, so the -k is read as the value given to -f. To make the user inactive, specify the expiry date in the past, as you have done, and then just use -f 0 to have the password expire with no delay.

The next issue is that login names cannot contain whitespace so you can't use Scott Walker. To set the first and last name using useradd, you need the -c or --comment options. Again, from man useradd:

       -c, --comment COMMENT
           Any text string. It is generally a short description of the
           account, and is currently used as the field for the user's full

Next, the -s is used to define the user's shell, and /bin/default/useradd isn't a shell, it shouldn't even exist as there should be no /bin/default directory (or any subdirectories in /bin). I don't know what you wanted there, but just not including -s will default to the system's default shell. So, putting all this together:

sudo useradd -m -d /Users/scott  \
   -e $(date -d "2 days ago" "+%Y-%m-%d") \
   -f -1 \
   -k /etc/skel2 \
   -c "Scott Walker" \

That will create a user named scott, with the full name Scott Walker, the home directory /Users/scott, an expiry date of 2 days ago and a inactive date of yesterday.

For more details, please see the official CentOS documentation.

  • I am working on homework for a IT class and the teacher is not the best at helping and i am trying everhing and i am comeing up with road blocks Commented Dec 3, 2023 at 14:46
  • @JonathanSpires and does my answer not help? In any case, please always read the man page to see what different options do.
    – terdon
    Commented Dec 3, 2023 at 16:38
  • it did thank you im a student older older going back to school and Its hard when you cant get it from a google search Commented Dec 3, 2023 at 18:58

Try specifying a 0 or -1 with the -f flag. Without the -f flag, useradd will use whatever is configured in the "INACTIVE" variable in /etc/default/useradd, or -1 by default. The /etc/default/useradd conf file is definitely recommended to edit to your liking in a production environment so that every new account starts with the same basic "shell".

From the manpage:

> -f, --inactive INACTIVE
>        The number of days after a password expires until the account is permanently disabled. A value of 0
>        disables the account as soon as the password has expired, and a value of -1 disables the feature.

I typically only use useradd to create the base shell of a user and then modify the groups and all the many .conf files associated with accounts. I'm all for using all the features, though! There are just too many fat finger variables that I don't want to assume the risk for.

  • 3
    Note that this is only one of various issues in the OP's command. They are also setting the shell wrong, using an invalid user name, and not specifying first and last name a they want.
    – terdon
    Commented Dec 3, 2023 at 14:34

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .