16

I am trying to change my username, as per advice here however after running the following command:

CurrentName@HostName ~ $ sudo usermod -l TheNameIWantToChange -d /home/TheNameIWantToChange -m CurrentName

Terminal responds with:

CurrentName@HostName ~ $ usermod: user CurrentName is currently used by process 2491

And the username stays the same. Does anybody know how I could fix this and change my username after all?

8

To quote man usermod :

CAVEATS
   You must make certain that the named user is not executing any 
   processes when this command is being executed
   if the user's numerical user ID, the user's name, or the user's home 
   directory is being changed.  usermod
   checks this on Linux, but only check if the user is logged in 
   according to utmp on other architectures.

So, you need to make sure the user you're renaming is not logged in.

Also, I note you're not running this as root. Either run it as root, or run with "sudo usermod".

  • 2
    if you can't kill the process without it restarting, combine the command e.g. kill -9 23162 && sudo usermod -l TheNameIWantToChange -d /home/TheNameIWantToChange -m CurrentName – Richard Frank Apr 19 '17 at 11:45
  • 2
    The program usermod seems to be broken by design. If the user management is done in a LDAP server, changing a user attribute is always possible and does not depend on the running system. I am using Ansible which uses usermod and the hole system is unreliable, because changes are blocked by users logged in. – ceving Aug 2 '17 at 14:17
1

I think that you should run the command with another user. Login with root, or other user, and try again. If you are in the x window with the user that you want to change, sounds logical that the commands fails.

1

This is mainly a problem with Ubutu where you don't have a root account to login from the first place. So this create a contradiction: I am a user in the sudoer group. I cannot change my own uid.

Not sure this is the best solution. I first create a fake account foo, add this to the sudo list. Then I login to the foo account and execute usermod -g MYOWNGID mylogin

0

I have the same issue using usermod, it fixed using the -m parameter, that move the content of the home directory to a new localization. Use this option in combination with -d (modify the user main directory, where there user ).

I suggest to see the man usermod command

0

Try these steps:

  1. Set the password for root user:

sudo passwd root

  1. reboot ubuntu
  2. Login as "root" after boot up -> This will allow ubuntu not to generate any process for current user.
  3. Change the username

    usermod -l newuser -d /home/newuser -m olduser

  4. Verify the username has changed by checking the folder name with new username in /home directory
-1

You shouldn't change username of a logged in user. Instead, you should end all user's processes, disconnect, log in as a different user and then rename.

If it seems like too much work, you can hotwire the change: https://medium.com/@deltazero/linux-howto-rename-currently-operating-user-f8fae62db110

It works like this:

# your new username
newuser=dave

# root-run these all at once
sudo su -c "\
  sed -i s/$USER/$newuser/g /etc/group \
  && sed -i s/$USER/$newuser/g /etc/shadow \
  && sed -i s/$USER/$newuser/g /etc/passwd \
  && mv /home/$USER/ /home/$newuser"

# exit & reconnect under new username

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.