0

Can I use useradd in SLES 11 where a username is just a number (didn't see anything in the man useradd(8) )?

currently getting:

useradd: Invalid account name: `9999'

The alternative is manually editing /etc/passwd, correct?

And then, what should I do to make the home directory?

Feel free to comment why this is a bad idea; because I'm unclear on that too. I'm just supporting legacy users

4
  • No, you can't have all-numeric usernames. For all intents and purposes, all-numeric names are UIDs. Commented Jan 25, 2017 at 17:43
  • @sato, I don't think that is entirely true - all numeric usernames work; it's probably important to make sure they match the UID. Adding them to passwd manually works; they work with ldap too. Commented Jan 25, 2017 at 17:51
  • Nope, they don't. Assume user 100 with UID 200, and user 200 with UID 100. What happens when you chown 100 file? Commented Jan 25, 2017 at 17:54
  • @sato, OK, I see what you're saying today. I didn't mean "every" numeric username works. I mean usernames with all numbers work (i.e. greater than or equal to 1000). I need to use hyphens more. Commented Jan 26, 2017 at 15:41

2 Answers 2

2

Can I use useradd in SLES 11 where a username is just a number?

No, you can't. See pablo's answer here

The alternative is manually editing /etc/passwd, correct?

Correct, edit /etc/passwd and /etc/group, but it's a bad idea to use numbers as usernames as infixed points out. You can use names like user1234, user5678 if you like.

And then, what should I do to make the home directory?

mkdir /home/whatever

chown whatever:whatever /home/whatever

Don't forget to initialize password with passwd whatever.

4
  • Assume user 100 with UID 200, and user 200 with UID 100. What happens when you chown 100 file? Commented Jan 25, 2017 at 17:56
  • 100 isn't a valid username, see the link in answer for explaination.
    – saga
    Commented Jan 25, 2017 at 17:58
  • @sato, probably why we take every precaution to keep names and UIDs in sync (and not use numeric username anymore) Commented Jan 25, 2017 at 17:59
  • SLES has a mkhomedir_helper which is handy in this case usermod -m would copy the skeleton to the users home dir (if it worked in the first place). Commented Jan 25, 2017 at 18:01
1

A symbolic user name consisting of solely digits would make commands like chown problematic, because the OWNER or GROUP argument of that command can be either symbolic or numeric, and a symbolic name consisting of only digits could be difficult to parse correctly

A few lines in /etc/passwd like

 123:x:100:100::/home/123:/bin/bash
 user:x:123:123::/home/user:/bin/bash

And then a command like chown 123 somefile may not be resolved correctly

So even if you do it by editing /etc/passwd, it is a bad idea

You must log in to answer this question.

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