3 # ssh-user-config, Copyright 2000-2008 Red Hat Inc.
5 # This file is part of the Cygwin port of OpenSSH.
7 # Permission to use, copy, modify, and distribute this software for any
8 # purpose with or without fee is hereby granted, provided that the above
9 # copyright notice and this permission notice appear in all copies.
11 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
12 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
13 # MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
14 # IN NO EVENT SHALL THE ABOVE COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
15 # DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR
16 # OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR
17 # THE USE OR OTHER DEALINGS IN THE SOFTWARE.
19 # ======================================================================
21 # ======================================================================
22 PROGNAME
=$
(basename -- $0)
23 _tdir
=$
(dirname -- $0)
24 PROGDIR
=$
(cd $_tdir && pwd)
26 CSIH_SCRIPT
=/usr
/share
/csih
/cygwin-service-installation-helper.sh
28 # Subdirectory where the new package is being installed
31 # Directory where the config files are stored
41 # ======================================================================
42 # Routine: create_ssh1_identity
43 # optionally create ~/.ssh/identity[.pub]
44 # optionally add result to ~/.ssh/authorized_keys
45 # ======================================================================
46 create_ssh1_identity
() {
47 if [ ! -f "${pwdhome}/.ssh/identity" ]
49 if csih_request
"Shall I create an SSH1 RSA identity file for you?"
51 csih_inform
"Generating ${pwdhome}/.ssh/identity"
52 if [ "${with_passphrase}" = "yes" ]
54 ssh-keygen
-t rsa1
-N "${passphrase}" -f "${pwdhome}/.ssh/identity" > /dev
/null
56 ssh-keygen
-t rsa1
-f "${pwdhome}/.ssh/identity" > /dev
/null
58 if csih_request
"Do you want to use this identity to login to this machine?"
60 csih_inform
"Adding to ${pwdhome}/.ssh/authorized_keys"
61 cat "${pwdhome}/.ssh/identity.pub" >> "${pwdhome}/.ssh/authorized_keys"
65 } # === End of create_ssh1_identity() === #
66 readonly -f create_ssh1_identity
68 # ======================================================================
69 # Routine: create_ssh2_rsa_identity
70 # optionally create ~/.ssh/id_rsa[.pub]
71 # optionally add result to ~/.ssh/authorized_keys
72 # ======================================================================
73 create_ssh2_rsa_identity
() {
74 if [ ! -f "${pwdhome}/.ssh/id_rsa" ]
76 if csih_request
"Shall I create an SSH2 RSA identity file for you?"
78 csih_inform
"Generating ${pwdhome}/.ssh/id_rsa"
79 if [ "${with_passphrase}" = "yes" ]
81 ssh-keygen
-t rsa
-N "${passphrase}" -f "${pwdhome}/.ssh/id_rsa" > /dev
/null
83 ssh-keygen
-t rsa
-f "${pwdhome}/.ssh/id_rsa" > /dev
/null
85 if csih_request
"Do you want to use this identity to login to this machine?"
87 csih_inform
"Adding to ${pwdhome}/.ssh/authorized_keys"
88 cat "${pwdhome}/.ssh/id_rsa.pub" >> "${pwdhome}/.ssh/authorized_keys"
92 } # === End of create_ssh2_rsa_identity() === #
93 readonly -f create_ssh2_rsa_identity
95 # ======================================================================
96 # Routine: create_ssh2_dsa_identity
97 # optionally create ~/.ssh/id_dsa[.pub]
98 # optionally add result to ~/.ssh/authorized_keys
99 # ======================================================================
100 create_ssh2_dsa_identity
() {
101 if [ ! -f "${pwdhome}/.ssh/id_dsa" ]
103 if csih_request
"Shall I create an SSH2 DSA identity file for you?"
105 csih_inform
"Generating ${pwdhome}/.ssh/id_dsa"
106 if [ "${with_passphrase}" = "yes" ]
108 ssh-keygen
-t dsa
-N "${passphrase}" -f "${pwdhome}/.ssh/id_dsa" > /dev
/null
110 ssh-keygen
-t dsa
-f "${pwdhome}/.ssh/id_dsa" > /dev
/null
112 if csih_request
"Do you want to use this identity to login to this machine?"
114 csih_inform
"Adding to ${pwdhome}/.ssh/authorized_keys"
115 cat "${pwdhome}/.ssh/id_dsa.pub" >> "${pwdhome}/.ssh/authorized_keys"
119 } # === End of create_ssh2_dsa_identity() === #
120 readonly -f create_ssh2_dsa_identity
122 # ======================================================================
123 # Routine: check_user_homedir
124 # Perform various checks on the user's home directory
125 # SETS GLOBAL VARIABLE:
127 # ======================================================================
128 check_user_homedir
() {
130 pwdhome
=$
(awk -F: '{ if ( $3 == '${uid}' ) print $6; }' < ${SYSCONFDIR}/passwd
)
131 if [ "X${pwdhome}" = "X" ]
134 "There is no home directory set for you in ${SYSCONFDIR}/passwd." \
135 'Setting $HOME is not sufficient!'
138 if [ ! -d "${pwdhome}" ]
141 "${pwdhome} is set in ${SYSCONFDIR}/passwd as your home directory" \
142 'but it is not a valid directory. Cannot create user identity files.'
145 # If home is the root dir, set home to empty string to avoid error messages
146 # in subsequent parts of that script.
147 if [ "X${pwdhome}" = "X/" ]
149 # But first raise a warning!
150 csih_warning
"Your home directory in ${SYSCONFDIR}/passwd is set to root (/). This is not recommended!"
151 if csih_request
"Would you like to proceed anyway?"
155 csih_warning
"Exiting. Configuration is not complete"
160 if [ -d "${pwdhome}" -a csih_is_nt
-a -n "`chmod -c g-w,o-w "${pwdhome}"`" ]
163 csih_warning
'group and other have been revoked write permission to your home'
164 csih_warning
"directory ${pwdhome}."
165 csih_warning
'This is required by OpenSSH to allow public key authentication using'
166 csih_warning
'the key files stored in your .ssh subdirectory.'
167 csih_warning
'Revert this change ONLY if you know what you are doing!'
170 } # === End of check_user_homedir() === #
171 readonly -f check_user_homedir
173 # ======================================================================
174 # Routine: check_user_dot_ssh_dir
175 # Perform various checks on the ~/.ssh directory
177 # pwdhome -- check_user_homedir()
178 # ======================================================================
179 check_user_dot_ssh_dir
() {
180 if [ -e "${pwdhome}/.ssh" -a ! -d "${pwdhome}/.ssh" ]
182 csih_error
"${pwdhome}/.ssh is existant but not a directory. Cannot create user identity files."
185 if [ ! -e "${pwdhome}/.ssh" ]
187 mkdir
"${pwdhome}/.ssh"
188 if [ ! -e "${pwdhome}/.ssh" ]
190 csih_error
"Creating users ${pwdhome}/.ssh directory failed"
193 } # === End of check_user_dot_ssh_dir() === #
194 readonly -f check_user_dot_ssh_dir
196 # ======================================================================
197 # Routine: fix_authorized_keys_perms
198 # Corrects the permissions of ~/.ssh/authorized_keys
200 # pwdhome -- check_user_homedir()
201 # ======================================================================
202 fix_authorized_keys_perms
() {
203 if [ csih_is_nt
-a -e "${pwdhome}/.ssh/authorized_keys" ]
205 if ! setfacl
-m "u::rw-,g::---,o::---" "${pwdhome}/.ssh/authorized_keys"
207 csih_warning
"Setting correct permissions to ${pwdhome}/.ssh/authorized_keys"
208 csih_warning
"failed. Please care for the correct permissions. The minimum requirement"
209 csih_warning
"is, the owner needs read permissions."
213 } # === End of fix_authorized_keys_perms() === #
214 readonly -f fix_authorized_keys_perms
217 # ======================================================================
219 # ======================================================================
221 # Check how the script has been started. If
222 # (1) it has been started by giving the full path and
223 # that path is /etc/postinstall, OR
224 # (2) Otherwise, if the environment variable
225 # SSH_USER_CONFIG_AUTO_ANSWER_NO is set
226 # then set auto_answer to "no". This allows automatic
227 # creation of the config files in /etc w/o overwriting
228 # them if they already exist. In both cases, color
229 # escape sequences are suppressed, so as to prevent
230 # cluttering setup's logfiles.
231 if [ "$PROGDIR" = "/etc/postinstall" ]
233 csih_auto_answer
="no"
236 if [ -n "${SSH_USER_CONFIG_AUTO_ANSWER_NO}" ]
238 csih_auto_answer
="no"
242 # ======================================================================
244 # ======================================================================
271 with_passphrase
="yes"
277 csih_FORCE_PRIVILEGED_USER
=yes
281 echo "usage: ${PROGNAME} [OPTION]..."
283 echo "This script creates an OpenSSH user configuration."
286 echo " --debug -d Enable shell's debug output."
287 echo " --yes -y Answer all questions with \"yes\" automatically."
288 echo " --no -n Answer all questions with \"no\" automatically."
289 echo " --passphrase -p word Use \"word\" as passphrase automatically."
290 echo " --privileged On Windows NT/2k/XP, assume privileged user"
291 echo " instead of LocalSystem for sshd service."
299 # ======================================================================
301 # ======================================================================
304 if [ ! -f ${SYSCONFDIR}/passwd
]
307 "${SYSCONFDIR}/passwd is nonexistant. Please generate an ${SYSCONFDIR}/passwd file" \
308 'first using mkpasswd. Check if it contains an entry for you and' \
309 'please care for the home directory in your entry as well.'
313 check_user_dot_ssh_dir
315 create_ssh2_rsa_identity
316 create_ssh2_dsa_identity
317 fix_authorized_keys_perms
320 csih_inform
"Configuration finished. Have fun!"