When installing Pop!_OS in a virtual machine, I want to choose a username that ends in “-local” such as “gpadmin-local.” The dash is a valid character for a username as I can demonstrate by connecting to my home server:
$ ssh vmserver
Last login: Sat Feb 26 23:33:16 2022 from 172.20.1.8
gpadmin-local@vmserver:~$ grep gpadmin-local /etc/passwd
gpadmin-local:x:1000:1000:Grayson Peddie - Local Admin,,,:/home/gpadmin-local:/bin/bash
The workaround is to use an underscore such as “gpadmin_local.” After that, I then edit three files as root by creating a password for a root user and edited the following files as a root user:
Once I changed all instances of gpadmin_local to gpadmin-local, I then changed the home directory of my local user from /home/gpadmin_local to /home/gpadmin-local as I want that same user to login as gpadmin-local and use the renamed /home/gpadmin-local instead. After that, it worked out pretty well after I do a reboot. To lock the root password, all I have to do is type `passwd -l root" as root and all is good now.
KNOW what you are doing with editing the files above. You may not be able to log in as a renamed user if you make a mistake.
Can anyone shed some light regarding why the Pop!_OS installer does not allow the use of dash for a username? It’s after I clicked in “Erase and Install” button.
Why don’t you just usermod -l gpadmin-local gpadmin_local && usermod -m -d /home/gpadmin-local gpadmin-local?
Also, the reason why it may not allow the dash is because of the adduser.conf. POSIX specifies that the portable users have to use the characters A-Z, a-z, 1-9, dot, underscore and dash, as long as the last three are only in the middle and not at the beginning or end of a username. Ubuntu doesn’t allow dot or dash in usernames and at some point Debian didn’t allow underscore (not sure about now), which is stupid, when IEEE says that should be fine. So what I used to do was edit /etc/adduser.conf and modify NAME_REGEX to:
I think for dash to work, the regex would be NAME_REGEX="^[a-z][-a-z0-9_-.]*\$?$", but I’m not entirely sure. If the above doesn’t work, remove the last ?$ at the end and see if that works.
When you create users, you also have the option to use useradd --badname "user-name" to make it work, but obviously, UbUnTu and PoP!_oS don’t allow it in their installers, and you can’t really modify it on the fly. But at least you can after the first user is create, so the subsequent users created can contain dashes.
gpadmin-local is a local user while gpadmin and gpeddie-* users were added by OpenLDAP when I joined my Linux desktop and a couple of virtualized Debian servers to my OpenLDAP server. So yeah, the dash still works in usernames.
Also, I’m not sure if the usermod command applies to a group as well. The usermod command creates a group in addition to a user. I will give that a try the next time I spin up a new instance of a virtual machine.
Oh, and when it comes to Debian and Ubuntu, I still make use of user* commands which include useradd and not adduser. As an Arch user, this is just a habit of mine. I could care less for Debian-specific commands except for apt commands.
Assuming? Well that’s because the groupmod -l command is omitted in post regarding the usermod -l command.
Oh, wait a minute…
What I should have meant is as follows:
If a groupmod is included as follows:
Then there wouldn’t be any assumptions because now I would know that usermod -l does not modify the name of the group. Not my place to be rude—I mean, no offense. It’s actually my fault that I didn’t use the word “modify” instead of “create” for opening up to assumptions.
In any case, I did what I did the first time I renamed the user and changed the three files as a root user.
Thanks. This thread has answered my question regarding why the installer won’t allow me to use a dash, which I found it to be silly.
Yeah, the parameters are a bit silly. usermod -l new-username old_username modifies the user, while groupmod -n new-group old_group modifies the group. There is no -l option in groupmod and there is no -n option in usermod. They should have stuck with -n with both (“new” or “name”).
I didn’t think of modifying the group too, yeah, should have figured, because you modified /etc/group manually. By the way, if you want to backup your users on your system and transfer them to another, you need to backup
Good advice regarding backing up the list of users; however, different Linux distributions have different system users and groups, so it would be unwise to transfer them to Rocky Linux or Arch Linux. If I want the same users and groups, it’s better to centralize them in an LDAP server such as Samba or OpenLDAP.
For example, in Debian server:
$ grep dial /etc/group
ls -l /dev/ttyS0
crw-rw---- 1 root dialout 4, 64 Feb 20 00:23 /dev/ttyS0
And in Arch Linux:
$ grep uucp /etc/group
$ ls -l /dev/ttyS0
crw-rw---- 1 root uucp 4, 64 Mar 12 07:26 /dev/ttyS0
Both dialout and uucp are the same for /dev/ttyS0. If I have a serial device (which I do), to allow a user to access a serial device I simply added the user to the group depending on which Linux distribution I am currently running.
However, I really went off-topic. This thread is about choosing a username with a dash during installation. I would really like to perform any installation “The Arch Way™” regardless of which Linux distribution I use. Would be nice if Debian-based distributions could ship with something like aptstrap (like in "pacstrapbut for Debian/Ubuntu/Pop!_OS) which allows me to specify which packages I want to install into the/mnt` directory and take full control of the installation process, so I do not have to deal with limitations of installers. If that were possible, DT from DistroTube would love to go with “The Arch Way™” of installing any Linux distribution in a virtual machine without the installer telling him “The password ‘dt’ is too weak and I won’t let you continue.” This is when Derek is doing reviews of Linux distributions.