#!/bin/sh # # ssh-user-config, Copyright 2000, Red Hat Inc. # # This file is part of the Cygwin port of OpenSSH. progname=$0 auto_answer="" auto_passphrase="no" passphrase="" request() { if [ "${auto_answer}" = "yes" ] then return 0 elif [ "${auto_answer}" = "no" ] then return 1 fi answer="" while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ] do echo -n "$1 (yes/no) " read answer done if [ "X${answer}" = "Xyes" ] then return 0 else return 1 fi } # Check options while : do case $# in 0) break ;; esac option=$1 shift case "$option" in -d | --debug ) set -x ;; -y | --yes ) auto_answer=yes ;; -n | --no ) auto_answer=no ;; -p | --passphrase ) with_passphrase="yes" passphrase=$1 shift ;; *) echo "usage: ${progname} [OPTION]..." echo echo "This script creates an OpenSSH user configuration." echo echo "Options:" echo " --debug -d Enable shell's debug output." echo " --yes -y Answer all questions with \"yes\" automatically." echo " --no -n Answer all questions with \"no\" automatically." echo " --passphrase -p word Use \"word\" as passphrase automatically." echo exit 1 ;; esac done # Ask user if user identity should be generated if [ "X${HOME}" = "X" ] then echo '$HOME is nonexistant. Cannot create user identity files.' exit 1 fi if [ ! -d "${HOME}" ] then echo '$HOME is not a valid directory. Cannot create user identity files.' exit 1 fi # If HOME is the root dir, set HOME to empty string to avoid error messages # in subsequent parts of that script. if [ "X${HOME}" = "X/" ] then HOME='' fi if [ -e "${HOME}/.ssh" -a ! -d "${HOME}/.ssh" ] then echo '$HOME/.ssh is existant but not a directory. Cannot create user identity files.' exit 1 fi if [ ! -e "${HOME}/.ssh" ] then mkdir "${HOME}/.ssh" if [ ! -e "${HOME}/.ssh" ] then echo "Creating users ${HOME}/.ssh directory failed" exit 1 fi fi if [ ! -f "${HOME}/.ssh/identity" ] then if request "Shall I create an SSH1 RSA identity file for you?" then echo "Generating ${HOME}/.ssh/identity" if [ "${with_passphrase}" = "yes" ] then ssh-keygen -t rsa1 -N "${passphrase}" -f "${HOME}/.ssh/identity" > /dev/null else ssh-keygen -t rsa1 -f "${HOME}/.ssh/identity" > /dev/null fi if request "Do you want to use this identity to login to this machine?" then echo "Adding to ${HOME}/.ssh/authorized_keys" cat "${HOME}/.ssh/identity.pub" >> "${HOME}/.ssh/authorized_keys" fi fi fi if [ ! -f "${HOME}/.ssh/id_rsa" ] then if request "Shall I create an SSH2 RSA identity file for you? (yes/no) " then echo "Generating ${HOME}/.ssh/id_rsa" if [ "${with_passphrase}" = "yes" ] then ssh-keygen -t rsa -N "${passphrase}" -f "${HOME}/.ssh/id_rsa" > /dev/null else ssh-keygen -t rsa -f "${HOME}/.ssh/id_rsa" > /dev/null fi if request "Do you want to use this identity to login to this machine?" then echo "Adding to ${HOME}/.ssh/authorized_keys2" cat "${HOME}/.ssh/id_rsa.pub" >> "${HOME}/.ssh/authorized_keys2" fi fi fi if [ ! -f "${HOME}/.ssh/id_dsa" ] then if request "Shall I create an SSH2 DSA identity file for you? (yes/no) " then echo "Generating ${HOME}/.ssh/id_dsa" if [ "${with_passphrase}" = "yes" ] then ssh-keygen -t dsa -N "${passphrase}" -f "${HOME}/.ssh/id_dsa" > /dev/null else ssh-keygen -t dsa -f "${HOME}/.ssh/id_dsa" > /dev/null fi if request "Do you want to use this identity to login to this machine?" then echo "Adding to ${HOME}/.ssh/authorized_keys2" cat "${HOME}/.ssh/id_dsa.pub" >> "${HOME}/.ssh/authorized_keys2" fi fi fi echo echo 'Please care for setting your home directory in /etc/passwd as well.' echo 'Otherwise you will get problems running ssh!!!' echo echo "Configuration finished. Have fun!"