Rename existing user

Hi!

Due to… reasons… I had to create a fresh user on my TW, as the old user is… eehm… mentally impaired, so to say, as some config is messed up and audio not working longer.

But this old, defective user is “my” user for each and everything and I run into problems (ssh, network copying) with file owners etc. all the time.

So I wanted to delete this old user and subsequently rename the new, functional account to my old user name.

Any thins to consider? Do I have to rename the home partition?

I hope you understand that the deciding factor here is the userid (UID). The username is only a human readable replacement for it. But yes, apart from the place where the username is coupled to the UID (the /etc/passwd file). it is normal also used for the name of the home directory of a user within /home. And in /etc/shadow. And possibly in /etc/group. And possibly in other configuration files (we can not know what “special things” you configured, like /etc/ftpusers, etc.)

TBH I’m looking for solutions, not problems, so:

Has anybody done something along this line

https://linuxtechlab.com/rename-user-in-linux-rename-home-directory/

in TW and what are the problems that will occur (never seen a solution that comes without new problems TBH)…

Actually you want to keep the existing user. But you want to get rid of the broken configuration files. Log out from the machine and make sure all processes are terminated. As root do the following:move the existing home directory:

  1. mv /home/rasputin /home/rasputin-backup.
  2. create a new home directory: mkdir /home/rasputin
  3. copy /etc/skel: cp -r /etc/skel/ /home/rasputin
  4. chown -R rasputin:users /home/rasputin
  5. login again and move data from /home/rasputin-backup as appropriate

You may succeed in using usermod (as suggested there in the first section).

I am not sure why usermod does then not change the name of the home directory. When it doesn’t then use the suggestion in the second section.

Of course that user should not be logged in at all. And the commando’s should be run as root (of course your preferred way to do so which is not necessery the infamous sudo).

And of course read

man usermod

first.

Henk explained what changes are needed.

Isn’t this overkill?

When I want to create a new user account for testing, I don’t actually do that. I have an existing test account.

I go to the home directory of that account, and:

rm -rf .??*

which cleans out all settings for that user.

Then when that test user logs in, new default settings are automatically generated for the user.

If I want to do that to my own account:

1: login at command line (first logout from GUI).
2:


mkdir OLD
mv .??* OLD/.

3: logout from command line and login to GUI account. I can look in OLD to recover any settings that I want to restore.

Hy!

What is this .??* selector doing?!

Read

man bash

about Pathname Expansion.

So now you have two users

  • an “old” one which has some not working configurations (e.g. audio)
  • a “new” one with its own name and UID/GID which cannot automatically “replace” the “old” user in many places (e.g. file owner ships)

Basically i see three ways to fix this situation

  1. repair the “old” user (probably very difficult?)
  2. find all the places where the “old” users name and/or UID/GID are referenced/used and replace them with the “new” users name and/or UID/GID (difficult and error prone!)
  3. do as proposed by nrickert
    and karlmistelberger

In all cases where i had messed up my user (on openSUSE Tumbleweed) i always used option 3 right from the beginning (i.e. i never created a second user). This worked so far without any problems.

Regards

susejunky

Many thanks! That did the trick! Lots of settings to adjust again, but back to old user … :slight_smile: