3

All my boxes have the same username for myself, except one legacy machine where I'm loath to try to change it. Whenever I ssh to the machine, I forget to specify my user name, and my password is rejected. This only takes maybe 30 seconds, but it should only take 3, so it's a PIA.

Is there any way to configure that machine to recognize the incoming username and map it to another, correct, one?

I'd really like to configure this on the server itself if possible. Configuring each client is less ideal, especially since I like to muck with my various installations and VM's quite a bit.

2 Answers 2

4

In your ~/.ssh/config:

host otherhostname
user otherusername

Then it'll use otherusername when you $ ssh otherhostname.

3
  • 1
    while this works, it requires maintenance. Whenever I do a clean install, or make a new VM, etc, I'll need to look up this post. Is there any way to get this done on the server side?
    – bukzor
    Mar 12, 2011 at 18:14
  • 1
    FWIW, I keep around and periodically update a vanilla tarball of my home directory to bootstrap new accounts on new machines, VMs, etc.
    – geekosaur
    Mar 12, 2011 at 18:25
  • 1
    @bukzor - anything other than stock config is going to require maintenance. From my experience, there's no way to do this on the server side. At it's root, this is a client-side issue and as such, should be dealt with on the client side.
    – EEAA
    Mar 12, 2011 at 19:39
0

You could add another account on the target server with your desired username, then edit /etc/passwd and change the UID to that of the original account. This would give you two usernames for the same account.

I'm not sure whether it will introduce any problems as I imagine it violates some spec somewhere, but I've done it temporarily before during server migrations and didn't encounter any issues.

Most programs that map UIDs back to usernames seem to pick the first entry in /etc/passwd so reordering the lines should control which username you see in things like ls directory listings (in case you would rather see your new username but have the old one continue to work).

You're only likely to run into problems with things that check the username against a string. For example you could do this to create an alias for the root account, but then you might encounter a situation where sudo whoami returns something other than root which may for example cause an application to abort claiming that you must be the root user to continue, even though you actually were.

You must log in to answer this question.

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