Linux User Management

  1. How to create a new user in linux ?

    Answer : sudo useradd <username>

    eg : sudo useradd Alexa

  2. How to set a password for user ?

    Answer : sudo passwd <username>

    eg: sudo passwd Alexa

  3. How to specify home directory path for a new user while user creation ?

    Answer : Use -d option . eg: sudo useradd -d /home/test_user test_user

  4. How to create a user without a home directory ?

    Answer : use -M option . eg: sudo useradd -M test_user

  5. How to switch to another user ?

    Answer :

      whoami
     user1
     $ su - user2
     Password:
     $ whoami
     user2
     $ exit
     logout