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.
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.
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.
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 -ltnpis 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_accessis the deny list.bindpicks 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/passwdinto/etc/shadow.grpconvdoes the group pair. - /etc/inittab
- SysV: the
initdefaultentry sets the boot runlevel. systemd uses thedefault.targetlink. - PermitRootLogin no
- In
sshd_config: no direct root login over SSH.
What the exam does with this
- stop and disable are not the same. A service stopped but still enabled is back after a reboot.
/etc/nologinblocks everyone except root, and only while the file exists.hosts.allowis checked beforehosts.deny, and a match in allow ends the decision.
- 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.
Questions in this lesson
- On a Linux system using shadow passwords, what appears in the second (password) field of a normal user's line in /etc/passwd, and where does the password hash actually live? machine-checked
- On a host using TCP wrappers, /etc/hosts.deny contains `ALL: ALL` and /etc/hosts.allow contains `sshd: 192.168.1.`. A wrapped connection arrives from 192.168.1.50 for sshd. What happens? machine-checked
- A legacy host runs its telnet service under xinetd, configured in /etc/xinetd.d/telnet. Which change turns the service off while keeping the configuration file in place? machine-checked
- A contractor's account must be barred from obtaining an interactive login while the account, its UID and its files stay exactly as they are. Every other user must keep working normally. Which change achieves that? machine-checked
- Policy requires the account jrivera to change its password at least every 90 days, with a warning starting 7 days before expiry. Which command writes exactly that into /etc/shadow? machine-checked
- You inherit a host whose password hashes still sit in the second field of the world-readable /etc/passwd, with no /etc/shadow in place. Type the command from the shadow suite, with no options, that moves those hashes into /etc/shadow and leaves an x behind. machine-checked
- After setting a temporary password for alice by hand, you want the system to force her to choose her own at her next login, without locking or expiring the account. Which command does that, and what does it write into /etc/shadow? machine-checked
- While hunting for services to switch off, ss -ltn shows a socket listening on 0.0.0.0:8080 but gives you no idea which daemon owns it. Which invocation names the owning process? machine-checked
- A systemd host has no printers attached, yet cups.service is running and listening. Which TWO commands leave cups.service not started at the next boot? (Choose two.) machine-checked
- You ran systemctl disable --now ssh.service on a host, yet after a reboot connections to port 22 are still accepted, and an sshd process only appears in the process list once a client connects. What explains this, and what stops it? machine-checked
- A legacy host runs in.telnetd under xinetd. The service must stay enabled, but only clients in the management network 10.0.5.0/24 may reach it. Which attribute in /etc/xinetd.d/telnet expresses that? machine-checked
- You put the line `ALL: ALL` in /etc/hosts.deny expecting the host to refuse everything, yet the Apache web server keeps serving pages to any client. Why is the rule ignored? machine-checked
- On a host using TCP wrappers, /etc/hosts.deny contains only the line `in.telnetd: ALL` and /etc/hosts.allow is empty. A wrapped FTP daemon receives a connection from 203.0.113.9. What happens? machine-checked
- On a SysV-init system you must change which runlevel the machine boots into, by editing the entry whose action field is initdefault. Type the full path of the file that holds that entry. machine-checked
- A SysV-init server currently boots into the graphical runlevel 5 and you must make it come up in the multi-user text runlevel 3 instead. Which line in /etc/inittab decides that? machine-checked
The rest of objective 110
- Security administration tasks
- Host security — you are here
- Securing data with encryption