#!/bin/sh # Create state dataset to persist SSH host keys across OS rebuilds. create_dataset -o "mountpoint=${ssh_host_key_dir}" "${state_dataset}/ssh" # If the state dataset contains existing host keys, symlink them into # /etc/ssh. # # If not, this is the first time we are building this box, so copy the # autogenerated host keys to the state partition. for key in \ ssh_host_ecdsa_key \ ssh_host_ed25519_key \ ssh_host_rsa_key do [ -f "${ssh_host_key_dir}/${key}" ] || \ mv -v "/etc/ssh/${key}" "/etc/ssh/${key}.pub" "$ssh_host_key_dir" ln -snvf "${ssh_host_key_dir}/${key}" "/etc/ssh/${key}" ln -snvf "${ssh_host_key_dir}/${key}.pub" "/etc/ssh/${key}.pub" done # Copy SSH configs. install_directory -m 0755 /etc/ssh/sshd_config.d install_template -m 0644 \ /etc/ssh/sshd_config \ /etc/ssh/ssh_config # Restart sshd. service sshd restart