Skip to the content

Lesson 247 of 296

Linux: processes, permissions, logs and SSH

What you will learn

  • Why Linux matters for developers
  • Navigating files and reading output
  • Processes, signals and ports
  • Users, groups and file permissions
  • Services and logs with systemd
  • SSH and keys
  • Diagnosing a server problem
On this page

Why Linux?

Almost every server, container and CI runner runs Linux. You need to be comfortable in a terminal: deploying, reading logs, finding what is using a port, fixing permissions.

Files and navigation

CommandDoes
pwd, ls -la, cd /var/logWhere am I / list including hidden files with details / change directory
cat, less, head -n 20, tail -n 50Show a file / page through it / first / last lines
tail -f app.logFollow a file as it grows (live logs)
cp, mv, rm, mkdir -p, touchCopy, move or rename, remove, create directories, create empty files
find /var/www -name "*.log" -mtime +7Find files by name and age
grep -rn "ERROR" /var/log/app/Search text in files recursively, with line numbers
du -sh *, df -hSize of directories / free disk space
wc -l fileCount lines
cmd1 | cmd2Pipe: the output of one becomes the input of the next
>, >>, 2>&1Write output to a file / append / send errors to the same place

A real example (a pipeline counting the most common HTTP status codes in an nginx access log, where the status is the 9th field):

awk '{print $9}' access.log | sort | uniq -c | sort -rn | head

Processes and signals

A process is a running program with a PID (process ID).

CommandDoes
ps aux, ps aux | grep nodeList processes
top, htopLive CPU and memory use
kill PIDSend SIGTERM: ask the process to stop (graceful shutdown, Lesson 193)
kill -9 PIDSend SIGKILL: force stop immediately; last resort, no clean-up
ss -tlnp (or lsof -i :3000)Which process is listening on which port
free -h, uptimeMemory; load averages
nohup cmd &Run in the background (but use a service manager in production)

"Port 3000 is already in use": ss -tlnp | grep 3000 (or lsof -i :3000) shows the PID; stop that process.

Users, groups and permissions

Every file has an owner, a group and permissions for three classes: user (owner), group, others. Each can have read, write, execute.

-rwxr-x---  1 deploy www-data  2048 Nov 23 10:00 deploy.sh
 │└┬┘└┬┘└┬┘
 │ │  │  └── others: no access
 │ │  └───── group (www-data): read and execute
 │ └──────── owner (deploy): read, write, execute
 └────────── "-" file ("d" would be a directory)

Numeric form: r = 4, w = 2, x = 1, added per class:

ModeMeaningTypical use
755rwx r-x r-xScripts and directories everyone may read
644rw- r-- r--Normal files
600rw- --- ---Private keys, .env files
700rwx --- ---Private directories such as ~/.ssh
777Everyone can do everythingNever in production

Commands: chmod 600 .env, chmod +x deploy.sh, chown deploy:www-data file, sudo (run as root). Principle of least privilege (Lesson 265): run applications as a dedicated non-root user; never run your Node app as root.

Services and logs (systemd)

Most Linux servers use systemd to run services: start at boot, restart on crash, collect logs.

[Unit]
Description=JobPrep API
After=network.target

[Service]
User=jobprep
WorkingDirectory=/srv/jobprep
EnvironmentFile=/srv/jobprep/.env
ExecStart=/usr/bin/node dist/main.js
Restart=on-failure
KillSignal=SIGTERM
TimeoutStopSec=30

[Install]
WantedBy=multi-user.target
CommandDoes
sudo systemctl start / stop / restart jobprepControl the service
sudo systemctl enable jobprepStart at boot
systemctl status jobprepState and recent log lines
journalctl -u jobprep -fFollow the service's logs
journalctl -u jobprep --since "1 hour ago"Recent logs

Classic log files live in /var/log (/var/log/nginx/error.log, /var/log/syslog). PM2 is a common Node-specific alternative to systemd; in containers, the platform does this job.

SSH

SSH (Secure Shell) gives you an encrypted terminal on a remote server.

ssh-keygen -t ed25519 -C "you@example.com"      creates ~/.ssh/id_ed25519 (private) and .pub (public)
ssh-copy-id deploy@203.0.113.10                  installs your public key on the server
ssh deploy@203.0.113.10                           log in
scp file.txt deploy@203.0.113.10:/srv/            copy a file
  • The private key never leaves your machine (chmod 600); the public key goes in the server's ~/.ssh/authorized_keys.
  • Harden servers: disable password login and root login over SSH (PasswordAuthentication no, PermitRootLogin no in /etc/ssh/sshd_config), allow SSH only from known IPs or through a bastion or a session manager (AWS Systems Manager Session Manager needs no open SSH port at all), keep the system updated, and use a firewall (ufw allow 22/tcp).
  • ~/.ssh/config stores shortcuts (Host prod, HostName, User, IdentityFile).

Diagnosing "the site is down"

  1. Is the process running? systemctl status app or docker ps.
  2. Is it listening? ss -tlnp | grep 3000; curl -i localhost:3000/healthz from the server.
  3. What do the logs say? journalctl -u app -n 100 or docker logs --tail 100 app.
  4. Resources? df -h (full disk is a classic), free -h, top.
  5. Network path? nginx error log, firewall and security group rules, DNS (dig jobprep.example), TLS certificate expiry.

How to say it in an interview

"I am comfortable on Linux servers: navigating and searching files with grep, find and pipes, following logs with tail and journalctl, finding processes and ports with ps and ss, and stopping them with SIGTERM before resorting to SIGKILL. I understand owner, group and other permissions, using 644 for files, 755 for executables and 600 for secrets, and run apps as a non-root user. I run services with systemd or containers so they restart and log properly, and use SSH keys with password and root login disabled. When something breaks I check the process, the port, the logs, disk and memory, then the network path."

Key words

WordMeaning
Process / PIDA running program / its ID
SignalSIGTERM (polite stop), SIGKILL (force stop)
PipeSends one command's output into another
Permissions (rwx)Read, write, execute for owner, group, others
chmod / chownChange permissions / ownership
systemdLinux service manager
journalctlReads systemd logs
SSH key pairA private key you keep and a public key on servers

Now prove it

This lesson is complete when you pass the quiz and all three practice levels.