How to Make a User with a Numeric Username in Linux
This is something you really shouldn't do. But I'm 23, so it had to be done.
Note: If you want to have numeric usernames for business reasons, put a letter in front, like u1234
. The following steps are only necessary to satisfy my vanity.
As far as the core operating system is concerned, usernames are strings, and what exactly is in them doesn't matter. However, some low-level tools assume numbers are options and usernames don't begin with numbers, so there are systems in place to make it hard to create a numeric username, and careless use of it can lead to chaos.
First, useradd
doesn't work, it simply rejects the username as invalid. So instead create an account with a letter in front:
useradd -m -s /bin/bash x23
Now you need to modify the files that hold user information:
- move the home directory:
mv /home/x23 /home/23
- change the username in
/etc/passwd
and/etc/group
- change the username in
/etc/shadow
- this file is marked read-only, but you can override that as root
The last step is generally a terrible idea, but required to log in without rebooting. Once all those are done, you can passwd 23
and then su 23
, and from there you should be fine.
The only low-level program I've ever encountered that completely refuses to handle numeric usernames is the suite of rcs
tools, which are like a primitive git
. The only time this came up was when I was using TwikiWiki, which uses them for versioning behind the scenes.
I've heard some versions of chown assume numeric values are userids, and don't check them as usernames first, but I haven't encountered this myself.
On an old Debian version around 2009, one version of the useradd
command took "23" as the username, userid, and groupid. Normally a groupid that low could cause problems since Debian reserves groupids below 100 for system use, but it turns out groupid 23 remains unassigned. Ψ