Skip to content

Commit 89d53e4

Browse files
Update/linux exercise users and groups (bregman-arie#198)
* updated answers of linux users and groups section
1 parent 9790bb7 commit 89d53e4

File tree

1 file changed

+84
-16
lines changed

1 file changed

+84
-16
lines changed

README.md

+84-16
Original file line numberDiff line numberDiff line change
@@ -1904,28 +1904,80 @@ Nginx, Apache httpd.
19041904
</b></details>
19051905

19061906
<details>
1907-
<summary>How do you create users? Where user information is stored?</summary><br><b>
1908-
</b></details>
1907+
<summary>How do you create users? Where user information is stored?</summary><br>
1908+
1909+
Command to create users is `useradd`
1910+
1911+
Syntax:
1912+
`useradd [options] Username`
1913+
1914+
There are 2 configuration files, which stores users information
1915+
1916+
1. `/etc/passwd` - Users information like, username, shell etc is stored in this file
1917+
1918+
2. `/etc/shadow` - Users password is stored in encrypted format
1919+
</details>
19091920

19101921
<details>
1911-
<summary>Which file stores information about groups?</summary><br><b>
1912-
</b></details>
1922+
<summary>Which file stores information about groups?</summary><br>
1923+
1924+
`/etc/groups` file stores the group name, group ID, usernames which are in secondary group.
1925+
</details>
19131926

19141927
<details>
1915-
<summary>How do you change/set the password of a user?</summary><br><b>
1916-
</b></details>
1928+
<summary>How do you change/set the password of a user?</summary><br>
1929+
1930+
`passwd <username>` is the command to set/change password of a user.
1931+
</details>
19171932

19181933
<details>
1919-
<summary>Which file stores users passwords? Is it visible for everyone?</summary><br><b>
1920-
</b></details>
1934+
<summary>Which file stores users passwords? Is it visible for everyone?</summary><br>
1935+
1936+
`/etc/shadow` file holds the passwords of the users in encryted format. NO, it is only visble to the `root` user
1937+
</details>
19211938

19221939
<details>
1923-
<summary>Do you know how to create a new user without using adduser/useradd command?</summary><br><b>
1924-
</b></details>
1940+
<summary>Do you know how to create a new user without using adduser/useradd command?</summary><br>
1941+
1942+
YES, we can create new user by manually adding an entry in the `/etc/passwd` file.
1943+
1944+
For example, if we need to create a user called `john`.
1945+
1946+
Step 1: Add an entry to `/etc/passwd` file, so user gets created.
1947+
1948+
`echo "john:x:2001:2001::/home/john:/bin/bash" >> /etc/passwd`
1949+
1950+
Step 2: Add an entry to `/etc/group` file, because every user belong to the primary group that has same name as the username.
1951+
1952+
`echo "john:x:2001:" >> /etc/group`
1953+
1954+
Step 3: Verify if the user got created
1955+
1956+
`id john`
1957+
1958+
</details>
19251959

19261960
<details>
1927-
<summary>What information is stored in /etc/passwd? explain each field</summary><br><b>
1928-
</b></details>
1961+
<summary>What information is stored in /etc/passwd? explain each field</summary><br>
1962+
1963+
`/etc/passwd` is a configuration file, which contains users information. Each entry in this file has, 7 fields,
1964+
1965+
`username:password:UID:GID:Comment:home directory:shell`
1966+
1967+
`username` - The name of the user.
1968+
1969+
`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.
1970+
1971+
`UID` - User ID of the user.
1972+
1973+
`GID` - Group ID
1974+
1975+
`Comment` - This field is to provide description about the user.
1976+
1977+
`home directory` - Abousulte path of the user's home directory. This directory gets created once the user is added.
1978+
1979+
`shell` - This field contains the absolute path of the shell that will be used by the respective user.
1980+
</details>
19291981

19301982
<details>
19311983
<summary>How to add a new user to the system without providing him the ability to log-in into the system?</summary><br><b>
@@ -1942,8 +1994,17 @@ Use su - to switch to root
19421994
</b></details>
19431995

19441996
<details>
1945-
<summary>What is the UID the root user? What about a regular user?</summary><br><b>
1946-
</b></details>
1997+
<summary>What is the UID the root user? What about a regular user?</summary><br>
1998+
1999+
UID of root user is 0
2000+
2001+
Default values of UID_MIN and UID_MAX in `/etc/login.defs`
2002+
`UID_MIN` is `1000`
2003+
`UID_MAX` is `60000`
2004+
2005+
Actually, we can change this value. But UID < 1000 are reserved for system accounts.
2006+
Therefore, as per the default configuration, for regular user UID starts from `1000`.
2007+
</details>
19472008

19482009
<details>
19492010
<summary>What can you do if you lost/forogt the root password?</summary><br><b>
@@ -1952,8 +2013,10 @@ Re-install the OS IS NOT the right answer :)
19522013
</b></details>
19532014

19542015
<details>
1955-
<summary>What is /etc/skel?</summary><br><b>
1956-
</b></details>
2016+
<summary>What is /etc/skel?</summary><br>
2017+
2018+
`/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.
2019+
</details>
19572020

19582021
<details>
19592022
<summary>How to see a list of who logged-in to the system?</summary><br><b>
@@ -1968,6 +2031,11 @@ Using the `last` command.
19682031
* usermod
19692032
* whoami
19702033
* id</summary><br><b>
2034+
2035+
`useradd` - Command for creating new users
2036+
`usermod` - Modify the users setting
2037+
`whoami` - Outputs, the username that we are currently logged in
2038+
`id` - Prints the
19712039
</b></details>
19722040

19732041
<details>

0 commit comments

Comments
 (0)