Linux User Management

Important commands for User Management

Linux User Management
  1. To list out all the users in Linux, use the awk command with -F option. Here, we are accessing a file and printing only the first column with the help of print $1 and awk.

awk -F':' '{ print $1}' /etc/passwd

2. Using id command, you can get the ID of any username. Every user has an id assigned to it and the user is identified with the help of this id. By default, this id is also the group id of the user.

3. The command to add a user. useradd command adds a new user to the directory. The user is given the ID automatically depending on which category it falls in. The username of the user will be as provided by us in the command.

4. Using passwd command to assign a password to a user. After using this command we have to enter the new password for the user and then the password gets updated to the new password.

  1. Granting sudo Privileges:

    If you want to grant administrative (sudo) privileges to a user, add the user to the sudo group. You can do this by editing the /etc/sudoers file or using the usermod command:

  2. Changing User Information:

    You can use the usermod command to modify user information, such as the username, home directory, or shell:

    sudo usermod -l newusername oldusername # Change username

    sudo usermod -d /new/home/directory username # Change home directory

    sudo usermod -s /bin/bash username # Change default shell

  3. Deleting a User:

    To delete a user, use the userdel command:

    sudo userdel username

  4. This command only removes the user. If you want to delete the user's home directory and mail spool, you can use the -r option:

    sudo userdel -r username