Following document will help you understand adding new users, groups and change ACL lists in your Linux system. It is important for a Linux System Administrator to understand the basics of Linux user/group/ACL management systems.
You can tryout all these commands on your personal linux machine.
Commands:
useradd testuser
The above command will add a new user to your system with username 'testuser' using the config file: /etc/default/useradd .
useradd -m testuser
useradd -m: to create the user's home directory if it does not exist. The files and directories contained in the skeleton directory (which can be defined with the -k option) will be copied to the home directory.
useradd -m -d /home/anydirname testuser
useradd -m -d:
-d, --home-dir HOME_DIR [-d will create anydirname as testuser's login home directory]
The new user will be created using HOME_DIR as the value for the user's login directory. The default is to append the LOGIN name to BASE_DIR and use that as the login directory name.
Important config files:
/etc/login.defs - contains default configuration settings about new user's login settings such as homedir path, permissions & more. You can vim the file to view the content.
/etc/passwd - contains user information such as:
username
encrypted password (which you obviously can't see)
userid
user's group id
full name of the user
user's home directory
login shell
A second file, called ´´/etc/shadow'', contains encrypted password as well as other information such as account or password expiration values, etc. The /etc/shadow file is readable only by the root account and is therefore less of a security risk. ... Passwords are stored in the ´´/etc/shadow'' file. Numeric user id.
adduser <> is another command to add users to your system. The difference between useradd & add user is:
useradd is native binary compiled with the system. But, adduser is a perl script which uses useradd binary in back-end.
adduser is more user friendly and interactive than its back-end useradd. There's no difference in features provided.
Remove user:
userdel testuser - this will delete username testuser from the system.
userdel -r testuser - this wiill delete username testuser with mail & home directory files of user.
How to add a user to a linux system without using useradd / adduser commands?
Example: I am adding an user called 'john85'.
1. We need to add a new lin to /etc/passwd file where the format should look like:
username:password:UID:GID:comments:/homedir/path:/bin/bash/or/bin/noshell
As per the example, let's convert the username to real data:
john85:x:1501:1501:Manually Added:/home/johnstuff:/bin/bash
UID:GID [user id group id] has to be unique so make sure that you are using higher integer.
2. Let's add this user to system group:
Add a new line to: vi /etc/group
john85:x:1501
3. Next set password for this user using command:
passwd john85
4. /etc/skel directory contains user default files such as .bashrc .mozilla etc. So, copy the contents from /etc/skel inside /home/johnstuff using the below command.
NOTE: You may need to manually create /home/johnstuff directory & then copy files from skel, besure to set change root ownership for any files of this users.