This question is not a duplicate. Please read it before you mark it as such.

Is it possible to assign nicknames or aliases to users on a Linux sever and SSH into the server using the nicknames? I am thinking something along the lines of the aliases for various commands that get added to the .bashrc or the .bash_aliases file, e.g.:

alias grep='grep --color=auto'

For example, if there is a requirement (business rule) to set up users on the server with their full name, e.g., john_smith instead of just their first name (john) but we want to nickname john_smith fruitloops and we want John to be able to:

ssh john_smith@ip_address

as well as:

ssh fruitloops@ip_address

If it is possible, where would the mapping between a user and their nickname be set up? Would the user fruitloops also need to exists on the sever?

This question is about setting up an alias for a user, not a host.

  • 1
    With a host alias you could do ssh fruitloop
    – Takkat
    May 24, 2017 at 10:19
  • My question is about setting up an alias for a user, not the host. fruitloops refers to the user john_smith, not the IP address.
    – dw8547
    May 24, 2017 at 10:22
  • 1
    I believe these are not the same questions ... +1 to question ;)
    – Ravexina
    May 24, 2017 at 10:32
  • 1
    Sorry for my misunderstanding - a SSH host alias would have to be set up on the client but what you need is a solution that was set up on the server. Retracted my close vote.
    – Takkat
    May 24, 2017 at 10:59
  • 1
    I think this is possible with some PAM trickery (if you're using PAM that is). I may be able to find some old code along these lines (if I do I'll post as an answer). May 24, 2017 at 13:21

2 Answers 2


Each user in linux has only one name and that is his only name. you can create aliases for commands not for users.

But you can create a second user with the same UID, home directory and password that would do the trick for you.

  • So my /etc/passwd entries corresponding to these users would look like: john_smith:x:1001:1001:,,,:/home/john_smith:/bin/bash and fruitloops:x:1001:1001:,,,:/home/john_smith:/bin/bash ?
    – dw8547
    May 24, 2017 at 10:49
  • 2
    I tried 3 different approaches after adding user john_smith with UID = 1001. 1) adduser --home /home/john_smith --uid 1001 fruitloops, this did not work (adduser failed because userid was taken) 2) useradd --home /home/john_smith --non-unique --uid 1001 fruitloops, this did work but lead to some behaviour that wasn't desirable 3) Finally I added the line fruitloops:x:1001:1001:,,,:/home/john_smith:/bin/bash directly to the /etc/passwd file and this was closest to what I was after. I SSH into ip_address as fruitloops and land in /home/john_smith upon arrival.
    – dw8547
    May 24, 2017 at 12:07
  • 1
    I'm going to quibble with your wording here. In your scenario, you've created one user (1001) with two different login names. You haven't done it here, but there's no reason the two names can't have different home directories and login shells. Log in as "fruitloops" and create a file. Now check the directory and you'll see that john_smith is shown as the file's owner, because that's the first name found in /etc/passwd for uid 1001. We can argue about whether john_smith is the name and fruitloops is an alias, or john_smith is the primary name and fruitloops secondary, but that's semantic. May 24, 2017 at 18:24
  • 3
    "you can create a second user with the same UID, home directory and password" – that sounds like a terrible hack that's not guaranteed to work across different POSIX-compliant implementations. POSIX requires that the relationship between user names and user IDs be bidirectionally distinct. May 24, 2017 at 20:07
  • @dw8547 Can you explain a bit more about the undesirable behavior from the useradd command? May 24, 2017 at 22:31

I haven't tried this but another option besides the two users mapped to a single UID (which IMO seems dangerous but this option is probably equally dangerous) is to have a single user serve as a redirector based on SSH key. This is how source control repositories that use SSH typically work.

Lets call the user me. Everyone will use this alias.

ssh me@ip_address

Now the user me has all of users public keys in their ~/.ssh/authorized_keys.

command="sudo -i -u user-mapped-to-key" ssh-rsa key

You will need to make the user me have the ability to sudo as the other users and you will need to manage me authorized keys file.

Anyway I haven't tested this but in theory something like this should work.

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .