1

My current username is mpatil, how can I change that to algo without losing data or causing problems?

terdon
  • 234,489
  • 66
  • 447
  • 667
ram
  • 143
  • 2
  • 3
  • 8
  • Are you trying to change your username or just your prompt? – John Nov 20 '13 at 13:07
  • @ John to change user name – ram Nov 20 '13 at 13:09
  • On your system you are mpatil. You can change your name, set the system name (so localhost (the default) changes). Or just change the prompt `PS1="hello>"` – ctrl-alt-delor Nov 20 '13 at 13:19
  • @richard see my update – ram Nov 20 '13 at 13:22
  • @ram I completely rewrote your question so that it is clearer, my apologies if that is not what you were asking. Please [edit] your question and add the operating system you are using. Are you on Linux, OSX, BSD? Which version? – terdon Nov 20 '13 at 13:29

3 Answers3

1

You can change your login name with usermod by issuing the command (as root, or with sudo):

usermod --login algo mpatil

where algo is the new login name, and mpatil is the old login name.

This is roughly equivalent to John's suggestion of editing your /etc/password by hand, but less error prone, as usermod does the changes for you.

Note that this will only change your login name, in particular your home directory will not be changed to reflect your new login name (most likely it will still be /home/mpatil).

If you want to change your home directory as well, you can issue the command:

usermod --login algo --home /home/algo --move-home mpatil

This can cause problems with applications that record your login name or expanded home directory path in their configuration. You will have to configure the application that do this to use the new home directory path and/or login name yourself, the exact method depending of the application.

A good starting point to identify such application is to grep for you old login / old home directory path in your dotfiles.

Thomas Nyman
  • 29,912
  • 10
  • 65
  • 77
0

mpatil is not the system name in [mpatil@localhost ~]$ - it's the username (the system name is localhost). If you want it to say algo here, then log in as algo.

symcbean
  • 5,008
  • 2
  • 25
  • 37
0

If you want to change your username, you must edit /etc/passwd and /etc/shadow as root, changing 'mpatil' to 'algo', then log out completely and log back in as 'algo'. If you want to switch to the pre-existing 'algo' account, use su or sudo.

John
  • 16,759
  • 1
  • 34
  • 43
  • `[root@localhost mpatil]# /etc/passwd bash: /etc/passwd: Permission denied` – ram Nov 20 '13 at 13:13
  • my question is just how to rename the mpatil to algo – ram Nov 20 '13 at 13:13
  • 1
    You must edit those files. Don't try to run them, they're not scripts. – John Nov 20 '13 at 13:18
  • see my update.. – ram Nov 20 '13 at 13:22
  • 1
    A utility (such as `usermod -l`) will be much safer than editing `passwd` and `shadow` directly, especially for someone not familiar with them. – phemmer Nov 20 '13 at 13:31
  • @John This isn't sufficient. You must also rename the home directory, user cron tabs, user mail boxes, etc. – derobert Nov 20 '13 at 13:35
  • Actually, you don't have to rename the home directory. You can leave it as 'mpatil'. But yeah, you will need to look at these other things - but even the `usermod` utility @Patrick mentioned won't handle those other items. – John Nov 20 '13 at 13:38
  • @John you don't have to rename the home directory, true. But that's the kind of cruft that I'd fully expect to come back to bite me later. Personally, I'd probably move it and put a symlink under the old name. – derobert Nov 20 '13 at 14:07
  • Oh, I expect a lot more than just that to come back to bite me in the butt. That's why I don't rename user accounts, I delete and create new after copying required data somewhere else. :) – John Nov 20 '13 at 14:08