Is it possible to alias a username on Linux?

23

6

I'm not sure if this has a practical application at all (aside from the fact that I am lazy. you know "christopher" has 11 characters, and I want to type 1), but is it possible to alias a username on Linux? (So I could, for example, ssh c@my.domain.top as opposed to ssh christopher@my.domain.top.)

I currently use Ubuntu as my primary machine, but if it is possible in any of the distro's, I'd like to know.

cwallenpoole

Posted 2011-12-13T18:23:25.157

Reputation: 742

3Are you only interested in a shorter ssh command, or do you want this more generally? – Daniel Beck – 2011-12-13T18:28:05.457

Answers

30

Create a file named ~/.ssh/config and put this in there:

Host h
User christopher
HostName my.domain.top

Now you only have to type ssh h and it does the same thing!

You can also use a wildcard:

Host *
User christopher

Kevin Panko

Posted 2011-12-13T18:23:25.157

Reputation: 6 339

6If you do define it with Host * it should be done at the end of the configuration file, so other more specific settings can take precedence. – Zoredache – 2011-12-13T23:02:08.590

16

You could create a second user, c, with the same UID. From here:

The UID is the actual information that the operating system uses to identify the user; usernames are provided merely as a convenience for humans. If two users are assigned the same UID , UNIX views them as the same user, even if they have different usernames and passwords. Two users with the same UID can freely read and delete each other's files and can kill each other's programs. Giving two users the same UID is almost always a bad idea; we'll discuss a few exceptions in the next section.

Chapter 4.1.2 explains when it might be useful. This is not one of the suggested use cases though!

Daniel Beck

Posted 2011-12-13T18:23:25.157

Reputation: 98 421

1

For the ssh specific case: if your username is the same on both machines you can omit the username completely.

Niels Basjes

Posted 2011-12-13T18:23:25.157

Reputation: 536