summaryrefslogtreecommitdiff
path: root/debian/postinst
diff options
context:
space:
mode:
Diffstat (limited to 'debian/postinst')
-rw-r--r--debian/postinst329
1 files changed, 329 insertions, 0 deletions
diff --git a/debian/postinst b/debian/postinst
new file mode 100644
index 000000000..af0f8a21c
--- /dev/null
+++ b/debian/postinst
@@ -0,0 +1,329 @@
1#!/bin/sh -e
2
3action="$1"
4oldversion="$2"
5
6. /usr/share/debconf/confmodule
7db_version 2.0
8
9umask 022
10
11if [ "$action" != configure ]
12 then
13 exit 0
14fi
15
16
17
18check_idea_key() {
19 #check for old host_key files using IDEA, which openssh does not support
20 if [ -f /etc/ssh/ssh_host_key ] ; then
21 if ssh-keygen -p -N '' -f /etc/ssh/ssh_host_key 2>&1 | \
22 grep -q 'unknown cipher' 2>/dev/null ; then
23 mv /etc/ssh/ssh_host_key /etc/ssh/ssh_host_key.old
24 mv /etc/ssh/ssh_host_key.pub /etc/ssh/ssh_host_key.pub.old
25 fi
26 fi
27}
28
29
30create_key() {
31 local msg="$1"
32 shift
33 local file="$1"
34 shift
35
36 if [ ! -f "$file" ] ; then
37 echo -n $msg
38 ssh-keygen -q -f "$file" -N '' "$@"
39 echo
40 fi
41}
42
43
44create_keys() {
45 db_get ssh/protocol2_only
46 if [ "$RET" = "false" ] ; then
47 create_key "Creating SSH1 key; this may take some time ..." \
48 /etc/ssh/ssh_host_key -t rsa1
49 fi
50
51 create_key "Creating SSH2 RSA key; this may take some time ..." \
52 /etc/ssh/ssh_host_rsa_key -t rsa
53 create_key "Creating SSH2 DSA key; this may take some time ..." \
54 /etc/ssh/ssh_host_dsa_key -t dsa
55}
56
57
58create_sshdconfig() {
59 if [ -e /etc/ssh/sshd_config ] ; then
60 if dpkg --compare-versions "$oldversion" lt-nl 1:1.3 ; then
61 db_get ssh/new_config
62 if [ "$RET" = "false" ] ; then return 0; fi
63 else return 0
64 fi
65 fi
66
67 #Preserve old sshd_config before generating a new one
68 if [ -e /etc/ssh/sshd_config ] ; then
69 mv /etc/ssh/sshd_config /etc/ssh/sshd_config.dpkg-old
70 fi
71
72 cat <<EOF > /etc/ssh/sshd_config
73# Package generated configuration file
74# See the sshd(8) manpage for details
75
76# What ports, IPs and protocols we listen for
77Port 22
78# Use these options to restrict which interfaces/protocols sshd will bind to
79#ListenAddress ::
80#ListenAddress 0.0.0.0
81EOF
82 db_get ssh/protocol2_only
83if [ "$RET" = "false" ]; then
84 cat <<EOF >> /etc/ssh/sshd_config
85Protocol 2,1
86# HostKeys for protocol version 1
87HostKey /etc/ssh/ssh_host_key
88# HostKeys for protocol version 2
89HostKey /etc/ssh/ssh_host_rsa_key
90HostKey /etc/ssh/ssh_host_dsa_key
91EOF
92else
93 cat <<EOF >> /etc/ssh/sshd_config
94Protocol 2
95# HostKeys for protocol version 2
96HostKey /etc/ssh/ssh_host_rsa_key
97HostKey /etc/ssh/ssh_host_dsa_key
98EOF
99fi
100
101db_get ssh/privsep_ask
102if [ "$RET" = "false" ]; then
103 cat <<EOF >> /etc/ssh/sshd_config
104#Explicitly set PrivSep off, as requested
105UsePrivilegeSeparation no
106
107# Use PAM authentication via keyboard-interactive so PAM modules can
108# properly interface with the user
109PAMAuthenticationViaKbdInt yes
110EOF
111else
112 cat <<EOF >> /etc/ssh/sshd_config
113#Privilege Separation is turned on for security
114UsePrivilegeSeparation yes
115
116# ...but breaks Pam auth via kbdint, so we have to turn it off
117# Use PAM authentication via keyboard-interactive so PAM modules can
118# properly interface with the user (off due to PrivSep)
119PAMAuthenticationViaKbdInt no
120EOF
121fi
122
123 cat <<EOF >> /etc/ssh/sshd_config
124# Lifetime and size of ephemeral version 1 server key
125KeyRegenerationInterval 3600
126ServerKeyBits 768
127
128# Logging
129SyslogFacility AUTH
130LogLevel INFO
131
132# Authentication:
133LoginGraceTime 600
134PermitRootLogin yes
135StrictModes yes
136
137RSAAuthentication yes
138PubkeyAuthentication yes
139#AuthorizedKeysFile %h/.ssh/authorized_keys
140
141# rhosts authentication should not be used
142RhostsAuthentication no
143# Don't read the user's ~/.rhosts and ~/.shosts files
144IgnoreRhosts yes
145# For this to work you will also need host keys in /etc/ssh_known_hosts
146RhostsRSAAuthentication no
147# similar for protocol version 2
148HostbasedAuthentication no
149# Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication
150#IgnoreUserKnownHosts yes
151
152# To enable empty passwords, change to yes (NOT RECOMMENDED)
153PermitEmptyPasswords no
154
155# Change to no to disable s/key passwords
156#ChallengeResponseAuthentication yes
157
158# To disable tunneled clear text passwords, change to no here!
159PasswordAuthentication yes
160
161
162# To change Kerberos options
163#KerberosAuthentication no
164#KerberosOrLocalPasswd yes
165#AFSTokenPassing no
166#KerberosTicketCleanup no
167
168# Kerberos TGT Passing does only work with the AFS kaserver
169#KerberosTgtPassing yes
170
171X11Forwarding no
172X11DisplayOffset 10
173PrintMotd no
174PrintLastLog yes
175KeepAlive yes
176#UseLogin no
177
178#MaxStartups 10:30:60
179#Banner /etc/issue.net
180#ReverseMappingCheck yes
181
182Subsystem sftp /usr/lib/sftp-server
183
184EOF
185}
186
187
188fix_rsh_diversion() {
189# get rid of mistaken rsh diversion (circa 1.2.27-1)
190
191 if [ -L /usr/bin/rsh ] &&
192 dpkg-divert --list '/usr/bin/rsh.real/rsh' | grep -q ' ssh$' ; then
193 for cmd in rlogin rsh rcp ; do
194 [ -L /usr/bin/$cmd ] && rm /usr/bin/$cmd
195 dpkg-divert --package ssh --remove --rename \
196 --divert /usr/bin/rsh.real/$cmd /usr/bin/$cmd
197
198 [ -L /usr/man/man1/$cmd.1.gz ] && rm /usr/man/man1/$$cmd.1.gz
199 dpkg-divert --package ssh --remove --rename \
200 --divert /usr/man/man1/$cmd.real.1.gz /usr/man/man1/$cmd.1.gz
201 done
202
203 rmdir /usr/bin/rsh.real
204 fi
205}
206
207
208fix_statoverride() {
209# Remove an erronous override for sshd (we should have overridden ssh)
210 if [ -x /usr/sbin/dpkg-statoverride ]; then
211 if dpkg-statoverride --list /usr/sbin/sshd >/dev/null ; then
212 dpkg-statoverride --remove /usr/sbin/sshd
213 fi
214 fi
215}
216
217
218create_alternatives() {
219# Create alternatives for the various r* tools.
220# Make sure we don't change existing alternatives that a user might have
221# changed, but clean up after some old alternatives that mistakenly pointed
222# rlogin and rcp to ssh.
223 update-alternatives --quiet --remove rlogin /usr/bin/ssh
224 update-alternatives --quiet --remove rcp /usr/bin/ssh
225 for cmd in rsh rlogin rcp; do
226 scmd="s${cmd#r}"
227 if ! update-alternatives --display "$cmd" | \
228 grep -q "$scmd"; then
229 update-alternatives --quiet --install "/usr/bin/$cmd" "$cmd" "/usr/bin/$scmd" 20 \
230 --slave "/usr/share/man/man1/$cmd.1.gz" "$cmd.1.gz" "/usr/share/man/man1/$scmd.1.gz"
231 fi
232 done
233}
234
235setup_sshd_user() {
236 if ! getent passwd sshd >/dev/null; then
237 adduser --quiet --system --no-create-home --home /var/run/sshd sshd
238 fi
239}
240
241set_sshd_permissions() {
242 if dpkg --compare-versions "$oldversion" lt-nl 1:3.4p1-1 ; then
243 if [ -x /usr/sbin/dpkg-statoverride ] ; then
244 if dpkg-statoverride --list /usr/bin/ssh >/dev/null; then
245 dpkg-statoverride --remove /usr/bin/ssh >/dev/null
246 fi
247 fi
248 fi
249
250 if [ ! -x /usr/sbin/dpkg-statoverride ] || \
251 ! dpkg-statoverride --list /usr/lib/ssh-keysign >/dev/null ; then
252 db_get ssh/SUID_client
253 if [ "$RET" = "false" ] ; then
254 chmod 0755 /usr/lib/ssh-keysign
255 elif [ "$RET" = "true" ] ; then
256 chmod 4755 /usr/lib/ssh-keysign
257 fi
258 fi
259}
260
261
262fix_ssh_group() {
263 # Try to remove non-system group mistakenly created by 1:3.5p1-1.
264 # set_ssh_agent_permissions() below will re-create it properly.
265 if getent group ssh >/dev/null; then
266 delgroup --quiet ssh || true
267 fi
268}
269
270
271set_ssh_agent_permissions() {
272 if ! getent group ssh >/dev/null; then
273 addgroup --system --quiet ssh
274 fi
275 if ! [ -x /usr/sbin/dpkg-statoverride ] || \
276 ! dpkg-statoverride --list /usr/bin/ssh-agent >/dev/null ; then
277 chgrp ssh /usr/bin/ssh-agent
278 chmod 2755 /usr/bin/ssh-agent
279 fi
280}
281
282
283fix_conffile_permissions() {
284 # Clean up after executable /etc/default/ssh in 1:3.5p1-5. dpkg
285 # doesn't do this for us; see bug #192981.
286 chmod 644 /etc/default/ssh
287}
288
289setup_startup() {
290 db_get ssh/run_sshd
291 if [ "$RET" = "false" ] ; then
292 /etc/init.d/ssh stop 2>&1 >/dev/null
293 touch /etc/ssh/sshd_not_to_be_run
294 else
295 rm -f /etc/ssh/sshd_not_to_be_run 2>/dev/null
296 fi
297}
298
299
300setup_init() {
301 if [ -e /etc/init.d/ssh ]; then
302 update-rc.d ssh defaults >/dev/null
303 /etc/init.d/ssh restart
304 fi
305}
306
307check_idea_key
308create_keys
309create_sshdconfig
310fix_rsh_diversion
311fix_statoverride
312create_alternatives
313setup_sshd_user
314set_sshd_permissions
315if [ "$2" = "1:3.5p1-1" ]; then
316 fix_ssh_group
317fi
318set_ssh_agent_permissions
319if dpkg --compare-versions "$2" lt 1:3.6.1p2-2; then
320 fix_conffile_permissions
321fi
322setup_startup
323setup_init
324
325
326db_stop
327
328exit 0
329