By example

  • Change the uid of gert (now 1000) to 1002:

    usermod -u 1002 gert

    Changing user IDs with usermod will also automagically change the ownership of files within the user's home directory. For files on other locations, please refer to the section below.

  • Change the username of gert to gvandijk:

    usermod -l gvandijk gert
  • Change the gid (primary group) of gert (now 1000) to 1002:

    usermod -g 1002 gert</code>
  • Change the gid of the group thegroup (now 1500) to 1501:

    groupmod -g 1501 thegroup
  • Change the groupname of thegroup to mygroup:

    groupmod -n mygroup thegroup
  • Changing the user ID and group ID can also be combined in one command:

    usermod -u 1002 -g 1002 gert
  • Changing the user's home directory to the new location (move the directory manually!):

    usermod -d /newhomes/gvandijk gvandijk

Most usermod commands can only be executed when the user is not logged in.

Fix ownership of files

Files on a Linux filesystem are stored with metadata like owner and group using numeric IDs. When you change these IDs, you will have to fix the IDs on the files.

For files outside the home directory, you'll have to fix all the ownerships of the user's files:

find / -user 1000 -exec chown -h 1002 {} \;

Explanation: Find all kind of files/directories with user ID 1000 from the base /, then execute the command chown -h 1002 <entry> for every entry found.

Share on: TwitterHacker NewsFacebookLinkedInRedditEmail


comments powered by Disqus


Last Updated


System Administration

Connect with me on...