• VMware

    Learn about VMware virtualization for its products like vsphere ESX and ESXi, vCenter Server, VMware View, VMware P2V and many more

  • Linux

    Step by step configuration tutorials for many of the Linux services like DNS, DHCP, FTP, Samba4 etc including many tips and tricks in Red Hat Linux.

  • Database

    Learn installation and configuration of databases like Oracle, My SQL, Postgresql, etc including many other related tutorials in Linux.

  • How to create user without useradd command in Linux


    Follow these steps to create a user without using useradd command in Red Hat Linux.

    Step 1
    Add an entry of user details in /etc/passwd

    The field details are as shown below
    username:password:UID:GID:Comments:Home_Directory:Login Shell
    # vi /etc/passwd
    user:x:501:501:test user:/home/user:/bin/bash

    Step 2



    You will have to create a group with same name. So add a new entry in /etc/group
    # vi /etc/group
    user:x:501:

    Step 3
    Assign a password to the user
    # passwd user
    Changing password for user user.
    New password:
    Retype new password:
    passwd: all authentication tokens updated successfully.

    Now let us try to login with our newly created user
    # su - user
    -bash-4.1$

    You should see [user@test ~]$ instead of -bash-4.1$ prompt. So why does this happens?





    Let us check the contents of its home directory
    -bash-4.1$ ls -al
    drwxr-xr-x 2 root root 4096 Jan 12 14:27 .
    drwxr-xr-x. 3 root root 4096 Jan 12 14:27 ..

    So, as you see none of the default contents of a normal user home directory is present like .bashrc, .bash_profile etc.

    Final Step 4
    NOTE: /etc/skel directory contains all the defaults files which are present inside the home folder of any user

    So, copy the contents from /etc/skel inside /home/user using the below command
    [root@test ~]# cp -v /etc/skel/.* /home/user/
    cp: omitting directory `/etc/skel/.'
    cp: omitting directory `/etc/skel/..'
    `/etc/skel/.bash_logout' -> `/home/user/.bash_logout'
    `/etc/skel/.bash_profile' -> `/home/user/.bash_profile'
    `/etc/skel/.bashrc' -> `/home/user/.bashrc'
    `/etc/skel/.emacs' -> `/home/user/.emacs'
    cp: omitting directory `/etc/skel/.gnome2'
    cp: omitting directory `/etc/skel/.mozilla'

    Now re login to the user
    [root@test user]# su - user
    [user@test ~]$

    And you are good to go.



    IMPORTANT NOTE:
    But one more thing, did you noticed I didn't touched /etc/shadow file while it also contains all the user related details. As soon as we assign a password to the user an entry for that user is created inside /etc/shadow

    NOTE: Do not manually edit /etc/shadow file because it contains the encrypted password section which is automatically generated
    # cat /etc/shadow | grep user
    user:
    $6$HG.agA9Q$X2scLxur6G6FIW0eb1ArgAQcnioNLJmeBjDX.FAvfchXUhElwVKhwa3hHCFMI/vNUdr3fgqcge2PTEaKFfzXW/:16082::::::

    Let me know your success and failures

    Deepak Prasad

    is a techie and an author who is still trying to survive in this IT generation with very little knowledge he has on Linux/Unix, VMware, SAN Storage, Automation, networking etc

    You can follow him on Facebook or Google+


    Do you also have something to share here?
    Join GoLinuxHub Team as an Author, Click here for more information
    How to create user without useradd command in Linux How to create user without useradd command in Linux Reviewed by Deepak Prasad on Sunday, January 12, 2014 Rating: 5

    18 comments:

    1. while assigning password with command "passwd username" iam getting error

      passwd: authentication token manipulation error

      what to do?

      ReplyDelete
      Replies
      1. Check your /etc/password and /etc/group

        Delete
    2. Password assigned by root user. Try wit help sudo user

      ReplyDelete
    3. hi i dont have any user except root and i am trying to create new user with out useradd command and getting following error message.

      1.)created user by editing /etc/password
      user:x:501:501::/home/user:/bin/bash
      2.)edited /etc/group entry
      user:x:501:
      3.)login to user
      -bash-4.1$ ls -al
      ls: cannot open directory .: Permission denied

      please help me

      ReplyDelete
      Replies
      1. danish kaha:

        mkdir /home/user/
        then open directory mr rama

        Delete
      2. danish kaha:

        mkdir /home/user/
        then open directory mr rama

        Delete
      3. danish kaha:

        mkdir /home/user/
        then open directory mr rama

        Delete
      4. correct danish, after making directory change its owner and group as user with the chown & chgrp command
        chown user /home/user
        chgrp user /home/user

        Delete
    4. After making directory in /home change owner and group setting through chown and chgrp commands:

      chown user /home/user
      chgrp user /home/user

      Now login again
      su - user

      ReplyDelete
    5. hai guys.....
      in my Linux machine there is no file in /etc/skel so error is like -bash-1.4$ what is the solution for recovery skeleton

      ReplyDelete
    6. we can newusers command right! i think it's pretty much easier than the way that you described !!!

      ReplyDelete
    7. I am not able to use the last step I.e. cp -v /etc/skel/.* /home/user/
      It's showing error such as 'target directory' is not a directory.
      Pls help me.

      ReplyDelete
      Replies
      1. create home directory for user
        example: mkdir /home/username
        after cp -v /etc/skel.* /home/username

        Delete
    8. how the /etc/shadow file got updated while the normal user changing his password? As only root user has the access then why it happens ?

      ReplyDelete
      Replies
      1. By default a normal is allowed to change his/her password assuming he/she knows the current password which will update the shadow file if they manage to change their password successfully.

        Delete
    9. Is there any shell script that will add user without Useradd utility?? if there don't be late in replying me back!

      ReplyDelete
      Replies
      1. Just combine all these commands in a script and add some checks so that your script does not do any harm

        Delete

    Powered by Blogger.