In enterprise environments, we often need to map professional email addresses (like john.smith@company.com
) to simpler system usernames (jsmith
). Linux provides multiple ways to implement this username/email synonym functionality.
For pure email mapping (Postfix/Sendmail):
# Edit /etc/aliases john.smith: jsmith team.lead: jsmith,admin.user # Then run: newaliases
For advanced mail server configurations:
# In /etc/postfix/virtual john.smith@example.com jsmith support@example.com jsmith,admin.user # Postmap and reload postmap /etc/postfix/virtual systemctl reload postfix
When both names need filesystem access:
# /etc/security/pam_mount.conf.xml <volume user="jsmith" fstype="none" path="/home/john.smith" />
Quick solution for web directories:
ln -s /var/www/jsmith /var/www/john.smith chown -h jsmith:jsmith /var/www/john.smith
For LDAP/Active Directory integration:
# Sample ldif for OpenLDAP dn: uid=jsmith,ou=People,dc=example,dc=com objectClass: inetOrgPerson uid: jsmith mail: john.smith@example.com givenName: John sn: Smith cn: John Smith
Verify with these commands:
getent passwd jsmith # Check user exists sendmail -bv john.smith@example.com # Test mail routing ls -ld /home/john.smith # Verify directory access
Always audit permissions after changes:
audit2allow -a # SELinux contexts getfacl /home/jsmith # POSIX ACLs
When managing Linux systems, you might need to associate multiple names with a single user account. This is particularly common in corporate environments where users need both a formal name (john.smith) and a shorter login name (jsmith).
For email purposes, the simplest solution is to modify the mail aliases file:
sudo nano /etc/aliases
Add the following line:
john.smith: jsmith
Then update the alias database:
sudo newaliases
If you need system-wide recognition of both names, create a symlink in the home directory:
sudo ln -s /home/jsmith /home/john.smith
Then update /etc/passwd to include both names in the GECOS field:
sudo usermod -c "John Smith,john.smith" jsmith
For login capabilities with both names, configure PAM:
sudo nano /etc/pam.d/common-auth
Add this line before other auth rules:
auth sufficient pam_listfile.so item=user sense=allow file=/etc/login.aliases
Create the aliases file:
sudo nano /etc/login.aliases
Add your alias mapping:
john.smith jsmith
Verify your setup works:
getent passwd jsmith getent aliases john.smith finger john.smith
For email testing:
sendmail -v john.smith@example.com << EOF Subject: Test alias Test message EOF