From 89d53e4a0217d86000bbd8de65a1c284c9c4d9c0 Mon Sep 17 00:00:00 2001
From: vanquisher <32311274+Prajwalmithun@users.noreply.github.com>
Date: Wed, 5 Jan 2022 13:09:27 +0530
Subject: [PATCH] Update/linux exercise users and groups (#198)
* updated answers of linux users and groups section
---
README.md | 100 +++++++++++++++++++++++++++++++++++++++++++++---------
1 file changed, 84 insertions(+), 16 deletions(-)
diff --git a/README.md b/README.md
index 19afb85..e993a8f 100644
--- a/README.md
+++ b/README.md
@@ -1904,28 +1904,80 @@ Nginx, Apache httpd.
-How do you create users? Where user information is stored?
-
+How do you create users? Where user information is stored?
+
+Command to create users is `useradd`
+
+Syntax:
+`useradd [options] Username`
+
+There are 2 configuration files, which stores users information
+
+1. `/etc/passwd` - Users information like, username, shell etc is stored in this file
+
+2. `/etc/shadow` - Users password is stored in encrypted format
+
-Which file stores information about groups?
-
+Which file stores information about groups?
+
+`/etc/groups` file stores the group name, group ID, usernames which are in secondary group.
+
-How do you change/set the password of a user?
-
+How do you change/set the password of a user?
+
+`passwd ` is the command to set/change password of a user.
+
-Which file stores users passwords? Is it visible for everyone?
-
+Which file stores users passwords? Is it visible for everyone?
+
+`/etc/shadow` file holds the passwords of the users in encryted format. NO, it is only visble to the `root` user
+
-Do you know how to create a new user without using adduser/useradd command?
-
+Do you know how to create a new user without using adduser/useradd command?
+
+YES, we can create new user by manually adding an entry in the `/etc/passwd` file.
+
+For example, if we need to create a user called `john`.
+
+Step 1: Add an entry to `/etc/passwd` file, so user gets created.
+
+`echo "john:x:2001:2001::/home/john:/bin/bash" >> /etc/passwd`
+
+Step 2: Add an entry to `/etc/group` file, because every user belong to the primary group that has same name as the username.
+
+`echo "john:x:2001:" >> /etc/group`
+
+Step 3: Verify if the user got created
+
+`id john`
+
+
-What information is stored in /etc/passwd? explain each field
-
+What information is stored in /etc/passwd? explain each field
+
+`/etc/passwd` is a configuration file, which contains users information. Each entry in this file has, 7 fields,
+
+`username:password:UID:GID:Comment:home directory:shell`
+
+`username` - The name of the user.
+
+`password` - This field is actually a placeholder of the password field. Due to security concerns, this field does not contain the password, just a placeholder (x) to the encrypted password stored in `/etc/shadow` file.
+
+`UID` - User ID of the user.
+
+`GID` - Group ID
+
+`Comment` - This field is to provide description about the user.
+
+`home directory` - Abousulte path of the user's home directory. This directory gets created once the user is added.
+
+`shell` - This field contains the absolute path of the shell that will be used by the respective user.
+
How to add a new user to the system without providing him the ability to log-in into the system?
@@ -1942,8 +1994,17 @@ Use su - to switch to root
-What is the UID the root user? What about a regular user?
-
+What is the UID the root user? What about a regular user?
+
+UID of root user is 0
+
+Default values of UID_MIN and UID_MAX in `/etc/login.defs`
+`UID_MIN` is `1000`
+`UID_MAX` is `60000`
+
+Actually, we can change this value. But UID < 1000 are reserved for system accounts.
+Therefore, as per the default configuration, for regular user UID starts from `1000`.
+
What can you do if you lost/forogt the root password?
@@ -1952,8 +2013,10 @@ Re-install the OS IS NOT the right answer :)
-What is /etc/skel?
-
+What is /etc/skel?
+
+`/etc/skel` is a directory, that contains files or directories, so when a new user is created, these files/directories created under `/etc/skel` will be copied to user's home directory.
+
How to see a list of who logged-in to the system?
@@ -1968,6 +2031,11 @@ Using the `last` command.
* usermod
* whoami
* id
+
+ `useradd` - Command for creating new users
+ `usermod` - Modify the users setting
+ `whoami` - Outputs, the username that we are currently logged in
+ `id` - Prints the