Create users by hand in Linux and Unix

It is usefull to know how to create users by hand in Linux and Unix. Not only because you undestand what the useradd command does in background, but also because you may not want to learn how to use the generical useradd command.

To create a user by hand, follow this steps:

I will create a sample DarthVader user:

0. Create backup files for /etc/passwd ,/etc/shadow and /etc/group, in case you destroy them, by mistake:

$ sudo su
# cd /etc
cp passwd{,.bak} #this is the same as cp passwd passwd.bak
# cp shadow{,.bak}
# cp group{,.bak}
# ls -l *.bak
-rw-r--r-- 1 root root 1527 2012-07-27 20:34 group.bak
-rw-r--r-- 1 root root 2579 2012-07-27 20:34 passwd.bak
-rw-r----- 1 root root 2559 2012-07-27 20:34 shadow.bak

1. Append the new user in the /etc/passwd file with echo, or open the /etc/passwd file with vipw and add this line:

# echo 'DarthVader:x:1699:1699:Dark Side:/home/darth/vader:/bin/bash' >> /etc/passwd

2. Append the new user in the /etc/shadow file with echo, or open the /etc/shadow file with vipw -s and add this line:

# echo 'DarthVader:x:15481:0:99999:7:::' >>/etc/shadow

3. Append the new user in the /etc/group file with echo, or open the /etc/group file with vigr and add this line:

# echo 'DarthVader:x:1699:' >>/etc/group

4. Create the user’s home directory, with mkdir:

# mkdir -p /home/darth/vader/

5. Copy the file and folders from /etc/skel in the new user’s homedir, with cp:

# cp -r /etc/skel/. /home/darth/vader/

6. Make the new user and its group the owner of the newly created homedir:

# chown DarthVader:DarthVader /home/darth/vader

7. Set the right permissions on the user’s home directory and every thing inside it, with chmod:

# chmod 755 /home/darth/vader/
# chmod -R 644 /home/darth/vader/*

8. Set the user’s passwd:

# passwd DarthVader
Enter new UNIX password:
Retype new UNIX password:
passwd: password updated successfully

This is all, your DarthVader user is ready.

Share and Enjoy

  • Twitter
  • Facebook
  • Google Plus
  • Email
  • RSS
Tagged with: , , , ,
Posted in The Linux and Unix Articles!

Leave a Reply

Your email address will not be published. Required fields are marked *

*

You may use these HTML tags and attributes: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <cite> <code> <del datetime=""> <em> <i> <q cite=""> <strike> <strong>

Subscribe

  

Subscribe to get the latest Linux news and how to guides directly on your e-mail!