How to Change a Username

When I installed FreeBSD, my username was more than 8 letters long, which I take it can cause problems. My username is nscribner. I was wondering if someone could provide simple instructions for a noob on how to rename my username, home directory, and login group to nick. In this post, SirDice says to do the following:

Just use vipw(8) and change the username and home directory. Rename the home directory itself and you're done. You may also want to rename the corresponding group name.

I'm guessing my login group is also named nscribner, so I would want that changed to nick as well. According to this page, I also should use mv to rename the user's mailfile in /var/mail. Is this everything I need to do? I am looking for very simple instructions that a noob can understand. Thanks!
 
Log in as root (or do whatever is morally equivalent, for example sudo or similar). Edit /etc/passwd using vipw. Change the user name field in the line for the user. If the user is also in a group of their own, and that group is named by the user name, then also edit /etc/group to match. There is no need to change the UID or GID of the user, and there is no need to change the ownership of any files (since they are owned by UID/GID, not username). Done.

If the user is logged in at the time, it would be a good idea to log out and log in again; things like shells might have cached the username in variables. Similar with any long-running processes the user might have started.

Also, it is probably a good idea to keep a session logged in as root, while checking that this all worked: if this goes wrong (it is possible to damage /etc/passwd by being careless), that might make future logins impossible.
 
Log in as root (or do whatever is morally equivalent, for example sudo or similar). Edit /etc/passwd using vipw. Change the user name field in the line for the user. If the user is also in a group of their own, and that group is named by the user name, then also edit /etc/group to match. There is no need to change the UID or GID of the user, and there is no need to change the ownership of any files (since they are owned by UID/GID, not username). Done.

If the user is logged in at the time, it would be a good idea to log out and log in again; things like shells might have cached the username in variables. Similar with any long-running processes the user might have started.

Also, it is probably a good idea to keep a session logged in as root, while checking that this all worked: if this goes wrong (it is possible to damage /etc/passwd by being careless), that might make future logins impossible.
Thanks. So do I run the following commands?

# vipw /etc/passwd
# vipw /etc/group

How is editing the files with vipw? Is it similar to the easy editor ( ee)? Do I press Esc to save and close?

Don't I also use mv to rename my user's directory in /home and my user's mailfile in /var/mail? If so, what would be the commands for renaming the username from nscribner to nick (and please specify whether I should be logged in as root)?
 
You have your favorite editor, it could be ee, or it could be vi or emacs. Best practice is to set the variable "EDITOR" of your shell to the name of your editor. Then, when you start vipw, it will use your favorite editor to edit /etc/passwd. If EDITOR is not set, then it will use vi (which you may or may not like, you might even dislike it catastrophically and not be able to use it). So please set EDITOR before using vipw.

I'm assuming that you know how to use your favorite editor; I don't know whether ee can be existing with "Esc to save and close".

Also, vipw can only be used to edit the password file. You can't even say "vipw /etc/group", you'll get an error message. To edit /etc/group, you can just use your favorite editor directly. (Side remark: The reason you need to use vipw instead of directly editing /etc/passwd is that there are multiple password files, which need to be synchronized with each other, which vipw does automatically.)

To your question about moving the home directory: There is no law that the user "bob" has his home directory in /home/bob. If bob used to be called adam, there is no fundamental problem with his home directory still being in /home/adam. (Side remark: Let's not argue whether the user's home directory is in /home or in /usr/home, either works.) If you want to also rename the home directory (probably a good idea), then you need to do two things: rename it with mv, and also edit /etc/passwd so it records correctly where the home directory is. The command would be "mv /home/nscribner /home/nick", and only root can run that (because it requires modifying the /home directory, which normal users can't do). It would probably be a good idea for user nscribner = nick to not be logged in at that moment (or immediately log out), because his shells will have all the wrong stuff in cache.

And I'm sorry that I forgot about /var/mail ... on my server at home, there is no such thing, because all mail is handled off-site. Yes, you need to rename the mail file in there /var/mail directory to match the user name!
 
Scribner As a side note: you don't need to change the username just because you think it's too long. FreeBSD's max login size is defined here. It's 32. Unless your login is distributed to some old legacy systems you really don't need to worry about this.
Last time I had to deal with this kind of problem was on HP-UX (but even there you can solve it with proper patches /at least on 11.31/).
 
Scribner As a side note: you don't need to change the username just because you think it's too long. FreeBSD's max login size is defined here. It's 32. Unless your login is distributed to some old legacy systems you really don't need to worry about this.
Last time I had to deal with this kind of problem was on HP-UX (but even there you can solve it with proper patches /at least on 11.31/).
It certainly was a factor back in the old Sun Solaris days with NIS. NIS+ fixed it with longer than 8 character user names.
As to your comment, I agree, leave it as is. SSH maxes out at 32 characters, FreeBSD likewise.
 
Thank you so much for the replies. Unless someone writes a convincing post telling me to rename my username, I am going to keep my username as is (at 9 letters long).
 
Back
Top