8

For example, hot to set-up the system for john.smith and jsmith to be synonyms?

UPDATE: the reason is than I want a user to be registered in the system as jsmith and to have john.smith@example.com email address.

Ivan
  • 3,398
  • 19
  • 50
  • 71
  • To what end? Do you want both john.smith and jsmith to have the same permissions? – Tyler K Jul 09 '10 at 04:29
  • Look into postfix aliases then (Or whatever mail server you're using). You don't need to mess around with OS level users to have a mail alias. If you want to share what mail server you're using, we can get you an actual answer with what you need to do. – csgeek Jul 13 '14 at 15:38
  • SSH users: If you were doing this because you are annoyed at having to type the username when connecting to an ssh host... there is a renaming config for that https://stackoverflow.com/questions/10197559/ssh-configuration-override-the-default-username – Ray Foss Jul 06 '17 at 15:19
  • Now a very old question, but I'm just going to add that in Linux two user accounts with the same UIDs are indeed the same accounts as the OS only cares about UIDs (e.g. in checking ownerships), but you CAN add multiple accounts with the same UIDs giving them different account names, specific passwords, specific home directories, specific shells, and also distinguish them in logs and audit trails, however, since it's an unsupported feature, it's risky/unpredictable to be used in a serious scenario. Read more about it in part 4.1.2 here: https://docstore.mik.ua/orelly/networking/puis/ch04_01.htm – aderchox Nov 27 '21 at 05:53

4 Answers4

9

You can't, reliably. Not all auth mechanisms allow for this, either natively or hacked-in.

Now if you don't mind it being an email alias, then just add a line to /etc/aliases and rebuild the alias DB.

Ignacio Vazquez-Abrams
  • 45,939
  • 6
  • 79
  • 84
4

Add john.smith user to /etc/passwd and set the same home and UID.

Nowaker
  • 281
  • 3
  • 10
  • 3
    I tried this approach. Not a good idea. It only served to completely confuse my OS – csgeek Dec 04 '12 at 21:40
  • 2
    It may confuse the OS becuase it's against POSIX. It may or may not work. – Nowaker Dec 05 '12 at 01:35
  • 3
    It works. If you try Bitnami's WordPress for Ubuntu 14.04 you can login using usernames `ubuntu` or `bitnami`. Basically in `/etc/passwd` you will find these lines `bitnami:x:1000:1000:Ubuntu:/home/bitnami:/bin/bash` and `ubuntu:x:1000:1000::/home/bitnami:/bin/bash` – Bhargav Nanekalva May 27 '15 at 12:12
3

What you looking for is an email alias, not an alias for the user name. Each user in Linux has one and only one name. However, setting up an email server is an entirely different matter. You can set up as many email accounts, with as many aliases to those accounts, as you like. Specifics of doing that are dependent on what your email package is.

Andy Lester
  • 740
  • 5
  • 16
2

If you REALLY want to do this. Keep in mind that it's not natively supported nor is it a supported feature.

This is my suggestion:

create a new user and set his $HOME to point to the same directory, then use acl to make him the owner of that folder as well.

something along these lines:

given that user1 exists and userAlias is the new user I'm creating.

sudo useradd userAlias sudo setfacl -m u:userAlias:rwx -R /home/user1

so now userAlias can create files in user1's $HOME. This isn't a perfect solution.. you might have to run a cron to fix the permissions (ie make sure that all files have user and userAlias as the user).

You still have the problem of passwords not being in sync and other silliness to watch out for... but it's theoretically feasible with some ugly hacks.

note: facl is not always standard in all distributions and all kernels. It's been supported by the Linux kernel for ages.. but has been mostly ignored for a long time.

csgeek
  • 167
  • 8