Merge pull request #280 from femtofox/new_working

Generate ttyd SSL encryption on first boot and whenever hostname changes
This commit is contained in:
noon92 2025-02-06 13:01:06 +02:00 • committed by GitHub
commit ea571110c9
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
4 changed files with 30 additions and 12 deletions

View file

@ -4,11 +4,11 @@ After=syslog.target
After=network.target
[Service]
ExecStart=/opt/ttyd/ttyd -W -6 login
ExecStart=/opt/ttyd/ttyd -W -6 --ssl --ssl-key /etc/ssl/private/ttyd.key --ssl-cert /etc/ssl/certs/ttyd.crt -i 0.0.0.0 login
Type=simple
Restart=always
User=root
Group=root
[Install]
WantedBy=multi-user.target
WantedBy=multi-user.target

View file

@ -150,6 +150,8 @@ $wifi_settings"
sed -i "s/$(hostname)/$OPTARG/g" /etc/hosts
hostnamectl set-hostname "$OPTARG"
systemctl restart avahi-daemon
echo "Regenerating web terminal ssl keys..."
femto-utils.sh -T
;;
\?) # Invalid option
echo "Invalid option: -$OPTARG"

View file

@ -63,14 +63,13 @@ else
log_message "Swap file already allocated, skipping"
fi
#generate keys
#generate SSH keys
log_message "Generating new SSH encryption keys. This can take a minute..."
sudo rm /etc/ssh/ssh_host_*
sudo ssh-keygen -q -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
sudo ssh-keygen -q -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
sudo chmod 600 /etc/ssh/ssh_host_*_key
sudo chmod 644 /etc/ssh/ssh_host_*_key.pub
sudo chown root:root /etc/ssh/ssh_host_*
femto-utils.sh -E
#generate ttyd SSL keys
log_message "Generating new Web Terminal SSL encryption keys. This can take a minute..."
femto-utils.sh -T
# prevent randomized mac address for eth0. If `eth0`` is already present in /etc/network/interfaces, skip
mac="$(awk '/Serial/ {print $3}' /proc/cpuinfo | tail -c 11 | sed 's/^\(.*\)/a2\1/' | sed 's/\(..\)/\1:/g;s/:$//')"

View file

@ -18,7 +18,9 @@ Options are:
-n Networking info
-o OS info
-S Storage & RAM info
-t "enable" Enable/disable/start/stop/check ttyd (http based terminal). Options: "enable" "disable" "start" "stop" "check"
-t "enable" Enable/disable/start/stop/check ttyd (web terminal). Options: "enable" "disable" "start" "stop" "check"
-T Generate/overwrite ttyd encryption keys
-E Generate/overwrite SSH encryption keys
EOF
)
@ -233,7 +235,7 @@ ttyd() {
fi
}
while getopts ":harsl:ipcnoSt:" opt; do
while getopts ":harsl:ipcnoSt:TE" opt; do
case ${opt} in
h) # Option -h (help)
echo -e $help
@ -258,7 +260,22 @@ while getopts ":harsl:ipcnoSt:" opt; do
n) networking_info ;; # Option -n (Networing info)
o) os_info ;; # Option -o (OS info)
S) storage_info ;; # Option -S (Storage & RAM info)
t) ttyd $OPTARG ;; # Option -t (ttyd)
t) ttyd $OPTARG ;; # Option -t (ttyd service manager)
T) # Option -T (new ttyd SSL keys)
openssl req -new -newkey rsa:4096 -days 3650 -nodes -x509 -keyout /etc/ssl/private/ttyd.key -out /etc/ssl/certs/ttyd.crt -subj "/CN=$(hostname)" -addext "subjectAltName=DNS:$(hostname)"
chmod 600 /etc/ssl/private/ttyd.key
chmod 644 /etc/ssl/certs/ttyd.crt
systemctl restart ttyd
;;
E) # Option -E (new SSH encryption keys)
rm /etc/ssh/ssh_host_*
ssh-keygen -t ed25519 -f /etc/ssh/ssh_host_ed25519_key -N ""
ssh-keygen -t rsa -b 4096 -f /etc/ssh/ssh_host_rsa_key -N ""
chmod 600 /etc/ssh/ssh_host_*_key
chmod 644 /etc/ssh/ssh_host_*_key.pub
chown root:root /etc/ssh/ssh_host_*
systemctl restart ssh
;;
\?) # Unknown option)
echo -e "Unknown argument $1.\n$help"
;;