Sub topic 2
Bring the system up to date
This chapter assumes you have finished a fresh install, can log in as root or as the first user the installer created, and can edit a file in a terminal editor such as nano or vim. Keep a second terminal or the cloud console open while you work, so a mistake does not lock you out.
Bring the system up to date
Fresh installs often ship with package lists and software that are already behind. Refresh the package index, then apply the pending upgrades.
# Debian/Ubuntu
sudo apt update
sudo apt full-upgrade
# RHEL family (Rocky, Alma, Fedora)
sudo dnf upgrade --refreshIf the kernel was upgraded, reboot. The running kernel does not change until the next boot.
Create an admin user and use sudo
Working as root every day is risky, because each mistake runs with full privileges. Create a regular user and give it sudo rights. Sudo runs a single command as root after checking the user's password.
# Debian/Ubuntu: members of the sudo group get sudo rights
sudo adduser admin
sudo usermod -aG sudo admin
# RHEL family: members of the wheel group get sudo rights
sudo useradd -m admin
sudo passwd admin
sudo usermod -aG wheel adminLog in as admin and run sudo -v. It prompts for the password and confirms the account can use sudo.
Set up SSH key authentication
An SSH key pair has a private key, which stays on your computer, and a public key, which you copy to the server. The server accepts logins from any client that proves it holds the matching private key. Run these commands on your own computer:
ssh-keygen -t ed25519 -C "admin@workstation"
ssh-copy-id [email protected]
ssh [email protected]If the last command logs you in without asking for the account password, key login works. Password login must still be enabled for ssh-copy-id to run.
Harden the SSH daemon safely
The SSH daemon, sshd, is the background service that accepts remote logins. Disable password and root logins only after key login works. Put the settings in a drop-in file:
# /etc/ssh/sshd_config.d/10-hardening.conf
PasswordAuthentication no
PermitRootLogin no
PubkeyAuthentication yesTest the syntax before you reload the service:
sudo sshd -t
sudo systemctl reload ssh # Debian/Ubuntu
# sudo systemctl reload sshd # RHEL familyKeep your current session open. In a second terminal, log in as admin again. Close the first session only after the second login succeeds.
Exercise
Why run sudo sshd -t before reloading SSH, and what does a valid configuration print?
Show answer
sshd -t checks the configuration for errors without changing the running service. A valid configuration prints nothing and exits with status 0. Errors appear with the file name and line number, so fix them before reloading.