Level 6 · Cloud Computing, DevOps and Cybersecurity · Course 6.1 Linux and Servers

Module 64: Linux Commands

Goal: work confidently on a Linux system from the terminal: manage files, users and groups, understand and set permissions, control processes, and combine commands with pipes and simple scripts.

You'll need: your Linux lab from Module 63 (with a fresh snapshot).

Lessons

  1. 1Working with files15–25 minutes✓
  2. 2Users and groups15–25 minutes✓
  3. 3Permissions15–25 minutes✓
  4. 4Processes15–25 minutes✓
  5. 5Pipes, redirection and scripts15–25 minutes✓

🛠️Module practice: Project A, part 2, an admin toolkit

In your lab:

  1. A deploy user and crm group; a /srv/crm folder with correct ownership and permissions; a 600 secrets file.
  2. A backup script with set -euo pipefail, scheduled with cron.
  3. A report.sh script that prints disk space, memory, the top 5 processes by memory, and listening ports.
  4. Notes in lab-notes.md. Commit the scripts to your Git repository.

✅Module check

Explain in a few sentences, in your own words:

What are the essential Linux skills for looking after a server?

Show a good answer

A good answer mentions: managing files and folders carefully (no recycle bin; read rm -rf twice), reading and searching logs with less, tail -f and grep; users and groups with least privilege, using sudo instead of working as root, and services running as their own users; permissions (owner/group/others, read/write/execute, 600 for secrets, never 777); finding and stopping processes and checking ports; and combining commands with pipes, redirection and safe scripts (set -euo pipefail, quoted variables) scheduled with cron.

📝Module quiz

10 questions · 10 marks each · 100 marks in all · pass mark 70% · retry as often as you like ·

1. What does rm -rf ~/practice do?

Why each option is right or wrong

  • “Moves the folder to the recycle bin so it can be restored” (Incorrect): The terminal has no recycle bin; rm deletes permanently.
  • “Deletes only the empty files in the folder” (Incorrect): It deletes everything, empty or not.
  • “Shows what would be deleted, without deleting anything” (Incorrect): There's no preview; it deletes immediately.
  • “Deletes the folder and everything in it, permanently, without asking” is correct.

    -r deletes folders and their contents; -f skips confirmation and ignores errors. There's no recycle bin in the terminal, so the files are gone unless you have a backup.

    • Double-check the path: a stray space, like rm -rf ~ /practice, deletes your whole home folder.
    • Safer habit: ls the path first.

📖 Revise: Lesson 1: Working with files

Question ID module-64-q1 · Report a mistake in this question
2. How do you watch a log file as new lines are added?

Why each option is right or wrong

  • “cat filename” (Incorrect): cat prints the file once and exits; it doesn't follow new lines.
  • “head -f filename” (Incorrect): head shows the start of a file and has no follow option.
  • “ls -f filename” (Incorrect): ls lists files; it doesn't show their contents.
  • “tail -f filename” is correct.

    tail shows the end of a file, and -f (follow) keeps it open, printing new lines as they're written. Press Ctrl + C to stop.

    • Filter at the same time: tail -f app.log | grep error.
    • Systemd services: journalctl -u name -f.

📖 Revise: Lesson 1: Working with files

Question ID module-64-q2 · Report a mistake in this question
3. Why do services like Nginx run as their own users?

Why each option is right or wrong

  • “Linux allows only one program per user” (Incorrect): Users can run many programs; separate users are for isolation.
  • “It makes the service start and respond to visitors faster” (Incorrect): Speed isn't affected; security is.
  • “So the service can read every file on the server” (Incorrect): The aim is the opposite: limited access.
  • “A flaw in one service can only reach what that user can” is correct.

    If an attacker exploits a bug in Nginx, they get the permissions of the user it runs as. A dedicated user like www-data, with access only to what Nginx needs, limits the damage compared with running as root.

    • Least privilege: applied to services.
    • Your app: should have its own user too.

📖 Revise: Lesson 2: Users and groups

Question ID module-64-q3 · Report a mistake in this question
4. Should you sign in as root for everyday work?

Why each option is right or wrong

  • “Yes, it avoids typing your password repeatedly” (Incorrect): Convenience isn't worth the risk of full power on every command.
  • “Yes, root is the only user that can run programs” (Incorrect): Normal users run programs; root is for administration.
  • “Yes, on a server you set up yourself, since nobody else uses it” (Incorrect): Even alone, root turns every typo into full power and leaves no record.
  • “No, use your own user and sudo only when needed” is correct.

    As root, every typo has full power, and there's no record of who did what. Your own account with sudo for specific commands limits accidents and keeps a log.

    • Disable root SSH login: on servers.
    • Audit: sudo usage is logged.

📖 Revise: Lesson 2: Users and groups

Question ID module-64-q4 · Report a mistake in this question
5. What does chmod 600 .env mean?

Why each option is right or wrong

  • “Everyone can read it but only the owner can change it” (Incorrect): That would be 644; 600 gives others no access at all.
  • “The file is deleted after 600 seconds” (Incorrect): chmod sets permissions, not timers.
  • “The file can be run as a program by anyone” (Incorrect): Execute permission isn't set, and others have no access.
  • “Only the owner can read and write it” is correct.

    Each digit sets permissions for owner, group and others: 6 is read + write, 0 is nothing. So the owner can read and change .env, and no other user can open it, which suits secrets.

    • 4 = read, 2 = write, 1 = execute: add them up.
    • Check: ls -l .env shows -rw-------.

📖 Revise: Lesson 3: Permissions

Question ID module-64-q5 · Report a mistake in this question
6. An AI suggests chmod -R 777 to fix a permission error. What do you do?

Why each option is right or wrong

  • “Run it; it's the standard fix for permission errors” (Incorrect): It's a common shortcut but makes files open to everyone.
  • “Run it, then change it back once the app works” (Incorrect): It's easy to forget, and in the meantime anything can change your files.
  • “Run it with sudo first, to make sure the change really applies” (Incorrect): Adding sudo makes it more powerful, not safer.
  • “Refuse, and grant only the access the right user needs” is correct.

    777 lets every user on the system read, change and run every file in the folder, including secrets and code. It hides the real problem. Find which user needs access and give just that, often by changing the owner or group.

    • Diagnose: ls -l and whoami.
    • Typical fix: chown to the service's user, then 640 or 750.

📖 Revise: Lesson 3: Permissions

Question ID module-64-q6 · Report a mistake in this question
7. What's the difference between kill and kill -9?

Why each option is right or wrong

  • “kill -9 stops the process and the next eight started after it” (Incorrect): 9 is the signal number (SIGKILL), not a count of processes.
  • “kill deletes the program; kill -9 only pauses it” (Incorrect): Neither deletes the program; -9 is the forceful one.
  • “There's no difference; -9 is just an older form” (Incorrect): They send different signals with different effects.
  • “kill asks politely; kill -9 forces an immediate stop” is correct.

    Plain kill sends SIGTERM, letting the program finish requests, save data and clean up. kill -9 sends SIGKILL, which stops it instantly with no clean-up. Try plain kill first.

    • Risk of -9: half-written files or lost data.
    • Find the process id: with ps or pgrep.

📖 Revise: Lesson 4: Processes

Question ID module-64-q7 · Report a mistake in this question
8. Your app says "port 3000 already in use". How do you find what's using it?

Why each option is right or wrong

  • “ls /ports/3000” (Incorrect): Ports aren't files in a folder you can list.
  • “Restart the computer and hope it clears” (Incorrect): That may work but doesn't tell you the cause.
  • “ps aux | grep 3000” (Incorrect): That searches process names for the text 3000 and can miss the program holding the port.
  • “ss -tlnp and look for port 3000” is correct.

    ss lists network sockets; -t TCP, -l listening, -n numeric ports, -p the process. The line for :3000 shows which program and process id holds it, often an old copy of your app.

    • Alternative: lsof -i :3000.
    • Then: stop it, or use another port.

📖 Revise: Lesson 4: Processes

Question ID module-64-q8 · Report a mistake in this question
9. What's the difference between > and >>?

Why each option is right or wrong

  • “>> replaces the file; > adds to the end” (Incorrect): That's the wrong way round.
  • “They're the same; >> is just the newer, easier-to-read form” (Incorrect): One overwrites, the other appends.
  • “> sends output to the screen; >> to a file” (Incorrect): Both send output to a file.
  • “> replaces the file's contents; >> adds to the end” is correct.

    echo hi > notes.txt empties the file and writes hi. echo hi >> notes.txt keeps what's there and appends. Using > by mistake can wipe a file.

    • Logs: use >>.
    • Errors too: 2>&1 sends errors to the same place.

📖 Revise: Lesson 5: Pipes, redirection and scripts

Question ID module-64-q9 · Report a mistake in this question
10. Why start scripts with set -euo pipefail?

Why each option is right or wrong

  • “It makes the script run faster by skipping slow safety checks” (Incorrect): It adds safety checks, not speed.
  • “It's required before Bash will run any script file at all” (Incorrect): Scripts run without it; they're just less safe.
  • “It hides error messages from the terminal” (Incorrect): It stops on errors; messages still show.
  • “So they stop at the first error instead of doing damage” is correct.

    By default, Bash keeps going after a failed command. A deploy script that fails to cd might then delete files in the wrong place. -e stops on errors, -u on unset variables, and pipefail catches failures inside pipes.

    • Example danger: rm -rf "$DIR/"* with DIR unset.
    • Still test: run scripts on a test machine first.

📖 Revise: Lesson 5: Pipes, redirection and scripts

Question ID module-64-q10 · Report a mistake in this question

ProLearners Assist