Linux
Li Wei
Preface
Operating System
An operating system (OS) is a computer program that manages hardware and software resources of a computer, and it serves as the core and foundation of a computer system. The OS must handle basic tasks such as managing and configuring memory, determining the priority of system resource allocation, controlling input and output devices, operating networks, and managing the file system. It also provides a user interface for interacting with the system.
Illustration of the OS as an interface:
Mobile device operating systems:
Linux System
System Overview
From the bottom up the layers are: hardware → kernel layer → shell layer → application layer → user
Kernel layer: The core and foundation, attached to the hardware platform, controlling and managing all system resources, efficiently organizing process execution, extending hardware functionality, improving resource utilization, and providing a secure and reliable environment for users.
Shell layer: The interface that interacts directly with the user. Users can type commands at the prompt; the shell interprets and executes them and outputs the results or relevant information. Therefore the shell is also called a command interpreter. Using the rich set of commands supplied by the system, many tasks can be performed quickly and easily.
File System
The Linux file system hierarchy differs significantly from the familiar Windows system; there is no concept of drive letters. There is a single root directory /, organized as a hierarchical tree.
Remote Connection
Setting the IP
NAT
First configure the NAT mode for the virtual machine. Open VMware, go to Edit → Virtual Network Editor, and set the NAT parameters.
Note: Ensure that the VMware Network Adapter VMnet8 is enabled.
Static IP
Ordinary users cannot modify network‑interface configuration, so switch to the root user to configure the IP: su root (or su).
Edit the interface configuration file:
vim /etc/sysconfig/network-scripts/ifcfg-ens33Modify the file contents as needed
Restart the network service:
systemctl restart networkVerify the IP address:
ifconfigPing the VM from the host and ping the host from the VM
To access the network from the VM, add a NAT network adapter
VM → Settings → Add
Remote Login
Server maintenance is performed remotely via an SSH client; there is no graphical interface, so all maintenance tasks must be done through commands. A Linux server needs the SSH service installed.
First run sudo apt-get install openssh-server, then connect with Xshell.
Log in with a regular user first, then switch to root.
User Management
Linux is a multi‑user, multitasking operating system. “Multi‑user” means that multiple user accounts can be created, and each user can run their own tasks simultaneously without affecting one another.
Key concepts in Linux:
- Username: the name of the user
- User’s group: the primary group the user belongs to
- Home directory: the directory the user lands in after a successful login
User Management
Current User
logname – displays the name of the current user
--help– online help--version– show version information
Switch User
su username – switch to another user
su -c command root – switch to root, execute command, then return to the original user
su – switch to the root user
Add User
Command: useradd [options] username
Options:
-c– comment; provide a descriptive comment-d– specify the user’s home directory; if the directory does not exist, use-mto create it simultaneously-m– create the user’s home directory-g– primary group for the user-G– supplementary groups for the user-s– login shell for the user-u– UID; specify the user’s numeric ID. With-o, you can reuse an existing UID
How to verify that the user was added successfully? Check /etc/passwd with cat /etc/passwd.
useradd -m Username creates the home directory, but by default it may assign a non‑bash shell, which limits functionality. Use sudo useradd -m -s /bin/bash Username to set Bash as the login shell.
User Password
A freshly installed system has a root account without a password; set one with sudo passwd root.
Regular user:
sudo passwd UserNameAdministrator (root) user:
passwd [options] UserName-l– lock the password (disable the account)-u– unlock the password-d– delete the password (account has no password)-f– force the user to change the password at next login
User Permissions
The usermod command modifies user account information by editing system account files.
Changing a user account means adjusting attributes such as UID, home directory, group membership, login shell, etc., according to actual needs.
Regular user:
sudo usermod [options] UsernameAdministrator:
usermod [options] Username- Example:
usermod -l newname oldname(rename the user)
- Example:
Delete User
Deleting a user removes the user’s entry from /etc/passwd and related files; optionally, it also removes the user’s home directory.
Regular user:
sudo userdel [options] UsernameAdministrator:
userdel [options] Username-f– force deletion even if the user is currently logged in-r– remove the user’s home directory and mail spool
Group Management
Group Operations
Add a group: groupadd groupname
Create a user and add them to a group: useradd -m -g groupname username
Add Group
Create a new group (choose a meaningful, standards‑compliant name) and add users to it using administrator privileges.
Command: groupadd [options] groupname
-g– GID; specify the numeric group ID for the new group-o– used together with-g; allows the new GID to duplicate an existing one
Modify Group
Administrator privileges are required.
Command: groupmod [options] groupname
-g– assign a new GID to the group-o– together with-g, permits the new GID to match an existing one-n– rename the group
Delete Group
Regular user:
sudo groupdel groupnameAdministrator:
groupdel groupname-f– also delete the group if it is the primary group of any user-h– display help
User’s Groups
List the groups a user belongs to: groups username
Show user and group IDs: id username
Create a user and assign a primary group: useradd -m -g groupname username
Change a user’s primary group: usermod -g groupname username
Common usermod options:
-d– new home directory-l– new login name
gpasswd
gpasswd is a tool for managing the /etc/group and /etc/gshadow files. It adds or removes a user from a group.
Command: gpasswd [option] username groupname
-a– add USER to GROUP-d– delete USER from GROUP
List all members of a group: grep 'groupname' /etc/group
System Administration
man
In the console, typing command -h / --help / -? (or just pressing Enter) shows the command’s help text.
man [command] – view the manual page, e.g., man ls. Press q to quit.
date
date displays or sets the system’s date and time.
Syntax: date [options]
-d– display the date/time represented by the given string (the string must be quoted)-s– set the date/time according to the given string (quoted)-u– display the time in UTC
(the rest of the original content was truncated)
Originally written by Li Wei (李唯_) and published in Chinese on 后端技术栈全书 (Full-Stack Backend Engineering). Translated and adapted for DriftSeas with permission.