]> andersk Git - gssapi-openssh.git/blob - openssh/contrib/cygwin/ssh-user-config
The man2html from jbasney on pkilab2 works whereas the standard one doesn't.
[gssapi-openssh.git] / openssh / contrib / cygwin / ssh-user-config
1 #!/bin/sh
2 #
3 # ssh-user-config, Copyright 2000, Red Hat Inc.
4 #
5 # This file is part of the Cygwin port of OpenSSH.
6
7 progname=$0
8 auto_answer=""
9 auto_passphrase="no"
10 passphrase=""
11
12 request()
13 {
14   if [ "${auto_answer}" = "yes" ]
15   then
16     return 0
17   elif [ "${auto_answer}" = "no" ]
18   then
19     return 1
20   fi
21
22   answer=""
23   while [ "X${answer}" != "Xyes" -a "X${answer}" != "Xno" ]
24   do
25     echo -n "$1 (yes/no) "
26     read answer
27   done
28   if [ "X${answer}" = "Xyes" ]
29   then
30     return 0
31   else
32     return 1
33   fi
34 }
35
36 # Check options
37
38 while :
39 do
40   case $# in
41   0)
42     break
43     ;;
44   esac
45
46   option=$1
47   shift
48
49   case "$option" in
50   -d | --debug )
51     set -x
52     ;;
53
54   -y | --yes )
55     auto_answer=yes
56     ;;
57
58   -n | --no )
59     auto_answer=no
60     ;;
61
62   -p | --passphrase )
63     with_passphrase="yes"
64     passphrase=$1
65     shift
66     ;;
67
68   *)
69     echo "usage: ${progname} [OPTION]..."
70     echo
71     echo "This script creates an OpenSSH user configuration."
72     echo
73     echo "Options:"
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."
78     echo
79     exit 1
80     ;;
81
82   esac
83 done
84
85 # Ask user if user identity should be generated
86
87 if [ ! -f /etc/passwd ]
88 then
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.'
92   exit 1
93 fi
94
95 uid=`id -u`
96 pwdhome=`awk -F: '{ if ( $3 == '${uid}' ) print $6; }' < /etc/passwd`
97
98 if [ "X${pwdhome}" = "X" ]
99 then
100   echo 'There is no home directory set for you in /etc/passwd.'
101   echo 'Setting $HOME is not sufficient!'
102   exit 1
103 fi
104
105 if [ ! -d "${pwdhome}" ]
106 then
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.'
109   exit 1
110 fi
111
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/" ]
115 then
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?"
119   then
120     pwdhome=''
121   else
122     exit 1
123   fi
124 fi
125
126 if [ -e "${pwdhome}/.ssh" -a ! -d "${pwdhome}/.ssh" ]
127 then
128   echo "${pwdhome}/.ssh is existant but not a directory. Cannot create user identity files."
129   exit 1
130 fi
131
132 if [ ! -e "${pwdhome}/.ssh" ]
133 then
134   mkdir "${pwdhome}/.ssh"
135   if [ ! -e "${pwdhome}/.ssh" ]
136   then
137     echo "Creating users ${pwdhome}/.ssh directory failed"
138     exit 1
139   fi
140 fi
141
142 if [ ! -f "${pwdhome}/.ssh/identity" ]
143 then
144   if request "Shall I create an SSH1 RSA identity file for you?"
145   then
146     echo "Generating ${pwdhome}/.ssh/identity"
147     if [ "${with_passphrase}" = "yes" ]
148     then
149       ssh-keygen -t rsa1 -N "${passphrase}" -f "${pwdhome}/.ssh/identity" > /dev/null
150     else
151       ssh-keygen -t rsa1 -f "${pwdhome}/.ssh/identity" > /dev/null
152     fi
153     if request "Do you want to use this identity to login to this machine?"
154     then
155       echo "Adding to ${pwdhome}/.ssh/authorized_keys"
156       cat "${pwdhome}/.ssh/identity.pub" >> "${pwdhome}/.ssh/authorized_keys"
157     fi
158   fi
159 fi
160
161 if [ ! -f "${pwdhome}/.ssh/id_rsa" ]
162 then
163   if request "Shall I create an SSH2 RSA identity file for you? (yes/no) "
164   then
165     echo "Generating ${pwdhome}/.ssh/id_rsa"
166     if [ "${with_passphrase}" = "yes" ]
167     then
168       ssh-keygen -t rsa -N "${passphrase}" -f "${pwdhome}/.ssh/id_rsa" > /dev/null
169     else
170       ssh-keygen -t rsa -f "${pwdhome}/.ssh/id_rsa" > /dev/null
171     fi
172     if request "Do you want to use this identity to login to this machine?"
173     then
174       echo "Adding to ${pwdhome}/.ssh/authorized_keys2"
175       cat "${pwdhome}/.ssh/id_rsa.pub" >> "${pwdhome}/.ssh/authorized_keys2"
176     fi
177   fi
178 fi
179
180 if [ ! -f "${pwdhome}/.ssh/id_dsa" ]
181 then
182   if request "Shall I create an SSH2 DSA identity file for you? (yes/no) "
183   then
184     echo "Generating ${pwdhome}/.ssh/id_dsa"
185     if [ "${with_passphrase}" = "yes" ]
186     then
187       ssh-keygen -t dsa -N "${passphrase}" -f "${pwdhome}/.ssh/id_dsa" > /dev/null
188     else
189       ssh-keygen -t dsa -f "${pwdhome}/.ssh/id_dsa" > /dev/null
190     fi
191     if request "Do you want to use this identity to login to this machine?"
192     then
193       echo "Adding to ${pwdhome}/.ssh/authorized_keys2"
194       cat "${pwdhome}/.ssh/id_dsa.pub" >> "${pwdhome}/.ssh/authorized_keys2"
195     fi
196   fi
197 fi
198
199 echo
200 echo "Configuration finished. Have fun!"
This page took 0.043449 seconds and 5 git commands to generate.