8 - Managing Linux Users

ROOT USER(super user) The root user is called a superuser because it has powers far beyond those of normal users.As root, you can access files and change the system in ways other users cannot.But you can also wipe out your entire hard drive in just ten keystrokes. The "root" user should not be used normally. This user should be used only when we plan do do some changes to our OS that require special permission. So is better to create a user for your daily jobs that you will use, and avoid using the root user. Creating a user in Linux In Linux new users are created by the superuser "root". Every user needs a login and a password. Each user must belong to a primary group and haveaccess or other privilages to several other secondary groups. To create a new userlogin you need to be loged in as ROOT user. Command to create a new user "useradd": Syntax

    bash:>
    useradd [option] "user name"
  
Options
  • [-d] home directory
  • [-s] starting program (shell)
  • [-p] password
  • [-g] (primary group assigned to the users)
  • [-G] (Other groups the user belongs to)
  • [-m] (Create the user's home directory)
  • Examples Now imagine you need to create a user called "JonDoe" with the password "lost" that has as primary group "MainGroup" and also he is assigned to "LostGroup" as well . - before this we need to make sure that the groups exist.
        bash:>
        useradd  -gMainGroup -GLostGroup -plost JonDoe
    Deleteing a User Command to delete a new user "userdel": Syntax
        bash:>
        userdel [option] "username"
    Option [-r] - remove the user directory content as well. Altering an User in Linux To alter a user specification we will use the "usermod" command. Syntax
        bash:>
        usermod [option] "username"
    Otions
  • [-d] home directory
  • [-s] starting program (shell)
  • [-p] password
  • [-g] (primary group assigned to the users)
  • [-G] (Other groups the user belongs to)
  • Example the most commond use of "usermod" command is the password change:
        bash:>
        usermod -p"new pass" JonDoe
    - so we have just changed the password of JonDoe user. Note : we can also change the passowrd just using the "passwd" command. After creating a new user you need to give him a password, so for this you will need to use the "passwd" command: Syntax
        bash:>
        passwd "user name"
    The "passwd" gives you the write to change your password by using the following Syntax
        bash:>
        passwd
    Enter existing password:"your old password"
    Enter new password:"your new password"
    Enter new password again:"your new password" (this is to validate)
    If you are the root and decide to change the password of a user you will just use following Syntax :
      bash:>
      passwd "username"
    Enter new password:"new passowrd"
    Enter new password again:"new passowrd" (this is to validate)
    How to see the user information as "root" user. User names and primary groups are stored in /etc/passwd .This file can be edited directly but is not recommended. To see the file just use the following command :
      bash :>
      vi /etc/passwd
    Example
  • 1-User (name normally all lower case) -Should be between 1 and 32 characters in length.
  • 2-Password (encrypted - only contains the letter 'x') -Password is stored in /etc/shadow file
  • 3-User ID (a unique number of each user)Each user must be assigned a user ID (UID). UID 0 (zero) is reserved for root and UIDs 1-99 are reserved for other predefined accounts. Further UID 100-999 are reserved by system for administrative and system accounts/groups.
  • 4-Primary Group ID -The primary group ID (stored in /etc/group file)
  • 5-Comment (Normally the person's full name)
  • 6-Home directory (normally /home/ - The absolute path to the directory the user will be in when they log in. If this directory does not exists then users directory becomes "/".
  • 7-Default shell (normally /bin/bash) -The absolute path of a command or shell (/bin/bash).Typically, this is a shell.
  • To see the details for a specific user use this command
      bash:>
      grep "user name" /etc/passwd
    su - Switch User command. To switch to another user, use the su command. This is most commonly used to switch to the root account. Example To switch to root account :
      bash:>su
      Enter root's passwd
    Example To switch to another user :
      bash:>  su "user name"Enter users's password or root password
    To return to original user, type exit and you will be back to previous user.