Chapter 10: Secure remote access
Exercise: Secure remote access review
Give a service account key-only access, harden the SSH server without locking yourself out, and move files with scp and rsync, mirroring a directory.
Secure remote access review
- Set up key authentication and a host alias.
- Harden sshd with a correctly named drop-in.
- Transfer and mirror files with scp and rsync.
Before you start: reset the servers and complete this chapter's lessons. You work on workstation as student and use ssh root@servera for the administration. The grader looks at the hardening settings, the account, the copied files and your answers.txt; it connects to servera as root with a key, so do not set PermitRootLogin no.
- On servera, create the account
ops(passwordOps-Pass-2026). On workstation, create the key~/.ssh/id_opsand install it withssh-copy-id. Add aHost opsaalias to~/.ssh/config. - In
/etc/ssh/sshd_config.d/10-hardening.confon servera, setPasswordAuthentication no,X11Forwarding no,MaxAuthTries 3andLoginGraceTime 30. Check withsshd -Tand reload. Keep a second session open while you do it. - Copy
inventory.txtto the home directory ofops. - Copy
reports/into/home/ops/mirror/with rsync. Then deletereports/b.txtlocally and run rsync with--delete. - Put servera's Ed25519 host key fingerprint and key type in
answers.txt.
Start the exercise
[student@workstation ~]$ lab start sa-ssh-review
[student@workstation ~]$ cd ~/sa-ssh-review
[student@workstation sa-ssh-review]$Account, key and alias
[student@workstation sa-ssh-review]$ ssh root@servera "useradd -m ops && echo 'Ops-Pass-2026' | passwd --stdin ops"
[student@workstation sa-ssh-review]$ ssh-keygen -t ed25519 -f ~/.ssh/id_ops -N '' -C 'student@workstation (ops)'
[student@workstation sa-ssh-review]$ ssh-copy-id -i ~/.ssh/id_ops.pub ops@servera
[student@workstation sa-ssh-review]$ cat >> ~/.ssh/config <<'EOT'
Host opsa
HostName servera
User ops
IdentityFile ~/.ssh/id_ops
IdentitiesOnly yes
EOT
[student@workstation sa-ssh-review]$ ssh opsa hostname
servera.lab.example.comHarden sshd
[student@workstation sa-ssh-review]$ ssh root@servera
[root@servera ~]# printf 'PasswordAuthentication no\nX11Forwarding no\nMaxAuthTries 3\nLoginGraceTime 30\n' > /etc/ssh/sshd_config.d/10-hardening.conf
[root@servera ~]# sshd -t && systemctl reload sshd
[root@servera ~]# sshd -T | grep -E '^(passwordauthentication|x11forwarding|maxauthtries|logingracetime) '
logingracetime 30
maxauthtries 3
passwordauthentication no
x11forwarding noIn a second terminal, run ssh opsa hostname to prove the key login still works before you close the first session.
Copy and mirror
[student@workstation sa-ssh-review]$ scp inventory.txt opsa:
[student@workstation sa-ssh-review]$ rsync -av reports/ opsa:mirror/
[student@workstation sa-ssh-review]$ rm reports/b.txt
[student@workstation sa-ssh-review]$ rsync -avn --delete reports/ opsa:mirror/
[student@workstation sa-ssh-review]$ rsync -av --delete reports/ opsa:mirror/
[student@workstation sa-ssh-review]$ ssh opsa ls mirror
a.txt
c.txtRecord the fingerprint and grade
Fill in answers.txt (use ssh-keygen -lF servera; the type is the word ED25519 in the listing), then:
Check your work with lab grade sa-ssh-review, then put the exercise away with lab finish sa-ssh-review.