6 . /usr/share/debconf/confmodule
11 if [ "$action" != configure ]
18 if [ ! -L /usr/share/doc/openssh-server ] && \
19 dpkg --compare-versions "$oldversion" lt-nl 1:4.1p1-5; then
20 rm -rf /usr/share/doc/openssh-server
21 ln -s openssh-client /usr/share/doc/openssh-server
29 [ -f /etc/ssh/sshd_config ] || return
31 # TODO: actually only one '=' allowed after option
32 perl -lne 's/\s+/ /g; print if s/^\s*'"$option"'[[:space:]=]+//i' \
42 $option = $ARGV[0]; $value = $ARGV[1]; $done = 0;
45 (my $match = $_) =~ s/\s+/ /g;
46 if ($match =~ s/^\s*\Q$option\E\s+.*/$option $value/) {
52 print "$option $value" unless $done;' \
54 < /etc/ssh/sshd_config > /etc/ssh/sshd_config.dpkg-new
55 chown --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
56 chmod --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
57 mv /etc/ssh/sshd_config.dpkg-new /etc/ssh/sshd_config
61 disable_config_option() {
64 value="$(get_config_option "$option")"
65 [ "$value" ] || return 0
71 (my $match = $_) =~ s/\s+/ /g;
72 # TODO: actually only one "=" allowed after option
73 if ($match =~ s/^(\s*\Q$option\E[[:space:]=]+.*)/#$1/i) {
79 < /etc/ssh/sshd_config > /etc/ssh/sshd_config.dpkg-new
80 chown --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
81 chmod --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
82 mv /etc/ssh/sshd_config.dpkg-new /etc/ssh/sshd_config
86 rename_config_option() {
90 value="$(get_config_option "$oldoption")"
91 [ "$value" ] || return 0
94 $oldoption = $ARGV[0]; $newoption = $ARGV[1];
97 (my $match = $_) =~ s/\s+/ /g;
98 # TODO: actually only one "=" allowed after option
99 if ($match =~ s/^(\s*)\Q$oldoption\E([[:space:]=]+)/$1$newoption$2/i) {
104 "$oldoption" "$newoption" \
105 < /etc/ssh/sshd_config > /etc/ssh/sshd_config.dpkg-new
106 chown --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
107 chmod --reference /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-new
108 mv /etc/ssh/sshd_config.dpkg-new /etc/ssh/sshd_config
112 remove_obsolete_gssapi() {
113 disable_config_option GSSAPINoMICAuthentication
114 disable_config_option GSSUseSessionCCache
115 disable_config_option GSSAPIUseSessionCredCache
119 host_keys_required() {
120 hostkeys="$(get_config_option HostKey)"
121 if [ "$hostkeys" ]; then
124 # No HostKey directives at all, so the server picks some
125 # defaults depending on the setting of Protocol.
126 protocol="$(get_config_option Protocol)"
127 [ "$protocol" ] || protocol=1,2
128 if echo "$protocol" | grep 1 >/dev/null; then
129 echo /etc/ssh/ssh_host_key
131 if echo "$protocol" | grep 2 >/dev/null; then
132 echo /etc/ssh/ssh_host_rsa_key
133 echo /etc/ssh/ssh_host_dsa_key
134 echo /etc/ssh/ssh_host_ecdsa_key
148 if echo "$hostkeys" | grep -x "$file" >/dev/null && \
149 [ ! -f "$file" ] ; then
151 ssh-keygen -q -f "$file" -N '' "$@"
153 if which restorecon >/dev/null 2>&1; then
154 restorecon "$file.pub"
161 hostkeys="$(host_keys_required)"
163 create_key "Creating SSH1 key; this may take some time ..." \
164 "$hostkeys" /etc/ssh/ssh_host_key -t rsa1
166 create_key "Creating SSH2 RSA key; this may take some time ..." \
167 "$hostkeys" /etc/ssh/ssh_host_rsa_key -t rsa
168 create_key "Creating SSH2 DSA key; this may take some time ..." \
169 "$hostkeys" /etc/ssh/ssh_host_dsa_key -t dsa
170 create_key "Creating SSH2 ECDSA key; this may take some time ..." \
171 "$hostkeys" /etc/ssh/ssh_host_ecdsa_key -t ecdsa
175 vulnerable_host_keys() {
176 # If the admin has explicitly put the vulnerable keys back, we
177 # assume they can look after themselves.
178 db_fget ssh/vulnerable_host_keys seen
179 if [ "$RET" = true ]; then
183 hostkeys="$(host_keys_required)"
185 for hostkey in $hostkeys; do
186 [ -f "$hostkey" ] || continue
187 if ssh-vulnkey -q "$hostkey"; then
188 vulnerable="${vulnerable:+$vulnerable }$hostkey"
191 if [ "$vulnerable" ]; then
192 db_subst ssh/vulnerable_host_keys HOST_KEYS "$vulnerable"
193 db_input critical ssh/vulnerable_host_keys || true
195 for hostkey in $vulnerable; do
196 mv "$hostkey" "$hostkey.broken" || true
197 mv "$hostkey.pub" "$hostkey.pub.broken" || true
204 check_password_auth() {
205 passwordauth="$(get_config_option PasswordAuthentication)"
206 crauth="$(get_config_option ChallengeResponseAuthentication)"
207 if [ "$passwordauth" = no ] && \
208 ([ -z "$crauth" ] || [ "$crauth" = yes ]); then
209 db_get ssh/disable_cr_auth
210 if [ "$RET" = true ]; then
211 set_config_option ChallengeResponseAuthentication no
217 move_subsystem_sftp() {
218 subsystem_sftp="$(get_config_option 'Subsystem sftp')"
219 if [ "$subsystem_sftp" = /usr/lib/sftp-server ] || \
220 [ "$subsystem_sftp" = /usr/libexec/sftp-server ]; then
221 set_config_option 'Subsystem sftp' /usr/lib/openssh/sftp-server
226 fix_loglevel_silent() {
227 if [ "$(get_config_option LogLevel)" = SILENT ]; then
228 set_config_option LogLevel QUIET
233 create_sshdconfig() {
234 if [ -e /etc/ssh/sshd_config ] ; then
235 # Upgrade an existing sshd configuration.
237 if (dpkg --compare-versions "$oldversion" lt-nl 1:3.8p1-1 && \
238 ! grep -iq ^UsePAM /etc/ssh/sshd_config) || \
239 grep -Eiq '^(PAMAuthenticationViaKbdInt|RhostsAuthentication)' \
240 /etc/ssh/sshd_config ; then
241 # Upgrade from pre-3.7: UsePAM needed to maintain standard
242 # Debian configuration.
243 # Note that --compare-versions is sadly not reliable enough
244 # here due to the package split of ssh into openssh-client
245 # and openssh-server. The extra grep for some deprecated
246 # options should with any luck be a good enough heuristic.
247 echo -n 'Upgrading sshd_config (old version in .dpkg-old) ...'
248 cp -a /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-old
249 perl -pe 's/^(PAMAuthenticationViaKbdInt|RhostsAuthentication)\b/#$1/i' \
250 /etc/ssh/sshd_config > /etc/ssh/sshd_config.dpkg-new
251 echo >> /etc/ssh/sshd_config.dpkg-new
252 echo 'UsePAM yes' >> /etc/ssh/sshd_config.dpkg-new
253 chown --reference /etc/ssh/sshd_config \
254 /etc/ssh/sshd_config.dpkg-new
255 chmod --reference /etc/ssh/sshd_config \
256 /etc/ssh/sshd_config.dpkg-new
257 mv /etc/ssh/sshd_config.dpkg-new /etc/ssh/sshd_config
261 # An empty version means we're upgrading from before the
262 # package split, so check.
263 if dpkg --compare-versions "$oldversion" lt 1:3.8.1p1-11; then
267 # libexecdir changed, so fix up 'Subsystem sftp'.
268 if dpkg --compare-versions "$oldversion" lt 1:4.1p1-1; then
272 # Remove obsolete GSSAPI options.
273 if dpkg --compare-versions "$oldversion" lt 1:4.3p2-8; then
274 remove_obsolete_gssapi
277 # This option was renamed in 3.8p1, but we never took care
278 # of adjusting the configuration file until now.
279 if dpkg --compare-versions "$oldversion" lt 1:4.7p1-8; then
280 rename_config_option KeepAlive TCPKeepAlive
283 # 'LogLevel SILENT' is now equivalent to QUIET.
284 if dpkg --compare-versions "$oldversion" lt 1:5.4p1-1; then
291 cat <<EOF > /etc/ssh/sshd_config
292 # Package generated configuration file
293 # See the sshd_config(5) manpage for details
295 # What ports, IPs and protocols we listen for
297 # Use these options to restrict which interfaces/protocols sshd will bind to
299 #ListenAddress 0.0.0.0
301 # HostKeys for protocol version 2
302 HostKey /etc/ssh/ssh_host_rsa_key
303 HostKey /etc/ssh/ssh_host_dsa_key
304 HostKey /etc/ssh/ssh_host_ecdsa_key
305 #Privilege Separation is turned on for security
306 UsePrivilegeSeparation yes
308 # Lifetime and size of ephemeral version 1 server key
309 KeyRegenerationInterval 3600
321 RSAAuthentication yes
322 PubkeyAuthentication yes
323 #AuthorizedKeysFile %h/.ssh/authorized_keys
325 # Don't read the user's ~/.rhosts and ~/.shosts files
327 # For this to work you will also need host keys in /etc/ssh_known_hosts
328 RhostsRSAAuthentication no
329 # similar for protocol version 2
330 HostbasedAuthentication no
331 # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
332 #IgnoreUserKnownHosts yes
334 # To enable empty passwords, change to yes (NOT RECOMMENDED)
335 PermitEmptyPasswords no
337 # Change to yes to enable challenge-response passwords (beware issues with
338 # some PAM modules and threads)
339 ChallengeResponseAuthentication no
341 # Change to no to disable tunnelled clear text passwords
342 #PasswordAuthentication yes
345 #KerberosAuthentication no
346 #KerberosGetAFSToken no
347 #KerberosOrLocalPasswd yes
348 #KerberosTicketCleanup yes
351 #GSSAPIAuthentication no
352 #GSSAPICleanupCredentials yes
361 #MaxStartups 10:30:60
362 #Banner /etc/issue.net
364 # Allow client to pass locale environment variables
367 Subsystem sftp /usr/lib/openssh/sftp-server
369 # Set this to 'yes' to enable PAM authentication, account processing,
370 # and session processing. If this is enabled, PAM authentication will
371 # be allowed through the ChallengeResponseAuthentication and
372 # PasswordAuthentication. Depending on your PAM configuration,
373 # PAM authentication via ChallengeResponseAuthentication may bypass
374 # the setting of "PermitRootLogin without-password".
375 # If you just want the PAM account and session checks to run without
376 # PAM authentication, then enable this but set PasswordAuthentication
377 # and ChallengeResponseAuthentication to 'no'.
383 # Remove an erronous override for sshd (we should have overridden ssh)
384 if [ -x /usr/sbin/dpkg-statoverride ]; then
385 if dpkg-statoverride --list /usr/sbin/sshd >/dev/null ; then
386 dpkg-statoverride --remove /usr/sbin/sshd
392 if getent passwd sshd | grep -q ':/bin/false$'; then
393 usermod -s /usr/sbin/nologin sshd || true
398 if ! getent passwd sshd >/dev/null; then
399 adduser --quiet --system --no-create-home --home /var/run/sshd --shell /usr/sbin/nologin sshd
403 fix_conffile_permissions() {
404 # Clean up after executable /etc/default/ssh in 1:3.5p1-5. dpkg
405 # doesn't do this for us; see bug #192981.
406 chmod 644 /etc/default/ssh
409 remove_old_init_links() {
410 # Yes, this only works with the SysV init script layout. I know.
411 # The important thing is that it doesn't actually *break* with
413 if [ -e /etc/rc2.d/S20ssh ]; then
414 update-rc.d -f ssh remove >/dev/null 2>&1
416 rm -f /etc/rc0.d/K??ssh /etc/rc1.d/K??ssh /etc/rc6.d/K??ssh
420 if [ -x /etc/init.d/ssh ]; then
421 update-rc.d ssh start 16 2 3 4 5 . >/dev/null
422 if [ -x /usr/sbin/invoke-rc.d ]; then
423 invoke-rc.d ssh restart
425 /etc/init.d/ssh restart
430 commit_transfer_conffile () {
432 if [ -e "$CONFFILE.moved-by-preinst" ]; then
433 rm -f "$CONFFILE.moved-by-preinst"
437 commit_mv_conffile () {
441 if [ -e "$OLDCONFFILE.moving" ]; then
442 echo "Preserving user changes to $NEWCONFFILE ..."
443 mv -f "$NEWCONFFILE" "$NEWCONFFILE.dpkg-new"
444 mv -f "$OLDCONFFILE.moving" "$NEWCONFFILE"
445 elif [ -e "$OLDCONFFILE.dpkg-old" ]; then
446 rm -f "$OLDCONFFILE.dpkg-old"
456 if dpkg --compare-versions "$2" lt 1:4.3p2-3; then
460 if dpkg --compare-versions "$2" lt 1:3.6.1p2-2; then
461 fix_conffile_permissions
463 if dpkg --compare-versions "$2" lt 1:5.2p1-1; then
464 remove_old_init_links
467 commit_transfer_conffile /etc/default/ssh
468 commit_transfer_conffile /etc/init.d/ssh
469 commit_transfer_conffile /etc/pam.d/ssh
470 commit_mv_conffile /etc/pam.d/ssh /etc/pam.d/sshd
471 # Renamed to /etc/ssh/moduli in 2.9.9 (!)
472 if dpkg --compare-versions "$2" lt 1:4.7p1-1; then
473 rm -f /etc/ssh/primes
475 if dpkg --compare-versions "$2" lt 1:5.5p1-6; then
476 rm -f /var/run/sshd/.placeholder