knowledge

Overview

Linux system management covers the administration of users, packages, services, processes, and scheduled tasks. Understanding these mechanisms is essential for both system administration and penetration testing — user account misconfigurations, overly permissive service accounts, and scheduled tasks are common attack surfaces.


Terminology

TermDefinition
sudo”Superuser do” — allows permitted users to execute commands with elevated privileges
suSwitch user — authenticates via PAM and switches to another user context
PAMPluggable Authentication Module — handles authentication for Linux services
DaemonBackground service process running silently
systemdModern init system; manages services, boot processes, and system state
initFirst process started by the kernel (PID 1); manages all other processes
PIDProcess ID — unique number assigned to each running process
PPIDParent PID — the PID of the process that spawned the current one
ZombieA stopped process that still has an entry in the process table
CronTask scheduler using time-based expressions to run jobs at set intervals
CrontabConfiguration file storing scheduled cron jobs
RepositoryRemote server hosting packages and their metadata for a Linux distribution
DependencyA package required by another package to function correctly

Core Concepts

User Management

/etc/shadow is only readable and writable by root — it stores encrypted passwords for all users. Authentication is typically handled through PAM.

CommandDescription
sudo <command>Execute a command with superuser privileges
suSwitch to root (default) or another user
su -c "command" <user>Execute a single command as a different user
whoamiShow current user
idShow UID, GID, and group memberships
useradd -m <user>Create a new user with a home directory
userdel <user>Delete a user account and associated files
usermod -L <user>Lock a user’s password (disable login)
passwd <user>Change a user’s password
addgroup <group>Add a group to the system
delgroup <group>Delete a group
usermod -aG <group> <user>Add a user to a group

Users can belong to multiple groups, granting access to group-owned files and directories. The principle of least privilege applies — users should only have the access they need.


Package Management

Packages are archives containing software binaries, configuration files, and dependency metadata. Different distributions use different package management systems.

ToolTypeDescription
dpkgLow-levelInstall, build, remove, and manage .deb packages directly
aptHigh-levelFront-end for dpkg with dependency resolution and repository management
aptitudeHigh-levelAlternative to apt with an interactive interface
snapUniversalInstall and manage snap packages with automatic updates
gemRubyFront-end to RubyGems — standard Ruby package manager
pipPythonInstall Python packages not available in the Debian archive
gitSourceDistributed version control; used to clone and install tools from GitHub

Repositories are labeled as stable, testing, or unstable. Most systems use the stable (main) repository. Repository list: /etc/apt/sources.list

Common apt Commands

CommandDescription
apt-cache search <keyword>Search for packages by keyword
apt-cache show <package>View detailed info about a package
apt list --installedList all installed packages
sudo apt install <package> -yInstall a package
sudo apt updateRefresh package lists from repositories
sudo apt dist-upgradeUpgrade all packages including kernel

Installing from Source

git clone <github_url> [destination]        # Clone a repository
wget <repo_url>                             # Download a .deb package
sudo dpkg -i <package.deb>                 # Install the downloaded package

Service and Process Management

Services (daemons) run silently in the background. Most modern Linux distributions use systemd as the init system. Running processes are visible in /proc/ organized by PID.

systemctl — Service Control

CommandDescription
systemctl start <service>Start a service
systemctl stop <service>Stop a service
systemctl restart <service>Restart a service
systemctl status <service>Show current status and recent logs
systemctl enable <service>Enable service to start on boot (adds to SysV)
systemctl disable <service>Disable service from starting on boot
systemctl list-units --type=serviceList all active services
sudo systemctl daemon-reloadReload systemd config after editing unit files

journalctl — Service Logs

CommandDescription
journalctl -u <service>Show logs for a specific service
journalctl -u ssh.service --no-pagerShow SSH logs without pager

Process States

Processes can be: running, waiting (for event or resource), stopped, or zombie (stopped but still in process table).

ps — Process Status

CommandDescription
psList processes for current session
ps -auxList all processes with user, CPU, and memory info

kill — Send Signals to Processes

CommandDescription
kill -lList all available signals
kill -9 <PID>Force kill a process (SIGKILL)
pkill <name>Kill processes by name
pgrep <name>Find PID of a process by name
killall <name>Kill all processes with a given name

Common Signals

SignalNumberDescription
SIGHUP1Terminal controlling the process was closed
SIGINT2Interrupt from user ([CTRL+C])
SIGQUIT3Quit from user ([CTRL+D])
SIGKILL9Immediately kill — no cleanup, not graceful
SIGTERM15Graceful program termination
SIGSTOP19Stop process — cannot be handled
SIGTSTP20User suspension ([CTRL+Z]) — can be handled

Background and Foreground Processes

  • [CTRL+Z] — suspend a running process
  • jobs — list suspended/background jobs
  • bg — resume suspended process in background
  • fg <job#> — bring a background job to the foreground
  • command & — launch a process directly in the background

Task Scheduling

Tasks can be automated to run at specific times or regular intervals using systemd timers or cron.

systemd Timers

systemd timers require two unit files: a .timer and a .service.

1. Create the timer unit (/etc/systemd/system/mytimer.timer):

[Unit]
Description=My Timer

[Timer]
OnBootSec=3min
OnUnitActiveSec=1hour

[Install]
WantedBy=timers.target

2. Create the service unit (/etc/systemd/system/mytimer.service):

[Unit]
Description=My Service

[Service]
ExecStart=/full/path/to/my/script.sh

[Install]
WantedBy=multi-user.target

3. Activate:

sudo systemctl daemon-reload
sudo systemctl start mytimer.timer
sudo systemctl enable mytimer.timer

Cron

Cron is simpler than systemd timers — all jobs are stored in crontab. Edit with crontab -e.

Cron expression format: Minute Hour DayOfMonth Month DayOfWeek /path/to/command

FieldRangeNotes
Minute0–59
Hour0–23
Day of Month1–31
Month1–12
Day of Week0–7Sunday = 0 and 7
ExampleMeaning
0 */6 * * * /path/to/script.shEvery 6 hours
0 0 1 * * /path/to/script.shFirst day of every month at midnight
* * * * * /path/to/script.shEvery minute

systemd vs cron: systemd offers more event triggers and options; cron is simpler and sufficient for most time-based scheduling.



References / Images

  • systemd documentation
  • man crontab