26

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 [email protected] as opposed to ssh [email protected].)

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

1
  • 3
    Are you only interested in a shorter ssh command, or do you want this more generally?
    – Daniel Beck
    Dec 13, 2011 at 18:28

3 Answers 3

33

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
1
  • 7
    If 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
    Dec 13, 2011 at 23:02
20

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!

1
  • An exception is: when you have multiple people with access to a system account, including the superuser, and you want to track their activities via the audit trail.
    – Pro Backup
    Jan 28 at 22:04
1

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

You must log in to answer this question.

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