Skip to content

Commit f1ec710

Browse files
saiarcot895judyjoseph
authored andcommitted
Remove SSH host keys after installing the custom version of sshd (#10633)
* Remove SSH host keys after installing the custom version of sshd Signed-off-by: Saikrishna Arcot <[email protected]> * Use an override for for sshd instead of overwriting the service file Don't overwrite upstream's .service file, and instead use an override file for making sure the host key(s) are generated. Signed-off-by: Saikrishna Arcot <[email protected]>
1 parent e2a2b30 commit f1ec710

File tree

4 files changed

+11
-19
lines changed

4 files changed

+11
-19
lines changed

build_debian.sh

+2-1
Original file line numberDiff line numberDiff line change
@@ -400,7 +400,8 @@ sudo sed -i 's/LOAD_KEXEC=true/LOAD_KEXEC=false/' $FILESYSTEM_ROOT/etc/default/k
400400
## Remove sshd host keys, and will regenerate on first sshd start
401401
sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key*
402402
sudo cp files/sshd/host-ssh-keygen.sh $FILESYSTEM_ROOT/usr/local/bin/
403-
sudo cp -f files/sshd/sshd.service $FILESYSTEM_ROOT/lib/systemd/system/ssh.service
403+
sudo mkdir $FILESYSTEM_ROOT/etc/systemd/system/ssh.service.d
404+
sudo cp files/sshd/override.conf $FILESYSTEM_ROOT/etc/systemd/system/ssh.service.d/override.conf
404405
# Config sshd
405406
# 1. Set 'UseDNS' to 'no'
406407
# 2. Configure sshd to close all SSH connetions after 15 minutes of inactivity

files/build_templates/sonic_debian_extension.j2

+5
Original file line numberDiff line numberDiff line change
@@ -329,6 +329,11 @@ sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/smartmontools_*.deb
329329
# Install custom-built openssh sshd
330330
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/openssh-server_*.deb
331331

332+
# Remove sshd host keys, and will regenerate on first sshd start. This needs to be
333+
# done again here because our custom version of sshd is being installed, which
334+
# will regenerate the sshd host keys.
335+
sudo rm -f $FILESYSTEM_ROOT/etc/ssh/ssh_host_*_key*
336+
332337
{% if sonic_asic_platform == 'broadcom' %}
333338
# Install custom-built flashrom
334339
sudo dpkg --root=$FILESYSTEM_ROOT -i $debs_path/flashrom_*.deb

files/sshd/override.conf

+4
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
[Service]
2+
ExecStartPre=
3+
ExecStartPre=/usr/local/bin/host-ssh-keygen.sh
4+
ExecStartPre=/usr/sbin/sshd -t

files/sshd/sshd.service

-18
This file was deleted.

0 commit comments

Comments
 (0)