In ubuntu it is possible to use the following:

sudo adduser --force-badname john.smith@example.com

This allows adding an email address as a username. The --force-badname option doesn't work in CentOS 7.

Is there a way to achieve this in CentOS 7?

  • 1
    Why the Ubuntu tag? – Jeff Schaller Jul 14 '17 at 19:16
  • 2
    Keep in mind that users on this host would not be able to receive email without significant tweaks to most out-of-the-box MTA configurations, as john.smith@example.com@example.com is not a valid email address (: – DopeGhoti Jul 14 '17 at 20:17

This is not possible on CentOS 7 using the useradd or adduser command. This following patch prevents it and there's no --force-badname option: https://git.centos.org/blob/rpms!shadow-utils.git/c7/SOURCES!shadow-

You can achieve this by adding the user john.smithATSYMBOLexample.com and using vipw to do s/ATSYMBOL/@/ . It appears vipw doesn't check validity of usernames.

  • I have not used vipw before @mmckinst . Can you tell me exactly how to achieve this with vipw? Please note I am not a sysadmin – KoreMike Jul 16 '17 at 14:29
  • its just a way to edit /etc/passwd, it uses a lockfile to prevent multiple people from editing it at the same time. You could just do sed instead if you want to automate it. – Mark McKinstry Jul 18 '17 at 2:06
  • We got this working with sed: sudo adduser john.smithATexample.com sudo sed -i 's/john.smithATexample.com/john.smith@example.com/g' /etc/passwd sudo sed -i 's/john.smithATexample.com/john.smith@example.com/g' /etc/shadow – KoreMike Jul 18 '17 at 15:48

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.