BaseSystem¶
Einleitung¶
In diesem HowTo beschreibe ich Schritt für Schritt die Remote Installation des FreeBSD 64 Bit BaseSystem mittels mfsBSD auf einem dedizierten Server. Um eine weitere Reproduktion der offiziellen FreeBSD Dokumentation zu vermeiden, werde ich in diesem HowTo nicht alle Punkte bis ins Detail erläutern.
Unser BaseSystem wird folgende Dienste umfassen.
- FreeBSD 15.0-RELEASE 64 Bit
- OpenSSL 3.5.4
- OpenSSH 10.0p2
- Unbound 1.24.1
Voraussetzungen¶
Zu den Voraussetzungen für dieses HowTo siehe bitte: Remote Installation
RescueSystem booten¶
Um unser mfsBSD Image installieren zu können, müssen wir unsere virtuelle Maschine mit einem RescueSystem booten. Hierfür eignet sich die auf Arch Linux basierende SystemRescueCD am Besten, welche wir mittels des mit Windows mitgelieferten cURL-Client herunterladen und unserer virtuellen Maschine als Bootmedium zuweisen.
cd "${Env:USERPROFILE}\VirtualBox VMs\FreeBSD"
curl.exe -o "systemrescue-12.03-amd64.iso" "https://fastly-cdn.system-rescue.org/releases/12.03/systemrescue-12.03-amd64.iso"
& "${Env:ProgramFiles}\Oracle\VirtualBox\VBoxManage.exe" storageattach "FreeBSD" --storagectl "AHCI Controller" --port 0 --device 0 --type dvddrive --medium "systemrescue-12.03-amd64.iso"
Wir können das RescueSystem jetzt booten.
Im Bootmenü wählen wir die erste Option "Boot with default options" aus.
Ist der Bootvorgang abgeschlossen, wird als Erstes das root-Passwort für das RescueSystem gesetzt und die Firewall deaktiviert.
setkmap de
openssl rand -hex 64 | openssl passwd -5 -stdin | tr -cd '[[:print:]]' | \
cut -c 2-17 | tee /root/_your_password_
passwd root
systemctl stop iptables
systemctl stop ip6tables
Jetzt sollten wir uns mittels PuTTY als root in das RescueSystem einloggen und mit der Installation unseres mfsBSD Image fortfahren können.
mfsBSD installieren¶
Um unsere umfangreichen Vorbereitungen nun abzuschliessen, müssen wir nur noch unser mfsBSD Image installieren und booten.
Als Erstes kopieren wir mittels PuTTYs SCP-Client (pscp) das mfsBSD Image in das RescueSystem.
pscp -P 2222 "${Env:USERPROFILE}\VirtualBox VMs\mfsBSD\mfsbsd-15.0-RELEASE-amd64.img" root@127.0.0.1:/tmp/mfsbsd-15.0-RELEASE-amd64.img
Jetzt können wir das mfsBSD Image mittels dd auf der ersten Festplatte (/dev/nvme0n1) unserer virtuellen Maschine installieren und uns anschliessend wieder aus dem RescueSystem ausloggen.
dd if=/dev/zero of=/dev/nvme0n1 count=512 bs=1M
dd if=/tmp/mfsbsd-15.0-RELEASE-amd64.img of=/dev/nvme0n1 bs=1M
exit
Abschliessend stoppen wir die virtuelle Maschine vorübergehend und entfernen die SystemRescueCD aus dem virtuellen DVD-Laufwerk.
& "${Env:ProgramFiles}\Oracle\VirtualBox\VBoxManage.exe" controlvm "FreeBSD" poweroff
& "${Env:ProgramFiles}\Oracle\VirtualBox\VBoxManage.exe" storageattach "FreeBSD" --storagectl "AHCI Controller" --port 0 --device 0 --type dvddrive --medium emptydrive
FreeBSD installieren¶
Nachdem nun alle Vorbereitungen abgeschlossen sind, können wir endlich mit der eigentlichen FreeBSD Remote Installation beginnen, indem wir die virtuelle Maschine wieder booten.
Jetzt sollten wir uns mittels PuTTY als root mit dem Passwort mfsroot in das mfsBSD Image einloggen und mit der Installation von FreeBSD beginnen können.
Info
Diese Shell nutzt das amerikanische Tastaturlayout, welches einige Tasten anders belegt als das deutsche Tastaturlayout.
Um auf das deutsche Tastaturlayout zu wechseln, wählen wir mittels kbdmap das Layout "German (accent keys)" aus:
Zunächst setzen wir die Systemzeit (CMOS clock) mittels tzsetup auf "UTC" (Universal Time Code).
Partitionieren der Festplatte¶
Bevor wir anfangen, bereinigen wir die Festplatten von jeglichen Datenrückständen, indem wir sie mit Nullen überschreiben. Je nach Festplattengrösse kann dies einige Stunden bis Tage in Anspruch nehmen. Aus diesem Grund verlegen wir diese Jobs mittels nohup in den Hintergrund, so dass wir uns zwischenzeitlich ausloggen können ohne dass dabei die Jobs automatisch von der Shell abgebrochen werden. Ob die Jobs fertig sind, lässt dann mittels ps -auxfwww und top -atCP ermitteln.
Da jeder Administrator andere Präferenzen an sein Partitionslayout stellt und wir andernfalls mit diesem HowTo nicht weiterkommen, verwenden wir im Folgenden ein Standard-Partitionslayout. Fortgeschrittenere FreeBSD-Administratoren können dieses Partitionslayout selbstverständlich an ihre eigenen Bedürfnisse anpassen.
| Partition | Mountpunkt | Filesystem | Grösse |
|---|---|---|---|
| /dev/mirror/root | / | UFS2 | 60 GB |
| /dev/mirror/swap | none | SWAP | 4 GB |
Als Erstes müssen wir die Festplatte partitionieren, was wir mittels gpart erledigen werden. Zuvor müssen wir dies aber dem Kernel mittels sysctl mitteilen, da er uns andernfalls dazwischenfunken würde.
Wir werden auf beiden Festplatten jeweils vier Partitionen anlegen, die Erste für den GPT-Bootcode, die Zweite für den EFI-Bootcode, die Dritte als Swap und die Vierte als Systempartition. Dabei werden wir die Partitionen auch gleich für modernere Festplatten mit 4K-Sektoren optimieren und statt den veralteten "MBR Partition Tables" die aktuelleren "GUID Partition Tables (GPT)" verwenden.
sysctl kern.geom.debugflags=0x10
gpart destroy -F nvd0
gpart destroy -F nvd1
gpart create -s gpt nvd0
gpart create -s gpt nvd1
gpart add -t freebsd-boot -b 40 -s 216 -l bootfs0 nvd0
gpart add -t efi -b 256 -s 3840 -l efiesp0 nvd0
gpart add -t freebsd-swap -b 4096 -s 8388608 -l swapfs0 nvd0
gpart add -t freebsd-ufs -b 8392704 -l rootfs0 nvd0
gpart add -t freebsd-boot -b 40 -s 216 -l bootfs1 nvd1
gpart add -t efi -b 256 -s 3840 -l efiesp1 nvd1
gpart add -t freebsd-swap -b 4096 -s 8388608 -l swapfs1 nvd1
gpart add -t freebsd-ufs -b 8392704 -l rootfs1 nvd1
gpart set -a bootme -i 4 nvd0
gpart set -a bootme -i 4 nvd1
Für eine leicht erhöhte Datensicherheit legen wir mittels gmirror ein Software-RAID1 an.
kldload geom_mirror
kldload zfs
sysctl vfs.zfs.min_auto_ashift=12
gmirror label -b load efiesp nvd0p2 nvd1p2
gmirror label -b load rootfs nvd0p4 nvd1p4
gmirror label -b prefer -F swapfs nvd0p3 nvd1p3
Formatieren der Partitionen¶
Nun müssen wir noch die Systempartition und die Partition für die Nutzdaten mit "UFS2" und einer 4K-Blockgrösse formatieren und aktivieren auch gleich die "soft-updates".
Mounten der Partitionen¶
Die Partitionen mounten wir unterhalb von /mnt.
Installation der Chroot-Umgebung¶
Auf die gemounteten Partitionen entpacken wir ein FreeBSD Basesystem mit dem wir problemlos weiterarbeiten können. Je nach Auslastung des FreeBSD FTP-Servers kann dies ein wenig dauern, bitte nicht ungeduldig werden.
fetch -4 -q -o - --no-verify-peer "https://download.freebsd.org/releases/amd64/15.0-RELEASE/base.txz" | tar Jxpvf - -C /mnt/
fetch -4 -q -o - --no-verify-peer "https://download.freebsd.org/releases/amd64/15.0-RELEASE/kernel.txz" | tar Jxpvf - -C /mnt/
cp -a /mnt/boot/kernel /mnt/boot/GENERIC
Unser System soll natürlich auch von den Festplatten booten können, weshalb wir jetzt den Bootcode und Bootloader in den Bootpartitionen installieren.
Festplatte 1:
newfs_msdos /dev/gpt/efiesp0
mkdir -p /mnt/boot/efi
mount -t msdosfs /dev/gpt/efiesp0 /mnt/boot/efi
mkdir -p /mnt/boot/efi/EFI/BOOT
cp /mnt/boot/loader.efi /mnt/boot/efi/EFI/BOOT/BOOTX64.efi
efibootmgr -a -c -l vtbd0p2:/EFI/BOOT/BOOTX64.efi -L FreeBSD
umount /mnt/boot/efi
gpart bootcode -b /mnt/boot/pmbr -p /mnt/boot/gptboot -i 1 nvd0
Festplatte 2:
newfs_msdos /dev/gpt/efiesp1
mkdir -p /mnt/boot/efi
mount -t msdosfs /dev/gpt/efiesp1 /mnt/boot/efi
mkdir -p /mnt/boot/efi/EFI/BOOT
cp /mnt/boot/loader.efi /mnt/boot/efi/EFI/BOOT/BOOTX64.efi
efibootmgr -a -c -l vtbd0p2:/EFI/BOOT/BOOTX64.efi -L FreeBSD
umount /mnt/boot/efi
gpart bootcode -b /mnt/boot/pmbr -p /mnt/boot/gptboot -i 1 nvd1
Vorbereiten der Chroot-Umgebung¶
Vor dem Wechsel in die Chroot-Umgebung müssen wir noch die resolv.conf in die Chroot-Umgebung kopieren und das Device-Filesysteme dorthin mounten.
cat <<'EOF' > /etc/resolv.conf
nameserver 127.0.0.1
nameserver ::1
options edns0 ndots:1 timeout:0.3 attempts:1 rotate
EOF
install -b -m 0644 /etc/resolv.conf /mnt/etc/resolv.conf
mount -t devfs devfs /mnt/dev
Betreten der Chroot-Umgebung¶
Das neu installierte System selbstverständlich noch konfiguriert werden, bevor wir es nutzen können. Dazu werden wir jetzt in das neue System chrooten und eine minimale Grundkonfiguration vornehmen.
Beim Betreten der Chroot-Umgebung setzen wir mittels /usr/bin/env -i erstmal alle Environment-Variablen zurück. Andererseits benötigen wir aber die Environment-Variablen HOME und TERM, welche wir manuell auf sinnvolle Defaults setzen.
Wir bringen etwas Farbe in die Console, passen den Prompt an und legen ee statt vi als Default-Editor fest:
cat <<'EOF' > /usr/share/skel/dot.cshrc
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#
alias h history 25
alias j jobs -l
alias la ls -aF
alias lf ls -FA
alias ll ls -lAF
alias ls ls -FGIPTW
alias l ls -FGIPTWahl
# These are normally set through /etc/login.conf. You may override them here
# if wanted.
set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
# A righteous umask
umask 22
setenv EDITOR ee
setenv PAGER less
if ($?prompt) then
# An interactive shell -- set some stuff up
set prompt = "[%B%n%b@%B%m%b:%B%~%b] %# "
set promptchars = "%#"
set filec
set history = 50000
set savehist = (5000 merge)
set autolist = ambiguous
# Use history to aid expansion
set autoexpand
set autorehash
set mail = (/var/mail/$USER)
if ( $?tcsh ) then
bindkey "^W" backward-delete-word
bindkey -k up history-search-backward
bindkey -k down history-search-forward
endif
endif
EOF
cat <<'EOF' > /usr/share/skel/dot.login
#
# .login - csh login script, read by login shell, after `.cshrc' at login.
#
# See also csh(1), environ(7).
#
# Query terminal size; useful for serial lines.
if ( -x /usr/bin/resizewin ) /usr/bin/resizewin -z
# Display a random cookie on each login.
if ( -x /usr/bin/fortune ) /usr/bin/fortune freebsd-tips
EOF
cat <<'EOF' > /usr/share/skel/dot.mailrc
#
# .mailrc - mail resources
#
# see also mail(1)
#
set append ask autoprint
set indentprefix="> "
set PAGER=less
set EDITOR=ee
set VISUAL=ee
set folder=Mail
retain bcc cc date from subject to
# include your private mail aliases
source ~/.mail_aliases
EOF
cat <<'EOF' > /usr/share/skel/dot.profile
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#
# These are normally set through /etc/login.conf. You may override them here
# if wanted.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH
# Setting TERM is normally done through /etc/ttys. Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm; export TERM
EDITOR=ee; export EDITOR
PAGER=less; export PAGER
CLICOLORS="YES"; export CLICOLOR
COLORFGBG="15;0"; export COLORFGBG
COLORTERM=truecolor; export COLORTERM
TERM=${TERM:-xterm-256color}; export TERM
MANCOLOR="1"; export MANCOLOR
MANWIDTH=tty; export MANWIDTH
# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV
# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi
# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi
# Display a random cookie on each login.
if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi
EOF
cat <<'EOF' > /usr/share/skel/dot.shrc
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#
# file permissions: rwxr-xr-x
#
umask 022
# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi
# some useful aliases
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'
alias ls='ls -FGIPTW'
alias l='ls -FGIPTWahl'
# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'
# # csh like history on arrow up and down
bind ^[[A ed-search-prev-history
bind ^[[B ed-search-next-history
# # Ctrl+right arrow: go to the next word
# # Ctrl+left arrow: go to the previous word
bind "\\e[1;5C" em-next-word
bind "\\e[1;5D" ed-prev-word
alias history='fc -l'
# Fix home/del for mobaxterm
bind ^[[5~ ed-move-to-beg
bind ^[[6~ ed-move-to-end
# set prompt: ``username@hostname:directory $ ''
PS1="\[\e[1;36m\][\[\e[1;33m\]\u@\h:\[\e[1;36m\]\w] \\$ \[\e[0m\]"
# search path for cd(1)
# CDPATH=:$HOME
EOF
cp /usr/share/skel/dot.cshrc /root/.cshrc
cp /usr/share/skel/dot.login /root/.login
cp /usr/share/skel/dot.mailrc /root/.mailrc
cp /usr/share/skel/dot.profile /root/.profile
cp /usr/share/skel/dot.shrc /root/.shrc
cp /usr/share/skel/dot.cshrc /mnt/root/.cshrc
cp /usr/share/skel/dot.login /mnt/root/.login
cp /usr/share/skel/dot.mailrc /mnt/root/.mailrc
cp /usr/share/skel/dot.profile /mnt/root/.profile
cp /usr/share/skel/dot.shrc /mnt/root/.shrc
chroot /mnt /usr/bin/env -i HOME=/root TERM=$TERM /bin/sh
Info
Diese Shell nutzt das amerikanische Tastaturlayout, welches einige Tasten anders belegt als das deutsche Tastaturlayout.
Um auf das deutsche Tastaturlayout zu wechseln, wählen wir mittels kbdmap das Layout "German (accent keys)" aus:
Zunächst setzen wir die Systemzeit (CMOS clock) mittels tzsetup auf "UTC" (Universal Time Code).
Wir setzen ein paar Defaults für "root" neu:
Das Home-Verzeichnis des Users root ist standardmässig leider nicht ausreichend restriktiv in seinen Zugriffsrechten, was wir mit einem entsprechenden Aufruf von chmod schnell ändern. Bevor wir es vergessen, setzen wir bei dieser Gelegenheit gleich ein sicheres Passwort für root.
mkdir -p /var/db/backups
mkdir -p /var/db/passwords
# Passwort erzeugen und speichern für den Systembenutzer "root"
install -b -m 0600 /dev/null /var/db/passwords/system_user_root
openssl rand -hex 64 | openssl passwd -5 -stdin | tr -cd '[[:print:]]' | \
cut -c 2-17 | tee /var/db/passwords/system_user_root | \
pw usermod -s sh -h 0 -n root
cat /var/db/passwords/system_user_root
chmod 700 /root
Shell einrichten¶
Wir bringen etwas Farbe in die Console, passen den Prompt an und legen ee statt vi als Default-Editor fest:
cat <<'EOF' > /usr/share/skel/dot.cshrc
#
# .cshrc - csh resource script, read at beginning of execution by each shell
#
# see also csh(1), environ(7).
# more examples available at /usr/share/examples/csh/
#
alias h history 25
alias j jobs -l
alias la ls -aF
alias lf ls -FA
alias ll ls -lAF
alias ls ls -FGIPTW
alias l ls -FGIPTWahl
# These are normally set through /etc/login.conf. You may override them here
# if wanted.
set path = (/sbin /bin /usr/sbin /usr/bin /usr/local/sbin /usr/local/bin $HOME/bin)
# A righteous umask
umask 22
setenv EDITOR ee
setenv PAGER less
if ($?prompt) then
# An interactive shell -- set some stuff up
set prompt = "[%B%n%b@%B%m%b:%B%~%b] %# "
set promptchars = "%#"
set filec
set history = 50000
set savehist = (5000 merge)
set autolist = ambiguous
# Use history to aid expansion
set autoexpand
set autorehash
set mail = (/var/mail/$USER)
if ( $?tcsh ) then
bindkey "^W" backward-delete-word
bindkey -k up history-search-backward
bindkey -k down history-search-forward
endif
endif
EOF
cat <<'EOF' > /usr/share/skel/dot.login
#
# .login - csh login script, read by login shell, after `.cshrc' at login.
#
# See also csh(1), environ(7).
#
# Query terminal size; useful for serial lines.
if ( -x /usr/bin/resizewin ) /usr/bin/resizewin -z
# Display a random cookie on each login.
if ( -x /usr/bin/fortune ) /usr/bin/fortune freebsd-tips
EOF
cat <<'EOF' > /usr/share/skel/dot.mailrc
#
# .mailrc - mail resources
#
# see also mail(1)
#
set append ask autoprint
set indentprefix="> "
set PAGER=less
set EDITOR=ee
set VISUAL=ee
set folder=Mail
retain bcc cc date from subject to
# include your private mail aliases
source ~/.mail_aliases
EOF
cat <<'EOF' > /usr/share/skel/dot.profile
#
# .profile - Bourne Shell startup script for login shells
#
# see also sh(1), environ(7).
#
# These are normally set through /etc/login.conf. You may override them here
# if wanted.
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin:$HOME/bin; export PATH
# Setting TERM is normally done through /etc/ttys. Do only override
# if you're sure that you'll never log in via telnet or xterm or a
# serial line.
# TERM=xterm; export TERM
EDITOR=ee; export EDITOR
PAGER=less; export PAGER
CLICOLORS="YES"; export CLICOLOR
COLORFGBG="15;0"; export COLORFGBG
COLORTERM=truecolor; export COLORTERM
TERM=${TERM:-xterm-256color}; export TERM
MANCOLOR="1"; export MANCOLOR
MANWIDTH=tty; export MANWIDTH
# set ENV to a file invoked each time sh is started for interactive use.
ENV=$HOME/.shrc; export ENV
# Let sh(1) know it's at home, despite /home being a symlink.
if [ "$PWD" != "$HOME" ] && [ "$PWD" -ef "$HOME" ] ; then cd ; fi
# Query terminal size; useful for serial lines.
if [ -x /usr/bin/resizewin ] ; then /usr/bin/resizewin -z ; fi
# Display a random cookie on each login.
if [ -x /usr/bin/fortune ] ; then /usr/bin/fortune freebsd-tips ; fi
EOF
cat <<'EOF' > /usr/share/skel/dot.shrc
#
# .shrc - bourne shell startup file
#
# This file will be used if the shell is invoked for interactive use and
# the environment variable ENV is set to this file.
#
# see also sh(1), environ(7).
#
# file permissions: rwxr-xr-x
#
umask 022
# Uncomment this to enable the builtin vi(1) command line editor in sh(1),
# e.g. ESC to go into visual mode.
# set -o vi
# some useful aliases
alias h='fc -l'
alias j=jobs
alias m="$PAGER"
alias ll='ls -laFo'
alias l='ls -l'
alias g='egrep -i'
alias ls='ls -FGIPTW'
alias l='ls -FGIPTWahl'
# # be paranoid
# alias cp='cp -ip'
# alias mv='mv -i'
# alias rm='rm -i'
# # csh like history on arrow up and down
bind ^[[A ed-search-prev-history
bind ^[[B ed-search-next-history
# # Ctrl+right arrow: go to the next word
# # Ctrl+left arrow: go to the previous word
bind "\\e[1;5C" em-next-word
bind "\\e[1;5D" ed-prev-word
alias history='fc -l'
# Fix home/del for mobaxterm
bind ^[[5~ ed-move-to-beg
bind ^[[6~ ed-move-to-end
# set prompt: ``username@hostname:directory $ ''
PS1="\[\e[1;36m\][\[\e[1;33m\]\u@\h:\[\e[1;36m\]\w] \\$ \[\e[0m\]"
# search path for cd(1)
# CDPATH=:$HOME
EOF
cp /usr/share/skel/dot.cshrc /root/.cshrc
cp /usr/share/skel/dot.login /root/.login
cp /usr/share/skel/dot.mailrc /root/.mailrc
cp /usr/share/skel/dot.profile /root/.profile
cp /usr/share/skel/dot.shrc /root/.shrc
Systemsicherheit verstärken¶
Die hier vorgestellten Massnahmen sind äusserst simple Basics, die aus Hygienegründen auf jedem FreeBSD System selbstverständlich sein sollten. Um ein FreeBSD System richtig zu härten (Hardened), kommt man jedoch nicht an komplexeren Methoden wie Security Event Auditing und Mandatory Access Control vorbei. Diese Themen werden im FreeBSD Handbuch recht ausführlich besprochen; für den Einstieg empfehle ich hier die Lektüre von Chapter 14. Security, für die weiterführenden Themen die Chapter 16. Mandatory Access Control und Chapter 17. Security Event Auditing.
OpenSSH konfigurieren¶
Da wir gerade ein Produktiv-System aufsetzen, werden wir den OpenSSH-Dienst recht restriktiv konfigurieren, unter Anderem werden wir den Login per Passwort verbieten und nur per PublicKey zulassen.
cat <<'EOF' > /etc/ssh/sshd_config
Port 22
PermitRootLogin prohibit-password
PubkeyAuthentication yes
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no
UsePAM yes
AllowAgentForwarding no
AllowTcpForwarding no
GatewayPorts no
X11Forwarding no
PermitTunnel no
PermitUserEnvironment no
UseBlacklist no
ClientAliveInterval 60
ClientAliveCountMax 3
PidFile /var/run/sshd.pid
VersionAddendum none
Subsystem sftp internal-sftp -u 0027
AllowGroups wheel admin sshusers sftponly
# Root bleibt ohne Passwort, aber ohne globales Chroot
Match User root
PasswordAuthentication no
# Admin- und Shell-Benutzer ohne Passwort-Login
Match Group admin,sshusers
PasswordAuthentication no
# Reine SFTP-Konten
Match Group sftponly
ChrootDirectory /home
ForceCommand internal-sftp -u 0027 -d /%u
PasswordAuthentication yes
KbdInteractiveAuthentication no
PermitTTY no
DisableForwarding yes
EOF
rm -f /etc/ssh/ssh_host_*_key*
ssh-keygen -q -t rsa -b 4096 -f "/etc/ssh/ssh_host_rsa_key" -N ""
ssh-keygen -l -f "/etc/ssh/ssh_host_rsa_key.pub"
ssh-keygen -q -t ecdsa -b 384 -f "/etc/ssh/ssh_host_ecdsa_key" -N ""
ssh-keygen -l -f "/etc/ssh/ssh_host_ecdsa_key.pub"
ssh-keygen -q -t ed25519 -f "/etc/ssh/ssh_host_ed25519_key" -N ""
ssh-keygen -l -f "/etc/ssh/ssh_host_ed25519_key.pub"
mkdir -p /root/.ssh
chmod 700 /root/.ssh
ssh-keygen -t ed25519 -O clear -O permit-pty -f "/root/.ssh/id_ed25519" -N ""
cat /root/.ssh/id_ed25519.pub >> /root/.ssh/authorized_keys
ssh-keygen -t ecdsa -b 384 -O clear -O permit-pty -f "/root/.ssh/id_ecdsa" -N ""
cat /root/.ssh/id_ecdsa.pub >> /root/.ssh/authorized_keys
ssh-keygen -t rsa -b 4096 -O clear -O permit-pty -f "/root/.ssh/id_rsa" -N ""
cat /root/.ssh/id_rsa.pub >> /root/.ssh/authorized_keys
Terminals absichern¶
Um zu verhindern, dass das System im Single User Mode ohne jeglichen Schutz benutzbar ist, ändern wir in der Datei /etc/ttys die Zeile console none... wie folgt ab.
Dadurch wird die Eingabe des root-Kennworts erforderlich, um das System im Single User Mode booten zu können. Den Rest sollten wir hingegen unverändert lassen.
System konfigurieren¶
Wir passen auch unsere Login-Begrüssung (motd) an.
cat <<'EOF' > /etc/motd.template
________________________________________________________________________________
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
______ , ,
| ____| __ ___ ___ /( )`
| |__ | '__/ _ \/ _ \ \ \___ / |
| __|| | | __/ __/ /- _ `-/ '
| | | | | | | (/\/ \ \ /\
|_| |_| \___|\___| / / | ` \
____ _____ _____ O O ) / |
| _ \ / ____| __ \ `-^--'`< '
| |_) | (___ | | | | (_.) _ ) /
| _ < \___ \| | | | `.___/` /
| |_) |____) | |__| | `-----' /
| | | | <----. __ / __ \
|____/|_____/|_____/ <----|====O)))==) \) /====
<----' `--' `.__,' \
| |
Welcome to our Server \ / /\
______( (_ / \______/
,' ,-----' |
`--{__________)
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
################################################################################
EOF
Die aliases-Datenbank für FreeBSDs DMA müssen wir mittels newaliases anlegen, auch wenn wir später DMA gar nicht verwenden möchten.
cat <<'EOF' > /etc/mail/aliases
# @(#)aliases 5.3 (Berkeley) 5/24/90
#
# Aliases in this file will NOT be expanded in the header from
# Mail, but WILL be visible over networks.
#
# >>>>>>>>>> The program "newaliases" must be run after
# >> NOTE >> this file is updated for any changes to
# >>>>>>>>>> show through to sendmail.
#
#
# See also RFC 2142, `MAILBOX NAMES FOR COMMON SERVICES, ROLES
# AND FUNCTIONS', May 1997
# http://tools.ietf.org/html/rfc2142
# Pretty much everything else in this file points to "root", so
# you would do well in either reading root's mailbox or forwarding
# root's email from here.
root: admin@example.com
# Basic system aliases -- these MUST be present
MAILER-DAEMON: postmaster
postmaster: root
# General redirections for pseudo accounts
_dhcp: root
_pflogd: root
auditdistd: root
bin: root
bind: root
daemon: root
games: root
hast: root
kmem: root
mailnull: postmaster
man: root
news: root
nobody: root
operator: root
pop: root
proxy: root
smmsp: postmaster
sshd: root
system: root
toor: root
tty: root
usenet: news
uucp: root
# Well-known aliases -- these should be filled in!
# manager:
# dumper:
# BUSINESS-RELATED MAILBOX NAMES
# info:
# marketing:
# sales:
# support:
# NETWORK OPERATIONS MAILBOX NAMES
abuse: root
# noc: root
security: root
# SUPPORT MAILBOX NAMES FOR SPECIFIC INTERNET SERVICES
ftp: root
ftp-bugs: ftp
hostmaster: root
webmaster: root
www: webmaster
# NOTE: /var/msgs and /var/msgs/bounds must be owned by sendmail's
# DefaultUser (defaults to mailnull) for the msgs alias to work.
#
# msgs: "| /usr/bin/msgs -s"
# bit-bucket: /dev/null
# dev-null: bit-bucket
vmail: root
clamav: root
vscan: root
EOF
newaliases
Die /etc/nscd.conf legen wir mit folgendem Inhalt an.
cat <<'EOF' > /etc/nscd.conf
#
# Default caching daemon configuration file
#
enable-cache passwd yes
enable-cache group yes
enable-cache hosts yes
enable-cache services yes
enable-cache protocols yes
enable-cache rpc yes
enable-cache networks yes
keep-hot-count hosts 16384
EOF
Die /etc/nsswitch.conf legen wir mit folgendem Inhalt an.
cat <<'EOF' > /etc/nsswitch.conf
#
# nsswitch.conf(5) - name service switch configuration file
#
group: files
# group_compat: nis
hosts: files dns
netgroup: files
networks: files
passwd: files
# passwd_compat: nis
shells: files
services: files
# services_compat: nis
protocols: files
rpc: files
EOF
Die /etc/ntp.conf legen wir mit folgendem Inhalt an.
cat <<'EOF' > /etc/ntp.conf
#
#
# Default NTP servers for the FreeBSD operating system.
#
# Don't forget to enable ntpd in /etc/rc.conf with:
# ntpd_enable="YES"
#
# The driftfile is by default /var/db/ntpd.drift, check
# /etc/defaults/rc.conf on how to change the location.
#
#
# Set the target and limit for adding servers configured via pool statements
# or discovered dynamically via mechanisms such as broadcast and manycast.
# Ntpd automatically adds maxclock-1 servers from configured pools, and may
# add as many as maxclock*2 if necessary to ensure that at least minclock
# servers are providing good consistent time.
#
tos minclock 3 maxclock 6
#
# The following pool statements will give you a random set of IPv4 and IPv6
# NTP servers geographically close to you. A single pool statement adds
# multiple servers from the pool, according to the tos minclock/maxclock
# targets.
# See http://www.pool.ntp.org/ for details. Note, pool.ntp.org encourages
# users with a static IP and good upstream NTP servers to add a server
# to the pool. See http://www.pool.ntp.org/join.html if you are interested.
#
# The option `iburst' is used for faster initial synchronization.
#
pool 2.freebsd.pool.ntp.org iburst
#
# If you want to pick yourself which country's public NTP server
# you want to sync against, comment out the above pool statements,
# uncomment the next ones, and replace CC with the country's abbreviation.
# Make sure that the hostnames resolves to a proper IP address!
#
pool 0.de.pool.ntp.org iburst
#
# To configure a specific server, such as an organization-wide local
# server, add lines similar to the following. One or more specific
# servers can be configured in addition to, or instead of, any server
# pools specified above. When both are configured, ntpd first adds all
# the specific servers, then adds servers from the pool until the tos
# minclock/maxclock targets are met.
#
server ptbtime3.ptb.de iburst
server ptbtime2.ptb.de iburst
server ptbtime1.ptb.de iburst
#
# Security:
#
# By default, only allow time queries and block all other requests
# from unauthenticated clients.
#
# The "restrict source" line allows peers to be mobilized when added by
# ntpd from a pool, but does not enable mobilizing a new peer association
# by other dynamic means (broadcast, manycast, ntpq commands, etc).
#
# See http://support.ntp.org/bin/view/Support/AccessRestrictions
# for more information.
#
restrict default limited kod nomodify notrap noquery nopeer
restrict source limited kod nomodify notrap noquery
#
# Alternatively, the following rules would block all unauthorized access.
#
#restrict default ignore
#
# In this case, all remote NTP time servers also need to be explicitly
# allowed or they would not be able to exchange time information with
# this server.
#
# Please note that this example doesn't work for the servers in
# the pool.ntp.org domain since they return multiple A records.
#
#restrict 0.pool.ntp.org nomodify nopeer noquery notrap
#restrict 1.pool.ntp.org nomodify nopeer noquery notrap
#restrict 2.pool.ntp.org nomodify nopeer noquery notrap
#
# The following settings allow unrestricted access from the localhost
#
restrict 127.0.0.1
restrict ::1
#
# If a server loses sync with all upstream servers, NTP clients
# no longer follow that server. The local clock can be configured
# to provide a time source when this happens, but it should usually
# be configured on just one server on a network. For more details see
# http://support.ntp.org/bin/view/Support/UndisciplinedLocalClock
# The use of Orphan Mode may be preferable.
#
#server 127.127.1.0
#fudge 127.127.1.0 stratum 10
# See http://support.ntp.org/bin/view/Support/ConfiguringNTP#Section_6.14.
# for documentation regarding leapfile. Updates to the file can be obtained
# from ftp://time.nist.gov/pub/ or ftp://tycho.usno.navy.mil/pub/ntp/.
# Use either leapfile in /etc/ntp or periodically updated leapfile in /var/db.
#
leapfile "/var/db/ntpd.leap-seconds.list"
# Specify the number of megabytes of memory that should be allocated and
# locked. -1 (default) means "do not lock the process into memory".
# 0 means "lock whatever memory the process wants into memory". Any other
# number means to lock up to that number of megabytes into memory.
# 0 may result in a segfault when ASLR with stack gap randomization
# is enabled.
#
#rlimit memlock 32
#
interface ignore wildcard
interface listen 127.0.0.1
interface listen ::1
EOF
Die /etc/resolvconf.conf legen wir mit folgendem Inhalt an.
Die /etc/periodic.conf legen wir mit folgendem Inhalt an.
cat <<'EOF' > /etc/periodic.conf
daily_backup_pkg_enable="YES"
daily_clean_hoststat_enable="NO"
daily_clean_tmps_enable="YES"
daily_status_gmirror_enable="YES"
daily_status_include_submit_mailq="NO"
daily_status_mail_rejects_enable="NO"
daily_status_ntpd_enable="YES"
daily_status_pkg_changes_enable="YES"
daily_submit_queuerun="NO"
security_status_pkgaudit_enable="YES"
security_status_pkgchecksum_enable="YES"
weekly_noid_enable="YES"
weekly_status_pkg_enable="YES"
EOF
Die /etc/fstab legen wir entsprechend unserem Partitionslayout an.
cat <<'EOF' > /etc/fstab
# Device Mountpoint FStype Options Dump Pass
# Custom /etc/fstab for FreeBSD VM images
/dev/mirror/rootfs / ufs rw 1 1
/dev/mirror/swapfs none swap sw 0 0
/dev/mirror/efiesp /boot/efi msdosfs rw 2 2
fdescfs /dev/fd fdescfs rw,late 0 0
EOF
mount -t fdescfs fdescfs /dev/fd
In der /etc/rc.conf werden diverse Grundeinstellungen für das System und die installierten Dienste vorgenommen.
cat <<'EOF' > /etc/rc.conf
##############################################################
### Important initial Boot-time options ####################
##############################################################
#kern_securelevel_enable="YES"
#kern_securelevel="1"
kld_list="accf_data accf_http accf_dns"
fsck_y_enable="YES"
growfs_enable="YES"
dmesg_enable="YES"
zfs_enable="YES"
zpool_reguid="zroot"
zpool_upgrade="zroot"
dumpdev="AUTO"
cloudinit_enable="YES"
qemu_guest_agent_enable="YES"
##############################################################
### Network configuration sub-section ######################
##############################################################
hostname="devnull.example.com"
##### IPv4
defaultrouter="__GATEWAY4__"
ifconfig_DEFAULT="inet __IPADDR4__"
##### IPv6
ipv6_defaultrouter="__GATEWAY6__"
ifconfig_DEFAULT_ipv6="inet6 __IPADDR6__ accept_rtadv"
##### Additional IP Addresses
### specify additional IPv4 and IPv6 addresses one per line
#ifconfig_DEFAULT_aliases="\
# inet IPV4 netmask NETMASK \
# inet IPV4 netmask NETMASK \
# inet6 IPV6 prefixlen PREFLEN \
# inet6 IPV6 prefixlen PREFLEN"
##############################################################
### Paketfilter (PF) options ###############################
##############################################################
pf_enable="YES"
pf_rules="/etc/pf.conf"
pflog_enable="YES"
##############################################################
### System console options #################################
##############################################################
keymap="de.acc.kbd"
##############################################################
### Mail Transfer Agent (MTA) options ######################
##############################################################
sendmail_enable="NONE"
sendmail_cert_create="NO"
sendmail_submit_enable="NO"
sendmail_outbound_enable="NO"
sendmail_msp_queue_enable="NO"
sendmail_rebuild_aliases="NO"
dma_flushq_enable="YES"
##############################################################
### Miscellaneous administrative options ###################
##############################################################
syslogd_flags="-ss"
clear_tmp_enable="YES"
cron_flags="$cron_flags -j 0 -J 0 -m root"
update_motd="YES"
nscd_enable="YES"
ntpd_enable="YES"
ntpd_sync_on_start="YES"
resolv_enable="NO"
##############################################################
### Jail Configuration #######################################
##############################################################
##############################################################
### System services options ################################
##############################################################
local_unbound_enable="YES"
local_unbound_tls="NO"
blacklistd_enable="NO"
sshd_enable="YES"
EOF
Es folgt ein wenig Voodoo, um die Netzwerkkonfiguration in der /etc/rc.conf zu vervollständigen.
# 1. Get Default Interface
# Looks for the line starting with 'interface:' and captures the second column
DEF_IF="$(route -n get -inet default | awk '/interface:/ {print $2}')"
[ -n "$DEF_IF" ] && sed -e "s|DEFAULT|$DEF_IF|g" -i '' /etc/rc.conf
# 2. Get IPv4 Gateway and IP
# Captures the gateway IP from route output
GW4="$(route -n get -inet default | awk '/gateway:/ {print $2}')"
[ -n "$GW4" ] && sed -e "s|__GATEWAY4__|$GW4|g" -i '' /etc/rc.conf
# Captures the primary IPv4 address (excluding loopback)
# Uses -f cidr to ensure standard CIDR notation for parsing
IP4="$(ifconfig -u -f cidr "$DEF_IF" inet | awk '/inet / && $2 !~ /^127\./ {print $2}' | head -n 1)"
[ -n "$IP4" ] && sed -e "s|__IPADDR4__|$IP4|g" -i '' /etc/rc.conf
# 3. Get IPv6 Gateway and IP
# Captures the IPv6 gateway
GW6="$(route -n get -inet6 default | awk '/gateway:/ {print $2}')"
[ -n "$GW6" ] && sed -e "s|__GATEWAY6__|$GW6|g" -i '' /etc/rc.conf
# Captures the primary Global IPv6 address
# Filters out link-local (fe80::) and loopback (::1) addresses
IP6="$(ifconfig -u -f cidr "$DEF_IF" inet6 | awk '/inet6 / && $2 !~ /^fe80:/ && $2 !~ /^::1/ {print $2}' | head -n 1)"
[ -n "$IP6" ] && sed -e "s|__IPADDR6__|$IP6|g" -i '' /etc/rc.conf
Wir richten die /etc/hosts ein.
sed -e "s|my.domain/example.com/g" -i '' /etc/hosts
echo '__IPADDR4__ devnull.example.com devnull' >> /etc/hosts
echo '__IPADDR6__ devnull.example.com devnull' >> /etc/hosts
# 1. Get Default Interface
# Looks for the line starting with 'interface:' and captures the second column
DEF_IF="$(route -n get -inet default | awk '/interface:/ {print $2}')"
# 2. Get IPv4 IP
# Captures the primary IPv4 address (excluding loopback)
IP4="$(ifconfig "$DEF_IF" inet | awk '/inet / && $2 !~ /^127\./ {print $2}' | head -n 1)"
[ -n "$IP4" ] && sed -e "s|__IPADDR4__|$IP4|g" -i '' /etc/hosts
# 3. Get IPv6 IP
# Captures the primary Global IPv6 address
# Filters out link-local (fe80::) and loopback (::1) addresses
IP6="$(ifconfig "$DEF_IF" inet6 | awk '/inet6 / && $2 !~ /^fe80:/ && $2 !~ /^::1/ {print $2}' | head -n 1)"
[ -n "$IP6" ] && sed -e "s|__IPADDR6__|$IP6|g" -i '' /etc/hosts
Systemgruppen anlegen¶
Zur besseren Trennung beziehungsweise Gruppierung unterschiedlicher Nutzungszwecke legen wir ein paar Gruppen an (admin für rein administrative Nutzer, users für normale Nutzer, sshusers für Nutzer mit SSH-Zugang und sftponly für reine SFTP-Nutzer).
pw groupshow admin >/dev/null 2>&1 || pw groupadd -n admin -g 1000
pw groupshow users >/dev/null 2>&1 || pw groupadd -n users -g 2000
pw groupshow sshusers >/dev/null 2>&1 || pw groupadd -n sshusers -g 3000
pw groupshow sftponly >/dev/null 2>&1 || pw groupadd -n sftponly -g 4000
Systembenutzer anlegen¶
Um nicht ständig mit dem root-User arbeiten zu müssen, legen wir uns einen Administrations-User an, den wir praktischerweise "admin" nennen. Diesem User verpassen wir die Standard-Systemgruppe "admin" und nehmen ihn zusätzlich in die Systemgruppe "wheel" auf, damit dieser User später per su zum root-User wechseln kann. Das Home-Verzeichnis des admin-Users lassen wir automatisch anlegen und setzen seine Standard-Shell auf /bin/tcsh. Ein sicheres Passwort bekommt er selbstverständlich auch noch.
# Passwort erzeugen und speichern für den Systembenutzer "admin"
id -u admin >/dev/null 2>&1 || \
install -b -m 0600 /dev/null /var/db/passwords/system_user_admin
id -u admin >/dev/null 2>&1 || \
openssl rand -hex 64 | openssl passwd -5 -stdin | tr -cd '[[:print:]]' | \
cut -c 2-17 | tee /var/db/passwords/system_user_admin | \
pw useradd -h 0 -n admin -u 1000 -g admin -c 'Administrator' -m
cat /var/db/passwords/system_user_admin
Wir richten unserem admin noch die Shell und die zum zukünftigen Einloggen zwingend nötigten SSH-Keys ein.
su - admin
mkdir -p .ssh
chmod 700 .ssh
ssh-keygen -t ed25519 -O clear -O permit-pty -f ".ssh/id_ed25519" -N ""
cat .ssh/id_ed25519.pub >> .ssh/authorized_keys
ssh-keygen -t ecdsa -b 384 -O clear -O permit-pty -f ".ssh/id_ecdsa" -N ""
cat .ssh/id_ecdsa.pub >> .ssh/authorized_keys
ssh-keygen -t rsa -b 4096 -O clear -O permit-pty -f ".ssh/id_rsa" -N ""
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
exit
Einen normalen User mit SSH-Zugang legen wir ebenfalls an, ihn nennen wir "joeuser". Diesem User verpassen wir die Standard-Systemgruppe "users" und nehmen ihn zusätzlich in die Systemgruppe "sshusers" auf, damit sich dieser User später per SSH einloggen kann. Das Home-Verzeichnis des Users lassen wir automatisch anlegen und setzen seine Standard-Shell auf /bin/tcsh. Ein sicheres Passwort bekommt er selbstverständlich auch noch.
# Passwort erzeugen und speichern für den Systembenutzer "joeuser"
id -u joeuser >/dev/null 2>&1 || \
install -b -m 0600 /dev/null /var/db/passwords/system_user_joeuser
id -u joeuser >/dev/null 2>&1 || \
openssl rand -hex 64 | openssl passwd -5 -stdin | tr -cd '[[:print:]]' | \
cut -c 2-17 | tee /var/db/passwords/system_user_joeuser | \
pw useradd -h 0 -n joeuser -u 2000 -g users -G sshusers -c 'Joe User' -m
cat /var/db/passwords/system_user_joeuser
Wir richten unserem joeuser noch die Shell und die zum zukünftigen Einloggen zwingend nötigten SSH-Keys ein.
su - joeuser
mkdir -p .ssh
chmod 700 .ssh
ssh-keygen -t ed25519 -O clear -O permit-pty -f ".ssh/id_ed25519" -N ""
cat .ssh/id_ed25519.pub >> .ssh/authorized_keys
ssh-keygen -t ecdsa -b 384 -O clear -O permit-pty -f ".ssh/id_ecdsa" -N ""
cat .ssh/id_ecdsa.pub >> .ssh/authorized_keys
ssh-keygen -t rsa -b 4096 -O clear -O permit-pty -f ".ssh/id_rsa" -N ""
cat .ssh/id_rsa.pub >> .ssh/authorized_keys
exit
Cronjobs konfigurieren¶
Cronjobs zur regelmässigen Syncronisation mit einem Zeitserver einrichten.
cat <<'EOF' > /etc/crontab
# /etc/crontab - root's crontab for FreeBSD
#
#
SHELL=/bin/sh
PATH=/sbin:/bin:/usr/sbin:/usr/bin:/usr/local/sbin:/usr/local/bin
#
#minute hour mday month wday who command
#
# Save some entropy so that /dev/random can re-seed on boot.
*/11 * * * * operator /usr/libexec/save-entropy
#
# Rotate log files every hour, if necessary.
0 * * * * root newsyslog
#
# Perform daily/weekly/monthly maintenance.
1 3 * * * root periodic daily
15 4 * * 6 root periodic weekly
30 5 1 * * root periodic monthly
#
# Adjust the time zone if the CMOS clock keeps local time, as opposed to
# UTC time. See adjkerntz(8) for details.
1,31 0-5 * * * root adjkerntz -a
#
57 */4 * * * root /usr/sbin/sntp -S ptbtime1.ptb.de >/dev/null 2>&1
58 */4 * * * root /usr/sbin/sntp -S ptbtime2.ptb.de >/dev/null 2>&1
59 */4 * * * root /usr/sbin/sntp -S ptbtime3.ptb.de >/dev/null 2>&1
#
#10 7 * * * root /usr/local/bin/git -C /usr/ports pull --quiet && /usr/bin/make -C /usr/ports fetchindex && /usr/local/sbin/pkg version -vIL= && /usr/local/sbin/pkg audit -F
#10 7 * * * root /usr/local/sbin/pkg update -f && /usr/local/sbin/pkg audit -F # && /usr/local/sbin/pkg upgrade
#
EOF
Buildsystem konfigurieren¶
cat <<'EOF' > /etc/make.conf
KERNCONF?=GENERIC MYKERNEL
PRINTERDEVICE=ascii
LICENSES_ACCEPTED+=EULA DCC
DISABLE_VULNERABILITIES=yes
.if ${.CURDIR:M/usr/ports/*}
OPTIONS_SET=CRYPTO GSSAPI_NONE ICONV ICU IDN IDN2 IPV6 LIBEDIT MAN3 MANPAGES NLS OPENSSL PCRE2 PGSQL SSL STRIP THREADS
OPTIONS_UNSET=BLACKLISTD DEBUG DOCS DOXYGEN DTRACE EXAMPLES GNUTLS GSSAPI GSSAPI_BASE GSSAPI_HEIMDAL GSSAPI_MIT INFO LDAP MEM_DEBUG STATIC TEST TESTS TRACE X11
.endif
DEFAULT_VERSIONS+=ssl=openssl35
EOF
cat <<'EOF' > /etc/src.conf
WITHOUT_APM=YES
WITHOUT_BHYVE=YES
WITH_BIND_NOW=YES
WITHOUT_BLUETOOTH=YES
WITHOUT_BOOTPARAMD=YES
WITHOUT_BOOTPD=YES
WITHOUT_BSNMP=YES
WITHOUT_CALENDAR=YES
WITHOUT_CCD=YES
WITH_CLANG_EXTRAS=YES
WITH_CLANG_FORMAT=YES
WITHOUT_CROSS_COMPILER=YES
WITHOUT_CUSE=YES
WITHOUT_DEBUG_FILES=YES
WITH_DETECT_TZ_CHANGES=YES
WITHOUT_DOCCOMPRESS=YES
WITHOUT_FINGER=YES
WITHOUT_FLOPPY=YES
WITHOUT_FTP=YES
WITHOUT_GAMES=YES
WITHOUT_GPIO=YES
WITHOUT_HTML=YES
WITHOUT_HYPERV=YES
WITHOUT_INETD=YES
WITHOUT_KERBEROS=YES
WITH_KERNEL_RETPOLINE=YES
WITH_LLVM_BINUTILS=YES
WITHOUT_LLVM_TARGET_ALL=YES
WITH_LLVM_TARGET_AARCH64=YES
WITH_LLVM_TARGET_X86=YES
WITHOUT_LPR=YES
WITHOUT_MANCOMPRESS=YES
WITHOUT_NIS=YES
WITH_PIE=YES
WITHOUT_PMC=YES
WITHOUT_PPP=YES
WITHOUT_RADIUS_SUPPORT=YES
WITHOUT_RBOOTD=YES
WITH_REPRODUCIBLE_BUILD=YES
WITH_RETPOLINE=YES
WITHOUT_SENDMAIL=YES
WITHOUT_SHAREDOCS=YES
WITH_SORT_THREAD=YES
WITHOUT_TALK=YES
WITHOUT_TESTS=YES
WITHOUT_TFTP=YES
WITHOUT_WIRELESS=YES
WITH_ZONEINFO_LEAPSECONDS_SUPPORT=YES
EOF
/etc/sysctl.conf anpassen¶
In der sysctl.conf können die meisten Kernel-Parameter verändert werden. Wir wollen dies nutzen, um unser System etwas robuster und sicherer zu machen.
cat <<'EOF' > /etc/sysctl.conf
##############################################
# FreeBSD 15+ High-Performance & Secure sysctl.conf
# TCP/UDP, ZFS, Security, Kernel, ICMP, PF-ready
##############################################
####### NETWORK PERFORMANCE & TCP/UDP TUNING ##################################
# Max socket buffer (high throughput)
kern.ipc.maxsockbuf=16777216
# TCP buffer sizes
net.inet.tcp.recvspace=65536
net.inet.tcp.recvbuf_max=4194304
net.inet.tcp.sendspace=65536
net.inet.tcp.sendbuf_max=4194304
net.inet.tcp.sendbuf_inc=65536
# TCP MSS tuning (avoid PMTU issues)
net.inet.tcp.mssdflt=1240
net.inet.tcp.minmss=536
net.inet.tcp.abc_l_var=52
net.inet.tcp.initcwnd_segments=52
# TCP Congestion Control
net.inet.tcp.cc.abe=1
net.inet.tcp.rfc6675_pipe=1
# SYN cache & syncookies
net.inet.tcp.syncookies=0
net.inet.tcp.syncookies_only=1
net.inet.tcp.syncache.rexmtlimit=0
# TCP FIN/KEEP tuning
net.inet.tcp.fast_finwait2_recycle=1
net.inet.tcp.finwait2_timeout=1000
net.inet.tcp.keepcnt=2
net.inet.tcp.keepidle=62000
net.inet.tcp.keepinit=5000
net.inet.tcp.msl=2500
net.inet.tcp.path_mtu_discovery=0
net.inet.tcp.blackhole=2
net.inet.tcp.drop_synfin=1
net.inet.tcp.icmp_may_rst=0
net.inet.tcp.tso=0
net.inet.tcp.fastopen.client_enable=0
net.inet.tcp.fastopen.server_enable=0
net.inet.tcp.isn_reseed_interval=4500
# UDP tuning
net.inet.udp.recvspace=1048576
net.inet.udp.blackhole=1
# IP & IPv6 randomization / security
net.inet.ip.random_id=1
net.inet.ip.check_interface=1
net.inet.ip.redirect=0
net.inet6.ip6.redirect=0
net.inet.ip.maxfragpackets=0
net.inet.ip.maxfragsperpacket=0
net.inet6.ip6.maxfragpackets=0
net.inet6.ip6.maxfrags=0
# ICMP protection
net.inet.icmp.drop_redirect=1
net.inet6.icmp6.rediraccept=0
net.inet6.icmp6.nodeinfo=0
net.inet.icmp.icmplim=1
net.inet.icmp.icmplim_output=0
# Randomized ephemeral ports
net.inet.ip.portrange.first=32768
net.inet.ip.portrange.randomcps=9999
net.inet.ip.portrange.randomtime=1
# RAW sockets tuning
net.inet.raw.maxdgram=16384
net.inet.raw.recvspace=16384
net.local.stream.sendspace=16384
net.local.stream.recvspace=16384
# BPF performance
net.bpf.optimize_writers=1
####### KERNEL / PROCESS TUNING ###############################################
kern.maxfiles=65536
kern.maxprocperuid=65535
kern.threads.max_threads_per_proc=4096
kern.ps_arg_cache_limit=4096
kern.ipc.soacceptqueue=1024
kern.ipc.somaxconn=1024
# Random / entropy
kern.random.fortuna.minpoolsize=128
kern.random.harvest.mask=33119
kern.randompid=1
####### SECURITY HARDENING ####################################################
# ELF W^X protection
kern.elf32.allow_wx=0
kern.elf64.allow_wx=0
# Shared memory pinned
kern.ipc.shm_use_phys=1
# Kernel message buffer restrictions
kern.msgbuf_show_timestamp=1
security.bsd.unprivileged_read_msgbuf=0
# Restrict unprivileged debugging
security.bsd.unprivileged_proc_debug=0
# Stack smashing protection
security.bsd.stack_guard_page=1
# Hardlink & process visibility restrictions
security.bsd.hardlink_check_gid=1
security.bsd.hardlink_check_uid=1
security.bsd.see_other_gids=0
security.bsd.see_other_uids=0
security.bsd.see_jail_proc=0
# Keyboard keymap restrictions
hw.kbd.keymap_restrict_change=4
####### FILESYSTEM / ZFS TUNING ##############################################
vfs.zfs.delay_min_dirty_percent=98
vfs.zfs.dirty_data_sync_percent=95
vfs.zfs.min_auto_ashift=12
vfs.zfs.trim.txg_batch=128
vfs.zfs.txg.timeout=75
vfs.zfs.vdev.def_queue_depth=128
vfs.zfs.vdev.write_gap_limit=0
vfs.read_max=128
vfs.ufs.dirhash_maxmem=67108864
####### MISC ##################################################################
net.inet.ip.ttl=128
EOF
Kernel konfigurieren¶
Kernel Parameter in /boot/loader.conf setzen.
cat <<'EOF' > /boot/loader.conf
##############################
# ZFS / Filesystem
##############################
zfs_load="YES" # ZFS Support
vfs.zfs.prefetch_disable="0" # Prefetch aktivieren für Performance
vfs.zfs.arc_max="4294967296" # 4GB ARC Limit
vfs.zfs.vdev.max_pending="128" # max IO per vdev, matches sysctl
vfs.zfs.dirty_data_max_max="17179869184" # 16GB maximal dirty data
vfs.zfs.dirty_data_max_percent="25" # Commit TXG bei 25% dirty data
#vfs.root.mountfrom="zfs:zroot" # Root auf ZFS Pool
##############################
# Netzwerk / Performance
##############################
# NIC Rings
hw.igb.rx_ring="512"
hw.igb.tx_ring="512"
hw.vtnet.rx_ring="512"
hw.vtnet.tx_ring="512"
# Hardware Crypto
hw.crypto.aesni="1"
hw.crypto.armcrypt="1"
# TCP Offload
hw.tso_disable="1" # TSO deaktiviert
hw.lro_disable="1" # LRO deaktiviert
hw.rxcsum="1" # Receive Checksums
hw.txcsum="1" # Transmit Checksums
##############################
# Security Hardening
##############################
kern.elf32.allow_wx="0" # W^X 32-bit
kern.elf64.allow_wx="0" # W^X 64-bit
security.bsd.stack_guard_page="1" # Stack protection
kern.geom.label.disk_ident.enable="0" # Verhindert Disk ID leaks
kern.geom.label.gptid.enable="0"
kern.geom.label.gpt.enable="1"
hw.kbd.keymap_restrict_change="4" # Keyboard hardening
hw.random.fortuna.minpoolsize="256" # RNG min pool
security.bsd.allow_destructive_dtrace="0"
machdep.hyperthreading_allowed="0" # Optional Hyperthreading off
##############################
# Kernel / Process Limits
##############################
kern.maxproc="65536"
kern.maxusers="512"
kern.ipc.semmni="256"
kern.ipc.semmns="512"
kern.ipc.semmnu="256"
kern.ipc.shmmax="2147483648"
kern.msgbufsize="2097152"
##############################
# TCP/IP / PF Performance
##############################
net.inet.tcp.hostcache.enable="0"
net.inet.tcp.hostcache.cachelimit="0"
net.inet.tcp.soreceive_stream="1"
net.inet.tcp.syncache.hashsize="1024"
net.inet.tcp.syncache.bucketlimit="100"
net.inet.tcp.tcbhashsize="524288"
net.isr.bindthreads="1"
net.isr.maxthreads="-1"
net.isr.defaultqlimit="2048"
net.link.ifqmaxlen="2048"
pf_load="YES"
pflog_load="YES"
net.pf.source_nodes_hashsize="1048576"
##############################
# Optional Kernel Modules
##############################
amdtemp_load="YES"
coretemp_load="YES"
geom_mirror_load="YES"
accf_http_load="YES"
accf_data_load="YES"
accf_dns_load="YES"
##############################
# Boot / Misc
##############################
autoboot_delay="3"
boot_mute="YES"
boot_verbose="YES"
verbose_loading="YES"
loader_logo="orb"
debug.trace_on_panic="0"
kern.vty=vt
# Optional Microcode Update
#cpu_microcode_load="YES"
#cpu_microcode_name="/boot/firmware/intel-ucode.bin"
#cpu_microcode_name="/usr/local/share/cpucontrol/microcode_amd.bin"
EOF
Packet Filter (PF) einrichten¶
touch /etc/pf.badhosts_drop
touch /etc/pf.badhosts_torp
touch /etc/pf.badhosts_misc
touch /etc/pf.badhosts_scan
touch /etc/pf.badhosts_dns
touch /etc/pf.badhosts_ntpd
touch /etc/pf.badhosts_sshd
touch /etc/pf.badhosts_mail
touch /etc/pf.badhosts_http
touch /etc/pf.badhosts_priv
cat <<'EOF' > /etc/pf.conf
##### INTERFACES ##############################################################
ext_if = "__EXTERNAL__"
#int_if = "__INTERNAL__"
##### SERVICE GROUPS ##########################################################
DHCP_CLIENT = "{ 67, 68 }"
DHCP6_CLIENT = "{ 546, 547 }"
DNS_UDP = "{ 53 }"
DNS_TCP = "{ 53, 853 }"
NTPD_UDP = "{ 123 }"
HTTP_TCP = "{ 80, 443, 8080, 8443 }"
MAIL_TCP = "{ 25, 465, 587, 993 }"
SSHD_TCP = "{ 22, 2222 }"
TRACEROUTE_UDP = "33433 >< 33626"
FTP_TCP = "{ 20, 21 }"
SVN_TCP = "{ 3690 }"
GIT_TCP = "{ 9418 }"
OTHER_TCP = "{ 43, 989, 990 }"
##### RATE LIMITS #############################################################
MAX_SRC_CONN_RATE = "500/30"
DNS_RATE = "250/30"
NTPD_RATE = "250/30"
SSHD_RATE = "25/300"
MAIL_RATE = "120/30"
HTTP_RATE = "200/30"
##### TABLES ##################################################################
table <internal> persist counters file "/etc/pf.internal"
table <badhosts_drop> persist counters file "/etc/pf.badhosts_drop"
table <badhosts_torp> persist counters file "/etc/pf.badhosts_torp"
table <badhosts_misc> persist counters file "/etc/pf.badhosts_misc"
table <badhosts_scan> persist counters file "/etc/pf.badhosts_scan"
table <badhosts_dns> persist counters file "/etc/pf.badhosts_dns"
table <badhosts_ntpd> persist counters file "/etc/pf.badhosts_ntpd"
table <badhosts_sshd> persist counters file "/etc/pf.badhosts_sshd"
table <badhosts_mail> persist counters file "/etc/pf.badhosts_mail"
table <badhosts_http> persist counters file "/etc/pf.badhosts_http"
table <badhosts_priv> persist counters file "/etc/pf.badhosts_priv"
##### GLOBAL OPTIONS ##########################################################
set hostid 100
set block-policy drop
set loginterface $ext_if
set optimization normal
set ruleset-optimization basic
set state-policy if-bound
set timeout {
tcp.established 3600,
tcp.first 30, tcp.opening 30, tcp.closing 30,
udp.first 30, udp.single 30, udp.multiple 60
}
set limit { states 500000, src-nodes 200000, table-entries 5000000 }
##### NORMALIZATION ###########################################################
scrub in all random-id reassemble min-ttl 2 max-mss 1440
match out on $ext_if scrub (random-id)
antispoof quick for { $ext_if inet, $ext_if inet6 }
##### INTERNAL (LOOSE BUT CONTROLLED) #########################################
#pass in quick on $int_if from <internal> to any keep state
#pass out quick on $int_if from any to any keep state
##### DEFAULT POLICY ##########################################################
block in log on $ext_if all
block out on $ext_if all
##### BADHOST FAST DROP #######################################################
block in quick on $ext_if from {
<badhosts_drop>,
<badhosts_torp>,
<badhosts_misc>,
<badhosts_scan>,
<badhosts_dns>,
<badhosts_ntpd>,
<badhosts_sshd>,
<badhosts_mail>,
<badhosts_http>,
<badhosts_priv>
}
##### SCAN DETECTION ##########################################################
block in quick on $ext_if proto tcp \
flags FUP/FUP keep state \
(overload <badhosts_scan> flush global)
block in quick on $ext_if proto tcp \
flags /FSA keep state \
(overload <badhosts_scan> flush global)
##### ICMP / ICMPv6 ##########################################################
pass in quick on $ext_if proto { icmp, icmp6 } \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
pass out quick on $ext_if proto { icmp, icmp6 } \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
##### DHCP CLIENT #############################################################
pass in quick on $ext_if proto udp from port 67 to port 68 \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
pass out quick on $ext_if proto udp from port 68 to port 67 \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
pass in quick on $ext_if proto udp from port 547 to port 546 \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
pass out quick on $ext_if proto udp from port 546 to port 547 \
keep state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
##### DNS #####################################################################
pass in quick on $ext_if proto udp from any to any port $DNS_UDP \
keep state \
(max-src-conn-rate $DNS_RATE, overload <badhosts_dns> flush global)
pass in quick on $ext_if proto tcp from any to any port $DNS_TCP \
flags S/SA synproxy state \
(max-src-conn-rate $DNS_RATE, overload <badhosts_dns> flush global)
##### NTP ####################################################################
pass in quick on $ext_if proto udp from any to any port $NTPD_UDP \
keep state \
(max-src-conn-rate $NTPD_RATE, overload <badhosts_ntpd> flush global)
##### SSH ####################################################################
pass in on $ext_if proto tcp from any to any port $SSHD_TCP \
flags S/SA synproxy state \
(max-src-conn-rate $SSHD_RATE, overload <badhosts_sshd> flush global)
##### MAIL ###################################################################
pass in on $ext_if proto tcp from any to any port $MAIL_TCP \
flags S/SA synproxy state \
(max-src-conn-rate $MAIL_RATE, overload <badhosts_mail> flush global)
##### WEB ####################################################################
pass in on $ext_if proto tcp from any to any port $HTTP_TCP \
flags S/SA synproxy state \
(max-src-conn-rate $HTTP_RATE, overload <badhosts_http> flush global)
##### OUTBOUND ###############################################################
pass out quick on $ext_if proto udp from any to any port \
{ $DHCP_CLIENT, $DHCP6_CLIENT, $DNS_UDP, $NTPD_UDP, $TRACEROUTE_UDP } \
keep state
pass out quick on $ext_if proto tcp from any to any port \
{ $DNS_TCP, $SSHD_TCP, $MAIL_TCP, $HTTP_TCP, $FTP_TCP, $SVN_TCP, $GIT_TCP, $OTHER_TCP } \
modulate state \
(max-src-conn-rate $MAX_SRC_CONN_RATE, overload <badhosts_scan> flush global)
EOF
cat <<'EOF' > /etc/pf.internal
EOF
# 1. Get Default Interface
# Looks for the line starting with 'interface:' and captures the second column
DEF_IF="$(route -n get -inet default | awk '/interface:/ {print $2}')"
[ -n "$DEF_IF" ] && sed -e "s|__EXTERNAL__|$DEF_IF|g" -i '' /etc/pf.conf
# 2. Get IPv4 IP
# Captures the primary IPv4 address (excluding loopback)
IP4="$(ifconfig -u -f cidr "$DEF_IF" inet | awk '/inet / && $2 !~ /^127\./ {print $2}' | head -n 1)"
[ -n "$IP4" ] && sed -e "s|__IPADDR4__|$IP4|g" -i '' /etc/pf.internal
# 3. Get IPv6 IP
# Captures the primary Global IPv6 address
# Filters out link-local (fe80::) and loopback (::1) addresses
IP6="$(ifconfig -u -f cidr "$DEF_IF" inet6 | awk '/inet6 / && $2 !~ /^fe80:/ && $2 !~ /^::1/ {print $2}' | head -n 1)"
[ -n "$IP6" ] && sed -e "s|__IPADDR6__|$IP6|g" -i '' /etc/pf.internal
Abschluss der Installation¶
Um uns künftig mit unserem Arbeitsuser einloggen zu können, müssen wir uns dessen SSH-Key (id_ed25519) auf unser lokales System kopieren und ihn dann mit Hilfe der PuTTYgen Dokumentation in einen für PuTTY lesbaren Private Key umwandeln (id_ed25519.ppk).
pscp -P 2222 -r root@127.0.0.1:/mnt/home/admin/.ssh "${Env:USERPROFILE}\VirtualBox VMs\FreeBSD\ssh"
puttygen "${Env:USERPROFILE}\VirtualBox VMs\FreeBSD\ssh\id_ed25519"
Nun ist es endlich soweit: Wir verlassen das Chroot, unmounten die Partitionen und rebooten zum ersten Mal in unser neues FreeBSD Basis-System.
exit
rm /mnt/root/.sh_history*
rm /mnt/home/*/.sh_history*
umount /mnt/dev
umount /mnt
shutdown -r now
Einloggen und zu root werden¶
Einloggen ab hier nur noch mit Public-Key
putty -ssh -P 2222 -i "${Env:USERPROFILE}\VirtualBox VMs\FreeBSD\ssh\id_ed25519.ppk" admin@127.0.0.1
System aktualisieren¶
Nach dem Reboot aktualisieren und entschlacken wir das System.
ports-mgmt/pkg installieren¶
Wir installieren als Erstes pkg.
Git installieren¶
Wir installieren als Nächstes git und seine Abhängigkeiten.
Source Tree auschecken¶
Am Besten funktioniert bei FreeBSD immer noch die Aktualisierung über die System-Sourcen. Auf diesem Wege kann man ein System über viele Release-Generationen hinweg aktuell halten, ohne eine Neuinstallation durchzuführen. Das Verfahren ist zwar etwas zeitaufwändig, aber erprobt und führt bei richtiger Anwendung zu einem sauberen, aktuellen System.
Zunächst wird hierzu das aktuelle Quellenverzeichnis von FreeBSD benötigt, weshalb wir es mittels git auschecken.
# Neues Quellenverzeichnis anlegen (clone)
rm -r /usr/src
git clone -o freebsd -b releng/`/bin/freebsd-version -u | cut -d- -f1` https://git.FreeBSD.org/src.git /usr/src
git -C /usr/src pull --rebase
etcupdate extract
etcupdate diff
# Vorhandenes Quellenverzeichnis aktualisieren (pull)
git -C /usr/src pull --rebase
# Vorhandenes Quellenverzeichnis zu FreeBSD 15-STABLE wechseln (checkout)
git -C /usr/src checkout stable/15
etcupdate extract
etcupdate diff
Portstree auschecken¶
Um unser Basissystem später um sinnvolle Programme erweitern zu können, fehlt uns noch der sogenannte Portstree. Diesen checken wir nun ebenfalls mittels git aus (kann durchaus eine Stunde oder länger dauern).
rm -r /usr/ports
git clone --depth 1 https://git.FreeBSD.org/ports.git /usr/ports
git -C /usr/ports pull --rebase
make -C /usr/ports fetchindex
Damit ist der Portstree einsatzbereit. Um den Tree künftig zu aktualisieren genügt der folgende Befehl.
Wichtige Informationen zu neuen Paketversionen finden sich in /usr/ports/UPDATING und sollten dringend beachtet werden.
Git deinstallieren¶
Wir deinstallieren git und seine Abhängigkeiten nun vorerst wieder.
Konfiguration anpassen¶
In den Abschnitten Buildsystem konfigurieren und Kernel konfigurieren haben wir uns bereits eine geeignete make.conf und gegebenenfalls auch eine individuelle Kernel-Konfiguration erstellt. Dennoch sei an dieser Stelle nochmals auf das FreeBSD Handbuch verwiesen. Insbesondere Chapter 8. Configuring the FreeBSD Kernel und 24.6. Updating FreeBSD from Source seien Jedem FreeBSD Administratoren ans Herz gelegt.
Ausserdem empfiehlt es sich vor einem Update des Basissystems die Datei /usr/src/UPDATING zu lesen. Alle Angaben und Hinweise in dieser Datei sind aktueller und zutreffender als das Handbuch und sollten unbedingt befolgt werden.
Vorbereitende Arbeiten¶
Info
Für die spätere Installation des neu kompilierten Basissystems darf /tmp nicht mit der Option noexec gemounted sein. Da zwischendrin noch mal ein Reboot erfolgt, können wir bei Bedarf bereits jetzt die entsprechende Zeile in der fstab anpassen, sofern vorhanden.
Zunächst müssen eventuell vorhandene Object-Dateien im Verzeichnis /usr/obj gelöscht werden, damit make später wirklich das gesamte System neu erstellt.
Basissystem rekompilieren¶
Das Kompilieren des Basissystems kann durchaus eine Stunde oder länger dauern.
Kernel rekompilieren und installieren¶
Wenn die eigene Kernel-Konfiguration wie bei uns bereits in der /etc/make.conf eingetragen ist, wird sie automatisch verwendet, andernfalls wird die Konfiguration des generischen FreeBSD-Kernels verwendet. Das Kompilieren des Kernels kann durchaus eine Stunde oder länger dauern.
mkdir -p /root/kernels
cat <<'EOF' > /root/kernels/MYKERNEL
include GENERIC
ident MYKERNEL
EOF
ln -s /root/kernels/MYKERNEL /usr/src/sys/amd64/conf/
ln -s /root/kernels/MYKERNEL /usr/src/sys/arm64/conf/
make -j`sysctl -n hw.ncpu | awk '{print int / 4 * 3}'` KERNCONF=GENERIC INSTALLKERNEL=GENERIC INSTKERNNAME=GENERIC kernel
make -j`sysctl -n hw.ncpu | awk '{print int / 4 * 3}'` KERNCONF=MYKERNEL INSTALLKERNEL=MYKERNEL INSTKERNNAME=MYKERNEL kernel
sed -e 's/^#*\(kernels=\).*$/\1"MYKERNEL GENERIC"/' -i '' /boot/loader.conf
sed -e 's/^#*\(kernel=\).*$/\1"MYKERNEL"/' -i '' /boot/loader.conf
rm -r /boot/kernel /boot/kernel.old
Normalerweise wäre nun ein Reboot in den Single User Mode an der Reihe. Da sich ein Remote-System in diesem Modus ohne KVM-Lösung aber nicht bedienen lässt, begnügen wir uns damit, das System regulär neu zu starten.
Wenn wir unser System zu einem späteren Zeitpunkt nochmals aktualisieren, sollten wir zuden zuvor alle Dienste ausser OpenSSH, sowie sämtliche Jails in der Datei /etc/rc.conf deaktivieren.
Einloggen und zu root werden
putty -ssh -P 2222 -i "${Env:USERPROFILE}\VirtualBox VMs\FreeBSD\ssh\id_ed25519.ppk" admin@127.0.0.1
Basissystem installieren¶
Wir installieren das neue Basissystem.
Ausserdem sollte etcupdate im Pre-Build-Mode angeworfen werden, damit es während der Aktualisierung nicht zu Fehlern kommt, weil z. B. bestimmte User oder Gruppen noch nicht vorhanden sind.
Als letzten Schritt müssen nun noch die Neuerungen in den Konfigurationsdateien gemerged werden. Dabei unterstützt uns das Tool etcupdate. Wir müssen selbstverständlich darauf achten, dass wir hierbei nicht versehentlich unsere zuvor gemachten Anpassungen an den diversen Konfigurationsdateien wieder rückgängig machen.
Wir entsorgen nun noch eventuell vorhandene veraltete und überflüssige Dateien.
make BATCH_DELETE_OLD_FILES=yes delete-old-files
make BATCH_DELETE_OLD_FILES=yes delete-old-libs
make BATCH_DELETE_OLD_FILES=yes delete-old-dirs
make BATCH_DELETE_OLD_FILES=yes delete-old
Anschliessend müssen wir noch die für die Installation gegebenenfalls vorgenommenen Änderungen in der fstab sowie rc.conf rückgängig machen und das System nochmals durchstarten.
Viel Spass mit dem neuen FreeBSD BaseSystem.