3 # ssh-user-config, Copyright 2000, Red Hat Inc.
5 # This file is part of the Cygwin port of OpenSSH.
14 if [ "${auto_answer}" = "yes" ]
17 elif [ "${auto_answer}" = "no" ]
23 while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ]
25 echo -n "$1 (yes/no) "
28 if [ "X${answer}" = "Xyes" ]
69 echo "usage: ${progname} [OPTION]..."
71 echo "This script creates an OpenSSH user configuration."
74 echo " --debug -d Enable shell's debug output."
75 echo " --yes -y Answer all questions with \"yes\" automatically."
76 echo " --no -n Answer all questions with \"no\" automatically."
77 echo " --passphrase -p word Use \"word\" as passphrase automatically."
85 # Ask user if user identity should be generated
87 if [ ! -f /etc/passwd ]
89 echo '/etc/passwd is nonexistant. Please generate an /etc/passwd file'
90 echo 'first using mkpasswd. Check if it contains an entry for you and'
91 echo 'please care for the home directory in your entry as well.'
96 pwdhome=`awk -F: '{ if ( $3 == '${uid}' ) print $6; }' < /etc/passwd`
98 if [ "X${pwdhome}" = "X" ]
100 echo 'There is no home directory set for you in /etc/passwd.'
101 echo 'Setting $HOME is not sufficient!'
105 if [ ! -d "${pwdhome}" ]
107 echo "${pwdhome} is set in /etc/passwd as your home directory"
108 echo 'but it is not a valid directory. Cannot create user identity files.'
112 # If home is the root dir, set home to empty string to avoid error messages
113 # in subsequent parts of that script.
114 if [ "X${pwdhome}" = "X/" ]
116 # But first raise a warning!
117 echo 'Your home directory in /etc/passwd is set to root (/). This is not recommended!'
118 if request "Would you like to proceed anyway?"
126 if [ -e "${pwdhome}/.ssh" -a ! -d "${pwdhome}/.ssh" ]
128 echo "${pwdhome}/.ssh is existant but not a directory. Cannot create user identity files."
132 if [ ! -e "${pwdhome}/.ssh" ]
134 mkdir "${pwdhome}/.ssh"
135 if [ ! -e "${pwdhome}/.ssh" ]
137 echo "Creating users ${pwdhome}/.ssh directory failed"
142 if [ ! -f "${pwdhome}/.ssh/identity" ]
144 if request "Shall I create an SSH1 RSA identity file for you?"
146 echo "Generating ${pwdhome}/.ssh/identity"
147 if [ "${with_passphrase}" = "yes" ]
149 ssh-keygen -t rsa1 -N "${passphrase}" -f "${pwdhome}/.ssh/identity" > /dev/null
151 ssh-keygen -t rsa1 -f "${pwdhome}/.ssh/identity" > /dev/null
153 if request "Do you want to use this identity to login to this machine?"
155 echo "Adding to ${pwdhome}/.ssh/authorized_keys"
156 cat "${pwdhome}/.ssh/identity.pub" >> "${pwdhome}/.ssh/authorized_keys"
161 if [ ! -f "${pwdhome}/.ssh/id_rsa" ]
163 if request "Shall I create an SSH2 RSA identity file for you? (yes/no) "
165 echo "Generating ${pwdhome}/.ssh/id_rsa"
166 if [ "${with_passphrase}" = "yes" ]
168 ssh-keygen -t rsa -N "${passphrase}" -f "${pwdhome}/.ssh/id_rsa" > /dev/null
170 ssh-keygen -t rsa -f "${pwdhome}/.ssh/id_rsa" > /dev/null
172 if request "Do you want to use this identity to login to this machine?"
174 echo "Adding to ${pwdhome}/.ssh/authorized_keys2"
175 cat "${pwdhome}/.ssh/id_rsa.pub" >> "${pwdhome}/.ssh/authorized_keys2"
180 if [ ! -f "${pwdhome}/.ssh/id_dsa" ]
182 if request "Shall I create an SSH2 DSA identity file for you? (yes/no) "
184 echo "Generating ${pwdhome}/.ssh/id_dsa"
185 if [ "${with_passphrase}" = "yes" ]
187 ssh-keygen -t dsa -N "${passphrase}" -f "${pwdhome}/.ssh/id_dsa" > /dev/null
189 ssh-keygen -t dsa -f "${pwdhome}/.ssh/id_dsa" > /dev/null
191 if request "Do you want to use this identity to login to this machine?"
193 echo "Adding to ${pwdhome}/.ssh/authorized_keys2"
194 cat "${pwdhome}/.ssh/id_dsa.pub" >> "${pwdhome}/.ssh/authorized_keys2"
200 echo "Configuration finished. Have fun!"