Host security

Reducing what an attacker can reach: turning off services that need not run, restricting who may connect, and the files that control login access.

Lesson 2 of 3 in objective 110. Security, part of LPIC-1 Exam 102-500.

Two switches, not one. Doing only half of it is the classic mistake. stop — Right now: The service ends; After a reboot: It starts again; Command: systemctl stop NAME. disable — Right now: Still running; After a reboot: Stays off; Command: systemctl disable NAME stop disable Right now The service ends Still running After a reboot It starts again Stays off Command systemctl stop NAME systemctl disable NAME
Two switches, not one. Doing only half of it is the classic mistake.

Fewer things running, fewer things reachable

A service that is not running cannot be exploited, so the first hardening step is always an inventory: systemctl list-units --type=service for what is running and ss -tulpn for what is listening. Disabling is two separate operations — systemctl stop ends it now, systemctl disable stops it starting at boot, and doing only one of them is a classic half-fix. The older inetd and xinetd super-servers started services on demand from /etc/inetd.conf or /etc/xinetd.d/, and are the answer when a question describes a service with no daemon of its own. On a SysV-init host the equivalent question about what starts at boot is answered by /etc/inittab, whose initdefault entry names the runlevel to enter when the kernel command line does not; a systemd host replaces that whole file with the default.target symlink.

The inventory is only useful once each socket has a name against it, and the flags that do it are worth learning as a set: -l for listening sockets, -t and -u to pick TCP or UDP, -n to keep addresses and ports numeric, and -p to attribute each socket to a process. The last one needs privilege — a socket owned by another user is anonymous otherwise — so sudo ss -ltnp is the invocation that answers "which daemon is holding 0.0.0.0:8080". netstat -ltnp is the net-tools spelling of the same thing, and lsof -i :8080 reaches it from the file-descriptor side.

TCP wrappers control access by host through /etc/hosts.allow and /etc/hosts.deny, with allow checked first and deny second; it is legacy but still examinable. A host firewall is the general answer, and it is worth being able to recognise iptables, nftables and the friendlier front ends firewalld and ufw by name.

xinetd carries its own access control, so a service it wraps can be filtered without TCP wrappers and without disabling it: only_from = 10.0.5.0/24 in that service's file under /etc/xinetd.d/ is the allow list, and no_access is the deny list; where an address matches both, the more specific mask wins. Do not confuse either with bind, which chooses which local address the service listens on rather than who may reach it.

Legacy TCP wrappers decide by host, and a match in hosts.allow ends it. A search over 2 places, tried in this order: the first hit ends it, and everything under the one that hits is never looked at. Going down a step means no rule in it names the host. First, /etc/hosts.allow; a hit there means the host is let in, and hosts.deny is never read. Last, /etc/hosts.deny; a hit there means the host is refused. A miss at every one of them: No rule named the host, so TCP wrappers do not refuse it. /etc/hosts.allow the host is let in, and hosts.deny is never read no rule in it names the host /etc/hosts.deny the host is refused No rule named the host, so TCP wrappers do not refuse it
Legacy TCP wrappers decide by host, and a match in hosts.allow ends it.

Who may log in at all

/etc/nologin, when it exists, blocks every non-root login and prints its contents as the reason — the standard way to close a machine for maintenance. A shell of /sbin/nologin or /bin/false in /etc/passwd stops one account being used interactively while leaving it usable by a service, and the command that puts it there is usermod -s /sbin/nologin contractor: the account, its UID and its files are untouched, only the seventh field of its passwd line changes, and nobody else on the host is affected. That is the answer when a question bars ONE named account — touch /etc/nologin would bar everybody, and passwd -l is weaker than either, because locking the password leaves any non-password route in. /etc/securetty limits which terminals root may log in on directly, and disabling root logins over SSH (PermitRootLogin no in /etc/ssh/sshd_config) is the same idea for the network.

Password policy sits in /etc/login.defs and in the PAM stack, and chage enforces ageing per account. None of this is a substitute for the general rule the exam keeps returning to: give an account the least privilege that lets it do its job.

Password SHADOWING is assumed on any current system, and the commands that turn it on are still asked about, because an inherited host may not have it. /etc/passwd has to stay world-readable so that any program can map a UID to a name; the hashes must not be. pwconv is the shadow-suite command that reconciles the two — it creates or updates /etc/shadow from /etc/passwd, moving each hash out of the world-readable file and leaving an x behind. pwunconv is its inverse and puts the hashes back, and grpconv and grpunconv are the same pair for /etc/group and /etc/gshadow.

Four ways to refuse a login, grouped by who each one shuts out. Refusing a login contains Everyone but root (the maintenance shutdown), /etc/nologin (while the file exists; its text says why), Root only, /etc/securetty (which terminals root may use directly), PermitRootLogin no (in sshd_config; the same for the network), One named account, /sbin/nologin or /bin/false (its shell in /etc/passwd; a service may still use it). Refusing a login Everyone but root the maintenance shutdown /etc/nologin while the file exists; its text says why Root only /etc/securetty which terminals root may use directly PermitRootLogin no in sshd_config; the same for the network One named account /sbin/nologin or /bin/false its shell in /etc/passwd; a service may still use it
Four ways to refuse a login, grouped by who each one shuts out.

Worth carrying in

systemctl stop / disable
Two different operations: now, and at next boot.
ss -tulpn
The inventory of what is actually reachable.
/etc/hosts.allow / .deny
TCP wrappers. Allow is consulted first.
/etc/nologin
Its existence blocks non-root logins; its contents are shown as the reason.
/sbin/nologin
A shell that refuses interactive login while leaving the account usable.
sudo ss -ltnp
-p names the owning process, and only with privilege. netstat -ltnp is the older spelling.
xinetd
Super-server starting services on demand, configured in /etc/xinetd.d/.
only_from = 10.0.5.0/24
xinetd's own allow list; no_access is the deny list. bind picks a listening address instead.
usermod -s /sbin/nologin
Bar ONE account from an interactive login, leaving UID and files alone.
pwconv
Move hashes from /etc/passwd into /etc/shadow. grpconv does the group pair.
/etc/inittab
SysV: the initdefault entry sets the boot runlevel. systemd uses the default.target link.
PermitRootLogin no
In sshd_config: no direct root login over SSH.

What the exam does with this

Objective
110. Security
Share of the exam
16.67% (the whole objective)
Questions in this lesson
15
Signed for by a person
0

Partly checked. None of the 15 questions here has been read against the cited source by a person. 15 questions have been checked against their cited clause by an automated pass — which is not the same thing, and is not a signature.

Only questions a person has signed for are used in mock exams here. That is the whole difference between the two kinds of checking above.

How these questions are written — where each question comes from, what the verification ledger records, and what happens when one is found wrong.

Drill this lesson

A lesson is one sitting: the trainer draws a short run from these questions alone and spaces the ones you get wrong.

Practise Host security

Questions in this lesson

Practise Host security

The rest of objective 110