diff options
Diffstat (limited to 'other/ssharp/contrib/cygwin/ssh-host-config')
| -rw-r--r-- | other/ssharp/contrib/cygwin/ssh-host-config | 449 |
1 files changed, 449 insertions, 0 deletions
diff --git a/other/ssharp/contrib/cygwin/ssh-host-config b/other/ssharp/contrib/cygwin/ssh-host-config new file mode 100644 index 0000000..70bbafd --- /dev/null +++ b/other/ssharp/contrib/cygwin/ssh-host-config | |||
| @@ -0,0 +1,449 @@ | |||
| 1 | #!/bin/sh | ||
| 2 | # | ||
| 3 | # ssh-host-config, Copyright 2000, Red Hat Inc. | ||
| 4 | # | ||
| 5 | # This file is part of the Cygwin port of OpenSSH. | ||
| 6 | |||
| 7 | # Subdirectory where the new package is being installed | ||
| 8 | PREFIX=/usr | ||
| 9 | |||
| 10 | # Directory where the config files are stored | ||
| 11 | SYSCONFDIR=/etc | ||
| 12 | |||
| 13 | # Subdirectory where an old package might be installed | ||
| 14 | OLDPREFIX=/usr/local | ||
| 15 | OLDSYSCONFDIR=${OLDPREFIX}/etc | ||
| 16 | |||
| 17 | progname=$0 | ||
| 18 | auto_answer="" | ||
| 19 | port_number=22 | ||
| 20 | |||
| 21 | request() | ||
| 22 | { | ||
| 23 | if [ "${auto_answer}" = "yes" ] | ||
| 24 | then | ||
| 25 | return 0 | ||
| 26 | elif [ "${auto_answer}" = "no" ] | ||
| 27 | then | ||
| 28 | return 1 | ||
| 29 | fi | ||
| 30 | |||
| 31 | answer="" | ||
| 32 | while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ] | ||
| 33 | do | ||
| 34 | echo -n "$1 (yes/no) " | ||
| 35 | read answer | ||
| 36 | done | ||
| 37 | if [ "X${answer}" = "Xyes" ] | ||
| 38 | then | ||
| 39 | return 0 | ||
| 40 | else | ||
| 41 | return 1 | ||
| 42 | fi | ||
| 43 | } | ||
| 44 | |||
| 45 | # Check options | ||
| 46 | |||
| 47 | while : | ||
| 48 | do | ||
| 49 | case $# in | ||
| 50 | 0) | ||
| 51 | break | ||
| 52 | ;; | ||
| 53 | esac | ||
| 54 | |||
| 55 | option=$1 | ||
| 56 | shift | ||
| 57 | |||
| 58 | case "$option" in | ||
| 59 | -d | --debug ) | ||
| 60 | set -x | ||
| 61 | ;; | ||
| 62 | |||
| 63 | -y | --yes ) | ||
| 64 | auto_answer=yes | ||
| 65 | ;; | ||
| 66 | |||
| 67 | -n | --no ) | ||
| 68 | auto_answer=no | ||
| 69 | ;; | ||
| 70 | |||
| 71 | -p | --port ) | ||
| 72 | port_number=$1 | ||
| 73 | shift | ||
| 74 | ;; | ||
| 75 | |||
| 76 | *) | ||
| 77 | echo "usage: ${progname} [OPTION]..." | ||
| 78 | echo | ||
| 79 | echo "This script creates an OpenSSH host configuration." | ||
| 80 | echo | ||
| 81 | echo "Options:" | ||
| 82 | echo " --debug -d Enable shell's debug output." | ||
| 83 | echo " --yes -y Answer all questions with \"yes\" automatically." | ||
| 84 | echo " --no -n Answer all questions with \"no\" automatically." | ||
| 85 | echo " --port -p <n> sshd listens on port n." | ||
| 86 | echo | ||
| 87 | exit 1 | ||
| 88 | ;; | ||
| 89 | |||
| 90 | esac | ||
| 91 | done | ||
| 92 | |||
| 93 | # Check for running ssh/sshd processes first. Refuse to do anything while | ||
| 94 | # some ssh processes are still running | ||
| 95 | |||
| 96 | if ps -ef | grep -v grep | grep -q ssh | ||
| 97 | then | ||
| 98 | echo | ||
| 99 | echo "There are still ssh processes running. Please shut them down first." | ||
| 100 | echo | ||
| 101 | exit 1 | ||
| 102 | fi | ||
| 103 | |||
| 104 | # Check for ${SYSCONFDIR} directory | ||
| 105 | |||
| 106 | if [ -e "${SYSCONFDIR}" -a ! -d "${SYSCONFDIR}" ] | ||
| 107 | then | ||
| 108 | echo | ||
| 109 | echo "${SYSCONFDIR} is existant but not a directory." | ||
| 110 | echo "Cannot create global configuration files." | ||
| 111 | echo | ||
| 112 | exit 1 | ||
| 113 | fi | ||
| 114 | |||
| 115 | # Create it if necessary | ||
| 116 | |||
| 117 | if [ ! -e "${SYSCONFDIR}" ] | ||
| 118 | then | ||
| 119 | mkdir "${SYSCONFDIR}" | ||
| 120 | if [ ! -e "${SYSCONFDIR}" ] | ||
| 121 | then | ||
| 122 | echo | ||
| 123 | echo "Creating ${SYSCONFDIR} directory failed" | ||
| 124 | echo | ||
| 125 | exit 1 | ||
| 126 | fi | ||
| 127 | fi | ||
| 128 | |||
| 129 | # Check for an old installation in ${OLDPREFIX} unless ${OLDPREFIX} isn't | ||
| 130 | # the same as ${PREFIX} | ||
| 131 | |||
| 132 | old_install=0 | ||
| 133 | if [ "${OLDPREFIX}" != "${PREFIX}" ] | ||
| 134 | then | ||
| 135 | if [ -f "${OLDPREFIX}/sbin/sshd" ] | ||
| 136 | then | ||
| 137 | echo | ||
| 138 | echo "You seem to have an older installation in ${OLDPREFIX}." | ||
| 139 | echo | ||
| 140 | # Check if old global configuration files exist | ||
| 141 | if [ -f "${OLDSYSCONFDIR}/ssh_host_key" ] | ||
| 142 | then | ||
| 143 | if request "Do you want to copy your config files to your new installation?" | ||
| 144 | then | ||
| 145 | cp -f ${OLDSYSCONFDIR}/ssh_host_key ${SYSCONFDIR} | ||
| 146 | cp -f ${OLDSYSCONFDIR}/ssh_host_key.pub ${SYSCONFDIR} | ||
| 147 | cp -f ${OLDSYSCONFDIR}/ssh_host_dsa_key ${SYSCONFDIR} | ||
| 148 | cp -f ${OLDSYSCONFDIR}/ssh_host_dsa_key.pub ${SYSCONFDIR} | ||
| 149 | cp -f ${OLDSYSCONFDIR}/ssh_config ${SYSCONFDIR} | ||
| 150 | cp -f ${OLDSYSCONFDIR}/sshd_config ${SYSCONFDIR} | ||
| 151 | fi | ||
| 152 | fi | ||
| 153 | if request "Do you want to erase your old installation?" | ||
| 154 | then | ||
| 155 | rm -f ${OLDPREFIX}/bin/ssh.exe | ||
| 156 | rm -f ${OLDPREFIX}/bin/ssh-config | ||
| 157 | rm -f ${OLDPREFIX}/bin/scp.exe | ||
| 158 | rm -f ${OLDPREFIX}/bin/ssh-add.exe | ||
| 159 | rm -f ${OLDPREFIX}/bin/ssh-agent.exe | ||
| 160 | rm -f ${OLDPREFIX}/bin/ssh-keygen.exe | ||
| 161 | rm -f ${OLDPREFIX}/bin/slogin | ||
| 162 | rm -f ${OLDSYSCONFDIR}/ssh_host_key | ||
| 163 | rm -f ${OLDSYSCONFDIR}/ssh_host_key.pub | ||
| 164 | rm -f ${OLDSYSCONFDIR}/ssh_host_dsa_key | ||
| 165 | rm -f ${OLDSYSCONFDIR}/ssh_host_dsa_key.pub | ||
| 166 | rm -f ${OLDSYSCONFDIR}/ssh_config | ||
| 167 | rm -f ${OLDSYSCONFDIR}/sshd_config | ||
| 168 | rm -f ${OLDPREFIX}/man/man1/ssh.1 | ||
| 169 | rm -f ${OLDPREFIX}/man/man1/scp.1 | ||
| 170 | rm -f ${OLDPREFIX}/man/man1/ssh-add.1 | ||
| 171 | rm -f ${OLDPREFIX}/man/man1/ssh-agent.1 | ||
| 172 | rm -f ${OLDPREFIX}/man/man1/ssh-keygen.1 | ||
| 173 | rm -f ${OLDPREFIX}/man/man1/slogin.1 | ||
| 174 | rm -f ${OLDPREFIX}/man/man8/sshd.8 | ||
| 175 | rm -f ${OLDPREFIX}/sbin/sshd.exe | ||
| 176 | rm -f ${OLDPREFIX}/sbin/sftp-server.exe | ||
| 177 | fi | ||
| 178 | old_install=1 | ||
| 179 | fi | ||
| 180 | fi | ||
| 181 | |||
| 182 | # First generate host keys if not already existing | ||
| 183 | |||
| 184 | if [ ! -f "${SYSCONFDIR}/ssh_host_key" ] | ||
| 185 | then | ||
| 186 | echo "Generating ${SYSCONFDIR}/ssh_host_key" | ||
| 187 | ssh-keygen -t rsa1 -f ${SYSCONFDIR}/ssh_host_key -N '' > /dev/null | ||
| 188 | fi | ||
| 189 | |||
| 190 | if [ ! -f "${SYSCONFDIR}/ssh_host_rsa_key" ] | ||
| 191 | then | ||
| 192 | echo "Generating ${SYSCONFDIR}/ssh_host_rsa_key" | ||
| 193 | ssh-keygen -t rsa -f ${SYSCONFDIR}/ssh_host_rsa_key -N '' > /dev/null | ||
| 194 | fi | ||
| 195 | |||
| 196 | if [ ! -f "${SYSCONFDIR}/ssh_host_dsa_key" ] | ||
| 197 | then | ||
| 198 | echo "Generating ${SYSCONFDIR}/ssh_host_dsa_key" | ||
| 199 | ssh-keygen -t dsa -f ${SYSCONFDIR}/ssh_host_dsa_key -N '' > /dev/null | ||
| 200 | fi | ||
| 201 | |||
| 202 | # Check if ssh_config exists. If yes, ask for overwriting | ||
| 203 | |||
| 204 | if [ -f "${SYSCONFDIR}/ssh_config" ] | ||
| 205 | then | ||
| 206 | if request "Overwrite existing ${SYSCONFDIR}/ssh_config file?" | ||
| 207 | then | ||
| 208 | rm -f "${SYSCONFDIR}/ssh_config" | ||
| 209 | if [ -f "${SYSCONFDIR}/ssh_config" ] | ||
| 210 | then | ||
| 211 | echo "Can't overwrite. ${SYSCONFDIR}/ssh_config is write protected." | ||
| 212 | fi | ||
| 213 | fi | ||
| 214 | fi | ||
| 215 | |||
| 216 | # Create default ssh_config from here script | ||
| 217 | |||
| 218 | if [ ! -f "${SYSCONFDIR}/ssh_config" ] | ||
| 219 | then | ||
| 220 | echo "Generating ${SYSCONFDIR}/ssh_config file" | ||
| 221 | cat > ${SYSCONFDIR}/ssh_config << EOF | ||
| 222 | # This is ssh client systemwide configuration file. This file provides | ||
| 223 | # defaults for users, and the values can be changed in per-user configuration | ||
| 224 | # files or on the command line. | ||
| 225 | |||
| 226 | # Configuration data is parsed as follows: | ||
| 227 | # 1. command line options | ||
| 228 | # 2. user-specific file | ||
| 229 | # 3. system-wide file | ||
| 230 | # Any configuration value is only changed the first time it is set. | ||
| 231 | # Thus, host-specific definitions should be at the beginning of the | ||
| 232 | # configuration file, and defaults at the end. | ||
| 233 | |||
| 234 | # Site-wide defaults for various options | ||
| 235 | |||
| 236 | # Host * | ||
| 237 | # ForwardAgent yes | ||
| 238 | # ForwardX11 yes | ||
| 239 | # RhostsAuthentication yes | ||
| 240 | # RhostsRSAAuthentication yes | ||
| 241 | # RSAAuthentication yes | ||
| 242 | # PasswordAuthentication yes | ||
| 243 | # FallBackToRsh no | ||
| 244 | # UseRsh no | ||
| 245 | # BatchMode no | ||
| 246 | # CheckHostIP yes | ||
| 247 | # StrictHostKeyChecking no | ||
| 248 | # Port 22 | ||
| 249 | # Protocol 2,1 | ||
| 250 | # Cipher 3des | ||
| 251 | # EscapeChar ~ | ||
| 252 | |||
| 253 | # Be paranoid by default | ||
| 254 | Host * | ||
| 255 | ForwardAgent no | ||
| 256 | ForwardX11 no | ||
| 257 | FallBackToRsh no | ||
| 258 | |||
| 259 | # Try authentification with the following identities | ||
| 260 | IdentityFile ~/.ssh/identity | ||
| 261 | IdentityFile ~/.ssh/id_rsa | ||
| 262 | IdentityFile ~/.ssh/id_dsa | ||
| 263 | EOF | ||
| 264 | if [ "$port_number" != "22" ] | ||
| 265 | then | ||
| 266 | echo "Host localhost" >> ${SYSCONFDIR}/ssh_config | ||
| 267 | echo " Port $port_number" >> ${SYSCONFDIR}/ssh_config | ||
| 268 | fi | ||
| 269 | fi | ||
| 270 | |||
| 271 | # Check if sshd_config exists. If yes, ask for overwriting | ||
| 272 | |||
| 273 | if [ -f "${SYSCONFDIR}/sshd_config" ] | ||
| 274 | then | ||
| 275 | if request "Overwrite existing ${SYSCONFDIR}/sshd_config file?" | ||
| 276 | then | ||
| 277 | rm -f "${SYSCONFDIR}/sshd_config" | ||
| 278 | if [ -f "${SYSCONFDIR}/sshd_config" ] | ||
| 279 | then | ||
| 280 | echo "Can't overwrite. ${SYSCONFDIR}/sshd_config is write protected." | ||
| 281 | fi | ||
| 282 | fi | ||
| 283 | fi | ||
| 284 | |||
| 285 | # Create default sshd_config from here script | ||
| 286 | |||
| 287 | if [ ! -f "${SYSCONFDIR}/sshd_config" ] | ||
| 288 | then | ||
| 289 | echo "Generating ${SYSCONFDIR}/sshd_config file" | ||
| 290 | cat > ${SYSCONFDIR}/sshd_config << EOF | ||
| 291 | # This is ssh server systemwide configuration file. | ||
| 292 | |||
| 293 | Port $port_number | ||
| 294 | # | ||
| 295 | Protocol 2,1 | ||
| 296 | ListenAddress 0.0.0.0 | ||
| 297 | #ListenAddress :: | ||
| 298 | # | ||
| 299 | # Uncomment the following lines according to the used authentication | ||
| 300 | HostKey /etc/ssh_host_key | ||
| 301 | HostKey /etc/ssh_host_rsa_key | ||
| 302 | HostKey /etc/ssh_host_dsa_key | ||
| 303 | ServerKeyBits 768 | ||
| 304 | LoginGraceTime 600 | ||
| 305 | KeyRegenerationInterval 3600 | ||
| 306 | PermitRootLogin yes | ||
| 307 | # | ||
| 308 | # Don't read ~/.rhosts and ~/.shosts files | ||
| 309 | IgnoreRhosts yes | ||
| 310 | # Uncomment if you don't trust ~/.ssh/known_hosts for RhostsRSAAuthentication | ||
| 311 | #IgnoreUserKnownHosts yes | ||
| 312 | StrictModes yes | ||
| 313 | X11Forwarding no | ||
| 314 | X11DisplayOffset 10 | ||
| 315 | PrintMotd yes | ||
| 316 | KeepAlive yes | ||
| 317 | |||
| 318 | # Logging | ||
| 319 | SyslogFacility AUTH | ||
| 320 | LogLevel INFO | ||
| 321 | #obsoletes QuietMode and FascistLogging | ||
| 322 | |||
| 323 | RhostsAuthentication no | ||
| 324 | # | ||
| 325 | # For this to work you will also need host keys in /etc/ssh_known_hosts | ||
| 326 | RhostsRSAAuthentication no | ||
| 327 | |||
| 328 | # To install for logon to different user accounts change to "no" here | ||
| 329 | RSAAuthentication yes | ||
| 330 | |||
| 331 | # To install for logon to different user accounts change to "yes" here | ||
| 332 | PasswordAuthentication no | ||
| 333 | |||
| 334 | PermitEmptyPasswords no | ||
| 335 | |||
| 336 | CheckMail no | ||
| 337 | UseLogin no | ||
| 338 | |||
| 339 | #Uncomment if you want to enable sftp | ||
| 340 | #Subsystem sftp /usr/sbin/sftp-server | ||
| 341 | #MaxStartups 10:30:60 | ||
| 342 | EOF | ||
| 343 | fi | ||
| 344 | |||
| 345 | # Care for services file | ||
| 346 | _sys="`uname -a`" | ||
| 347 | _nt=`expr "$_sys" : "CYGWIN_NT"` | ||
| 348 | if [ $_nt -gt 0 ] | ||
| 349 | then | ||
| 350 | _wservices="${SYSTEMROOT}\\system32\\drivers\\etc\\services" | ||
| 351 | _wserv_tmp="${SYSTEMROOT}\\system32\\drivers\\etc\\srv.out.$$" | ||
| 352 | else | ||
| 353 | _wservices="${WINDIR}\\SERVICES" | ||
| 354 | _wserv_tmp="${WINDIR}\\SERV.$$" | ||
| 355 | fi | ||
| 356 | _services=`cygpath -u "${_wservices}"` | ||
| 357 | _serv_tmp=`cygpath -u "${_wserv_tmp}"` | ||
| 358 | |||
| 359 | mount -t -f "${_wservices}" "${_services}" | ||
| 360 | mount -t -f "${_wserv_tmp}" "${_serv_tmp}" | ||
| 361 | |||
| 362 | # Remove sshd 22/port from services | ||
| 363 | if [ `grep -q 'sshd[ \t][ \t]*22' "${_services}"; echo $?` -eq 0 ] | ||
| 364 | then | ||
| 365 | grep -v 'sshd[ \t][ \t]*22' "${_services}" > "${_serv_tmp}" | ||
| 366 | if [ -f "${_serv_tmp}" ] | ||
| 367 | then | ||
| 368 | if mv "${_serv_tmp}" "${_services}" | ||
| 369 | then | ||
| 370 | echo "Removing sshd from ${_services}" | ||
| 371 | else | ||
| 372 | echo "Removing sshd from ${_services} failed\!" | ||
| 373 | fi | ||
| 374 | rm -f "${_serv_tmp}" | ||
| 375 | else | ||
| 376 | echo "Removing sshd from ${_services} failed\!" | ||
| 377 | fi | ||
| 378 | fi | ||
| 379 | |||
| 380 | # Add ssh 22/tcp and ssh 22/udp to services | ||
| 381 | if [ `grep -q 'ssh[ \t][ \t]*22' "${_services}"; echo $?` -ne 0 ] | ||
| 382 | then | ||
| 383 | awk '{ if ( $2 ~ /^23\/tcp/ ) print "ssh 22/tcp #SSH Remote Login Protocol\nssh 22/udp #SSH Remote Login Protocol"; print $0; }' < "${_services}" > "${_serv_tmp}" | ||
| 384 | if [ -f "${_serv_tmp}" ] | ||
| 385 | then | ||
| 386 | if mv "${_serv_tmp}" "${_services}" | ||
| 387 | then | ||
| 388 | echo "Added ssh to ${_services}" | ||
| 389 | else | ||
| 390 | echo "Adding ssh to ${_services} failed\!" | ||
| 391 | fi | ||
| 392 | rm -f "${_serv_tmp}" | ||
| 393 | else | ||
| 394 | echo "Adding ssh to ${_services} failed\!" | ||
| 395 | fi | ||
| 396 | fi | ||
| 397 | |||
| 398 | umount "${_services}" | ||
| 399 | umount "${_serv_tmp}" | ||
| 400 | |||
| 401 | # Care for inetd.conf file | ||
| 402 | _inetcnf="/etc/inetd.conf" | ||
| 403 | _inetcnf_tmp="/etc/inetd.conf.$$" | ||
| 404 | |||
| 405 | if [ -f "${_inetcnf}" ] | ||
| 406 | then | ||
| 407 | # Check if ssh service is already in use as sshd | ||
| 408 | with_comment=1 | ||
| 409 | grep -q '^[ \t]*sshd' "${_inetcnf}" && with_comment=0 | ||
| 410 | # Remove sshd line from inetd.conf | ||
| 411 | if [ `grep -q '^[# \t]*sshd' "${_inetcnf}"; echo $?` -eq 0 ] | ||
| 412 | then | ||
| 413 | grep -v '^[# \t]*sshd' "${_inetcnf}" >> "${_inetcnf_tmp}" | ||
| 414 | if [ -f "${_inetcnf_tmp}" ] | ||
| 415 | then | ||
| 416 | if mv "${_inetcnf_tmp}" "${_inetcnf}" | ||
| 417 | then | ||
| 418 | echo "Removed sshd from ${_inetcnf}" | ||
| 419 | else | ||
| 420 | echo "Removing sshd from ${_inetcnf} failed\!" | ||
| 421 | fi | ||
| 422 | rm -f "${_inetcnf_tmp}" | ||
| 423 | else | ||
| 424 | echo "Removing sshd from ${_inetcnf} failed\!" | ||
| 425 | fi | ||
| 426 | fi | ||
| 427 | |||
| 428 | # Add ssh line to inetd.conf | ||
| 429 | if [ `grep -q '^[# \t]*ssh' "${_inetcnf}"; echo $?` -ne 0 ] | ||
| 430 | then | ||
| 431 | if [ "${with_comment}" -eq 0 ] | ||
| 432 | then | ||
| 433 | echo 'ssh stream tcp nowait root /usr/sbin/sshd -i' >> "${_inetcnf}" | ||
| 434 | else | ||
| 435 | echo '# ssh stream tcp nowait root /usr/sbin/sshd -i' >> "${_inetcnf}" | ||
| 436 | fi | ||
| 437 | echo "Added ssh to ${_inetcnf}" | ||
| 438 | fi | ||
| 439 | fi | ||
| 440 | |||
| 441 | if [ "${old_install}" = "1" ] | ||
| 442 | then | ||
| 443 | echo | ||
| 444 | echo "Note: If you have used sshd as service or from inetd, don't forget to" | ||
| 445 | echo " change the path to sshd.exe in the service entry or in inetd.conf." | ||
| 446 | fi | ||
| 447 | |||
| 448 | echo | ||
| 449 | echo "Host configuration finished. Have fun!" | ||
