]> andersk Git - openssh.git/blame - contrib/cygwin/ssh-user-config
- (dtucker) [contrib/cygwin/ssh-user-config] Put keys in authorized_keys
[openssh.git] / contrib / cygwin / ssh-user-config
CommitLineData
f4ebf0e8 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
7progname=$0
8auto_answer=""
9auto_passphrase="no"
10passphrase=""
11
12request()
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
38while :
39do
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
83done
84
85# Ask user if user identity should be generated
86
87if [ ! -f /etc/passwd ]
88then
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
93fi
94
95uid=`id -u`
96pwdhome=`awk -F: '{ if ( $3 == '${uid}' ) print $6; }' < /etc/passwd`
97
98if [ "X${pwdhome}" = "X" ]
99then
100 echo 'There is no home directory set for you in /etc/passwd.'
101 echo 'Setting $HOME is not sufficient!'
102 exit 1
103fi
104
105if [ ! -d "${pwdhome}" ]
106then
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
110fi
111
112# If home is the root dir, set home to empty string to avoid error messages
113# in subsequent parts of that script.
114if [ "X${pwdhome}" = "X/" ]
115then
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
124fi
125
126if [ -e "${pwdhome}/.ssh" -a ! -d "${pwdhome}/.ssh" ]
127then
128 echo "${pwdhome}/.ssh is existant but not a directory. Cannot create user identity files."
129 exit 1
130fi
131
132if [ ! -e "${pwdhome}/.ssh" ]
133then
134 mkdir "${pwdhome}/.ssh"
135 if [ ! -e "${pwdhome}/.ssh" ]
136 then
137 echo "Creating users ${pwdhome}/.ssh directory failed"
138 exit 1
139 fi
140fi
141
142if [ ! -f "${pwdhome}/.ssh/identity" ]
143then
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
159fi
160
161if [ ! -f "${pwdhome}/.ssh/id_rsa" ]
162then
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
fcd7f067 174 echo "Adding to ${pwdhome}/.ssh/authorized_keys"
175 cat "${pwdhome}/.ssh/id_rsa.pub" >> "${pwdhome}/.ssh/authorized_keys"
f4ebf0e8 176 fi
177 fi
178fi
179
180if [ ! -f "${pwdhome}/.ssh/id_dsa" ]
181then
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
fcd7f067 193 echo "Adding to ${pwdhome}/.ssh/authorized_keys"
194 cat "${pwdhome}/.ssh/id_dsa.pub" >> "${pwdhome}/.ssh/authorized_keys"
f4ebf0e8 195 fi
196 fi
197fi
198
199echo
200echo "Configuration finished. Have fun!"
This page took 0.159018 seconds and 5 git commands to generate.