Change a user's name?

Has anyone experienced how difficult it is to change a user’s login name in linux?
I thought I could just create a new user, and copy across all the configuration files from the old user’s home directory
but no
Those dot files have the old user’s name scattered thruout all their recursive directories , and it takes ages to grep your way thru all the subdirectories to find every occurrence of the old name and replace it with the new name.
And I also have to change file ownership and group.
There has to be a better way?
I want the new user to retain all the settings of the old user, so I need to keep all the old user’s dot files.

1 Like

sudo Whatever Text Editor You're Using /etc/hostname
sudo Whatever Text Editor You're Using /etc/hosts

Change your name in both of these files, Open these files one at a time. save then reboot.
If you want to change OS name, change the first line in these files to whatever you want to call your OS
sudo Whatever Text Editor You're Using /etc/lsb-release
sudo Whatever Text Editor You're Using /etc/os-release

@clatterfordslim
That is a different thing from changing users login name

1 Like

@nevj This may not apply, but I have a user called “Guest” which has never been used. Just for curiosity I opened Settings, Users, Unlock, (pwd) , then clicked on the pencil icon next to Guest, and changed the name to Guest1. It took the change. Does that mean that if Guest had been logging in, their settings, etc. would have been lost when I changed their name to Guest1 ? (I’m using Zorin OS16)

1 Like

Yes you’re right sorry. Users and groups Gnome-System-Tools Can that be used to change user name?

gnome-system-tools in menu it’s called users and groups. I’m just wondering though if changing username, would be easier without anything else installed, on a clean install? Then again a clean install, you would setup the names or users you want anyway.

Hello all.
Just found this:
https://www.cyberciti.biz/faq/howto-change-rename-user-name-id/
May it be useful.
Seems pretty high effort to achieve this, but, anyways… :wink:

Yes that is the big problem. Its not a clean install. There are dozens of files like .config in the jsers home directory, and many of them contain the users name.
If I just change the login name and not the dot files, things stop working

Thanks.
Did not know about usermod
I used useradd to make a new user, then copied all the old users files over. That was not successful. The old users dot files contain references to the old users login name… so when I became the ne user it started trying to update the old users files… and failed
I had to edit all the dot files

Found this reference

It seems to back up what I have been saying… dont do it

If you had used userdel on the command line, it would delete everything… the Guest user would not be in the password file or the groups file, and their home directory would disappear. Yes that drastic.

I am not sure if your GUI click would do the same … Why dont you check… is /home/guest still there? Did it make a new /home/guest1.
What happened to guest’s dot files… there would be some default dot files there even if guest had never logged in. Were they discarded?

Lots of questions, but you learn stuff this way

Cheers Neville

I had already changed “guest1” back to “guest”, so I repeated the gui process and changed it to “guest2” and again, it seemed to take it. If I go back to the log-in screen it shows guest2 and not guest. When I log in as guest2 it required me to set a new password. However if I look in /home I see folder guest and no folder guest2. So it appears that the gui name change only affects the log in process. I suppose it somehow “remembers” that “guest2” is a sort of alias for “guest”. Oh, and all the original guest .dot files seemed to be still intact.

This is a known issue from way back in UNIX.

Also note if you have FireFox or Chromium setup and try name changing it won’t remember the settings correctly. To save Logins/Passwords export them then import them under the new user. See:

Exporting is straight forward.

Thanks,
I can see that it would always been the case. I used BSD Unix in 1980’s

Dont save passwords, but it did interfere with .mozilla files because they contain the user name. They refer to /home/username/… and try to write stuff there, which does not work if username has changed

Regards
Neville

Well that is at least safe.
Not a solution for me, I wanted to transfer the dot files to the new user.
If you just copy them across, that is when it breaks.

Try this. In the master folder where you want to use the dot files:

tar -cf dotfiles.tar .* Yes after tar add space dot star " .*"

cp dotfiles.tar to their new home. Then as the new user:

tar -xf dotfiles.tar

Now the dot files from the master will be installed owned by the new owner.
If you want to see what’s getting to get copied do tar -tvf dotfiles.tar

Ken

@UnixGuy
Yes copying that way will fix the file ownership and group permissions all the way down the filesystem… Thats clever

But it will not fix user name embedded inside the files. They are not in any standard layout, and I dont see any way other than grep and then edit the files.
Thanks
Neville

Yes, that cannot be fixed in a standardised way. It would require a standardised way of referring to a username, to begin with.

Nevj,

Send me an example to look at. Filename that is. /home/nevj/.???

I may be able to help.

OK, here is one case in a firefox dot file

nevj@mary:~/.mozilla/firefox/39gdfkdt.default-esr$ more pkcs11.txt
library=
name=NSS Internal PKCS #11 Module
parameters=configdir='sql:/home/nevj/.mozilla/firefox/39gdfkdt.default-esr' cert
Prefix='' keyPrefix='' secmod='secmod.db' flags=optimizeSpace updatedir='' updat
eCertPrefix='' updateKeyPrefix='' updateid='' updateTokenDescription='' 
NSS=Flags=internal,critical trustOrder=75 cipherOrder=100 slotParams=(1={slotFla
gs=[ECC,RSA,DSA,DH,RC2,RC4,DES,RANDOM,SHA1,MD5,MD2,SSL,TLS,AES,Camellia,SEED,SHA
256,SHA512] askpw=any timeout=30})

You can see it refers to sql:/home/nevj/...
It will not find that reference if I shift the files to a new user’s home.

I must say, I appreciate the help, but it is not worth you putting a big effort into this. I have already fixed it with grep and vi. If you can see a general solution well thats great, go ahead. There is probably something that could be done with awk and sed… I am wary of such manouvres, they can make unexpected changes.

If they used $HOME instead of /home/nevj this would not be an issue

Regards
Neville

Nev,

See if this helps…

https://support.mozilla.org/en-US/questions/1065938

Actually save the directory somewhere handy.