How to change username or UserID/uid on Linux

Usermod is a useful command to manage user settings. It modifies the system account files to reflect the changes that are specified on the command line. It is capable of doing a lot of things, but here we will see how to change username and UserID or uid on Linux using usermod.

Change the username using Usermod

The command syntax is simple:

[root]# usermod -l new_username old_username

The above command only changes the username, nothing else is done. So, its a good practice to manually change the user home directory to reflect the change.

[root]# mv /home/old_username /home/new_username

Change the UID/UserID using Usermod

Here's the syntax.

[root]# usermod -u UID username

Please note that, UID 0-999 are reserved for system accounts and should not be used. The above command will change the ownership of all the files owned by the user in his home directory; stuff outside the home directory needs to be manually fixed.

For more information, take a look at usermod's manpage.

1 Comment

Anon Linuxer (not verified)
July 1st, 2010 05:00 pm
Please note that, UID 0-999 are reserved for system accounts

While that's the case with Debian, it's not true of Linux. Red Hat user UIDs start at 500 for example.

Post new comment

  • Web page addresses and e-mail addresses turn into links automatically.
  • Allowed HTML tags: <img> <a> <em> <strong> <cite> <code> <ul> <ol> <li> <dl> <dt> <dd> <blockquote> <h1> <h2> <h3> <h4> <h5> <h6> <p> <br>
  • Image links with 'rel="lightbox"' in the <a> tag will appear in a Lightbox when clicked on.
  • Search Engines will index and follow ONLY links to allowed domains.

More information about formatting options

Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.