DEV Community

AWS Cloud Security Roadmap, Phase 0 / Ch.2: Linux for Cloud Engineers (Users, Permissions, systemd, Logs, SSH)

This is Chapter 2 of a full series. The complete roadmap (networking → Linux → AWS → DevOps → DevSecOps → Cloud Security Engineering → Architecture) lives here:
AWS Cloud Security Roadmap: The Full Learning Path from Networking to Security Engineering

Chapter 1

covered how a web request travels. Now we learn the operating system most cloud workloads actually run on.

Why Linux first?

EC2 instances, containers, Lambda runtimes, CI runners: nearly all of it is Linux underneath. When something breaks at 2 a.m., you won't have a console button for it. You'll have a shell, logs and your own understanding of users, permissions and processes.

Goal of this chapter: run a small service as an unprivileged user under systemd, break it five different ways, and recover each time using only logs and shell tools.


1. Filesystem map

Path What lives there
/etc System configuration (sshd_config, fstab, service configs)
/var/log Logs (syslog/messages, auth.log/secure, app logs)
/home User home directories (~/.ssh lives here)
/opt Self-contained third-party or custom apps
/usr Installed programs and libraries
/tmp Temporary files, cleared often, world-writable
/proc, /sys Kernel and process info exposed as files

Everything is a file, including processes (/proc/<pid>) and devices (/dev). That's why shell tools work on almost everything.

2. Users, groups, sudo

id                       # who am I, which groups
whoami
getent passwd statusapp  # look up a user
sudo -l                  # what may I run with sudo
Enter fullscreen mode Exit fullscreen mode

Principles to burn in:

  • Never run services as root. Give each service its own user with no login shell and no sudo.
  • Root is for administration, and sudo leaves an audit trail. Prefer sudo over logging in as root.
  • Real people get their own accounts. Shared accounts destroy accountability.

Create a service account:

sudo useradd --system --home /opt/statusapp --shell /usr/sbin/nologin statusapp
Enter fullscreen mode Exit fullscreen mode

3. Permissions


ls -l /opt/statusapp
chmod 640 file           # numeric
chmod u+x,g-w file       # symbolic
chown statusapp:statusapp file
chown -R statusapp:statusapp /opt/statusapp
Enter fullscreen mode Exit fullscreen mode

Two traps worth knowing early:

  • Directories need x to be entered. A directory with r but not x lets you list names but not open anything inside.
  • SUID (chmod u+s) makes a program run as its owner. A SUID root binary you don't recognize is a red flag:
sudo find / -xdev -perm -4000 -type f 2>/dev/null     # list SUID files
Enter fullscreen mode Exit fullscreen mode

4. Processes and signals

ps aux | head            # snapshot
ps -o pid,user,%cpu,%mem,cmd -p <PID>
top                      # live view (q to quit)
kill -TERM <PID>         # polite: "please shut down" (default)
kill -HUP  <PID>         # many daemons reload config on this
kill -KILL <PID>         # last resort: cannot be caught, no cleanup
Enter fullscreen mode Exit fullscreen mode

Try SIGTERM first so the program can close files and connections. SIGKILL skips cleanup and can leave corrupted state.

5. systemd: how services run

systemd starts, supervises and restarts services described in unit files. Key commands:

systemctl status  statusapp
systemctl start|stop|restart statusapp
systemctl enable --now statusapp      # start now AND on boot
systemctl daemon-reload               # after editing a unit file
systemctl --failed                    # what's broken right now
journalctl -u statusapp -f            # follow this service's logs
journalctl -u statusapp --since "10 min ago"
Enter fullscreen mode Exit fullscreen mode

Cron vs timers. crontab -e with */5 * * * * /opt/scripts/backup.sh is the classic way to schedule jobs. systemd timers do the same with better logging (systemctl list-timers shows what's scheduled).

6. SSH: keys, not passwords

ssh-keygen -t ed25519 -C "you@laptop"          # on YOUR machine
ssh-copy-id user@server                         # installs the public key
Enter fullscreen mode Exit fullscreen mode

The server stores public keys in ~/.ssh/authorized_keys. Permissions matter: ~/.ssh must be 700 and authorized_keys must be 600, or sshd ignores them.

Hardening in /etc/ssh/sshd_config:

PermitRootLogin no
PasswordAuthentication no
PubkeyAuthentication yes
Enter fullscreen mode Exit fullscreen mode

Always validate and keep a second session open when you change SSH settings:

sudo sshd -t                                   # syntax check, no output = OK
sudo systemctl reload ssh                      # service is "sshd" on RHEL/Amazon Linux
# test a NEW login in another terminal before closing the old one
Enter fullscreen mode Exit fullscreen mode

(Cloud preview: on AWS we'll later avoid inbound SSH completely with Systems Manager Session Manager. The Linux concepts still apply.)

7. Where to look when something is wrong

Question Command
Is the service up, and why did it die? systemctl status svc, journalctl -u svc -e
What happened on the system recently? journalctl -p err -b (errors since boot)
Who logged in or failed to? /var/log/auth.log (Debian/Ubuntu) or /var/log/secure (RHEL)
Disk full? df -h, then `du -xh / 2>/dev/null \
Out of memory? {% raw %}free -m, `ps aux --sort=-%mem \
What's holding this file open? {% raw %}lsof <file>
What's listening on which port? ss -tulpn

🛠 Build: a service under its own user

Use a throwaway Linux VM (local VM or a cloud instance you will delete).

# 1. service account and app directory
sudo useradd --system --home /opt/statusapp --shell /usr/sbin/nologin statusapp
sudo mkdir -p /opt/statusapp
echo "ok" | sudo tee /opt/statusapp/index.html
sudo chown -R statusapp:statusapp /opt/statusapp
sudo chmod 750 /opt/statusapp
Enter fullscreen mode Exit fullscreen mode

Create /etc/systemd/system/statusapp.service:

[Unit]
Description=Tiny status service
After=network.target

[Service]
User=statusapp
Group=statusapp
WorkingDirectory=/opt/statusapp
ExecStart=/usr/bin/python3 -m http.server 8080 --bind 127.0.0.1
Restart=on-failure
RestartSec=3
NoNewPrivileges=true
ProtectSystem=strict
ProtectHome=true
PrivateTmp=true

[Install]
WantedBy=multi-user.target
Enter fullscreen mode Exit fullscreen mode
sudo systemctl daemon-reload
sudo systemctl enable --now statusapp
systemctl status statusapp
curl http://127.0.0.1:8080/          # prints: ok
journalctl -u statusapp -n 20        # request log lines appear here
Enter fullscreen mode Exit fullscreen mode

What the hardening lines do: NoNewPrivileges blocks privilege escalation via SUID, ProtectSystem=strict makes the filesystem read-only for the service, ProtectHome hides home directories, PrivateTmp gives it its own /tmp.

'Break it, then recover' way

(Testing purposes) Do these one at a time on the throwaway VM, and write each fix as a runbook.

# Break What you'll see Diagnose and fix
1 sudo kill -9 $(pgrep -f "http.server 8080") Service blips, then returns journalctl -u statusapp shows the restart. Restart=on-failure did its job
2 sudo chmod 000 /opt/statusapp/index.html curl returns 404 even though the file exists Python's server reports unreadable files as "not found". ls -l shows mode 000. Fix: sudo chmod 640 ... and chown statusapp:statusapp
3 sudo systemctl stop statusapp then sudo userdel statusapp then sudo systemctl start statusapp status=217/USER in systemctl status The unit references a user that no longer exists. Recreate the user, fix ownership, start again
4 Fill the disk on the VM only: fallocate -l 20G /var/tmp/big.bin (size to match your VM) Writes fail, services misbehave df -h shows 100%. `du -xh / 2>/dev/null \
5 Edit the unit's {% raw %}ExecStart path to something wrong, then daemon-reload and restart status=203/EXEC journalctl -u statusapp -e and systemctl cat statusapp show the bad path

Runbook template (copy this format):

Symptom:   curl returns 404 but file exists
Check:     ls -l /opt/statusapp/index.html ; journalctl -u statusapp -e
Cause:     file mode 000, service user cannot read it
Fix:       chmod 640 + chown statusapp:statusapp
Prevent:   deploy files with a script that sets ownership and mode
Enter fullscreen mode Exit fullscreen mode

A small Cheat sheet

I want to... Command
See who I am and my groups id
Run something as root sudo <cmd>
Change owner / mode chown user:group f / chmod 640 f
Check a service systemctl status svc
Read a service's logs journalctl -u svc -f
Find what's listening ss -tulpn
Check disk / memory df -h / free -m
Validate SSH config sudo sshd -t

Docs


Next up: Chapter 3, Shell, Git and Python for automation (strict-mode Bash, safe Git habits, and a Python log parser).

Full roadmap with every phase, certification path and job mapping:
👉 Read the complete AWS Cloud Security Roadmap on Medium

Lab note: run destructive steps only on a disposable VM you own. Distro details (package names, service names, log paths) vary between Debian/Ubuntu and RHEL/Amazon Linux.

Top comments (0)