@@ -28,10 +28,10 @@ Install import_users.sh and authorized_key_commands.
28
28
EOF
29
29
}
30
30
31
- SSHD_CONFIG_FILE=" /etc/ssh/sshd_config"
32
- AUTHORIZED_KEYS_COMMAND_FILE=" /opt/authorized_keys_command.sh"
33
- IMPORT_USERS_SCRIPT_FILE=" /opt/import_users.sh"
34
- MAIN_CONFIG_FILE=" /etc/aws-ec2-ssh.conf"
31
+ export SSHD_CONFIG_FILE=" /etc/ssh/sshd_config"
32
+ export AUTHORIZED_KEYS_COMMAND_FILE=" /opt/authorized_keys_command.sh"
33
+ export IMPORT_USERS_SCRIPT_FILE=" /opt/import_users.sh"
34
+ export MAIN_CONFIG_FILE=" /etc/aws-ec2-ssh.conf"
35
35
36
36
IAM_GROUPS=" "
37
37
SUDO_GROUPS=" "
80
80
esac
81
81
done
82
82
83
+ export IAM_GROUPS
84
+ export SUDO_GROUPS
85
+ export LOCAL_GROUPS
86
+ export ASSUME_ROLE
87
+ export USERADD_PROGRAM
88
+ export USERADD_ARGS
89
+
90
+ # check if AWS CLI exists
91
+ if ! which aws; then
92
+ echo " aws executable not found - exiting!"
93
+ exit 1
94
+ fi
95
+
83
96
tmpdir=$( mktemp -d)
84
97
85
98
cd " $tmpdir "
@@ -121,21 +134,9 @@ then
121
134
echo " USERADD_ARGS=\" ${USERADD_ARGS} \" " >> $MAIN_CONFIG_FILE
122
135
fi
123
136
124
- if grep -q ' #AuthorizedKeysCommand none' $SSHD_CONFIG_FILE ; then
125
- sed -i " s:#AuthorizedKeysCommand none:AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE} :g" $SSHD_CONFIG_FILE
126
- else
127
- if ! grep -q " AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE} " $SSHD_CONFIG_FILE ; then
128
- echo " AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE} " >> $SSHD_CONFIG_FILE
129
- fi
130
- fi
137
+ ./install_configure_selinux.sh
131
138
132
- if grep -q ' #AuthorizedKeysCommandUser nobody' $SSHD_CONFIG_FILE ; then
133
- sed -i " s:#AuthorizedKeysCommandUser nobody:AuthorizedKeysCommandUser nobody:g" $SSHD_CONFIG_FILE
134
- else
135
- if ! grep -q ' AuthorizedKeysCommandUser nobody' $SSHD_CONFIG_FILE ; then
136
- echo " AuthorizedKeysCommandUser nobody" >> $SSHD_CONFIG_FILE
137
- fi
138
- fi
139
+ ./install_configure_sshd.sh
139
140
140
141
cat > /etc/cron.d/import_users << EOF
141
142
SHELL=/bin/bash
@@ -148,53 +149,4 @@ chmod 0644 /etc/cron.d/import_users
148
149
149
150
$IMPORT_USERS_SCRIPT_FILE
150
151
151
- # In order to support SELinux in Enforcing mode, we need to tell SELinux that it
152
- # should have the nis_enabled boolean turned on (so it should expect login services
153
- # like PAM and sshd to make calls to get public keys from a remote server)
154
- #
155
- # This is observed on CentOS 7 and RHEL 7
156
-
157
- # Capture the return code and use that to determine if we have the command available
158
- retval=0
159
- which getenforce > /dev/null 2>&1 || retval=$?
160
-
161
- if [[ " $retval " -eq " 0" ]]; then
162
- retval=0
163
- selinuxenabled || retval=$?
164
- if [[ " $retval " -eq " 0" ]]; then
165
- setsebool -P nis_enabled on
166
- fi
167
- fi
168
-
169
-
170
- # Restart sshd using an appropriate method based on the currently running init daemon
171
- # Note that systemd can return "running" or "degraded" (If a systemd unit has failed)
172
- # This was observed on the RHEL 7.3 AMI, so it's added for completeness
173
- # systemd is also not standardized in the name of the ssh service, nor in the places
174
- # where the unit files are stored.
175
-
176
- # Capture the return code and use that to determine if we have the command available
177
- retval=0
178
- which systemctl > /dev/null 2>&1 || retval=$?
179
-
180
- if [[ " $retval " -eq " 0" ]]; then
181
- if [[ (` systemctl is-system-running` =~ running) || (` systemctl is-system-running` =~ degraded) || (` systemctl is-system-running` =~ starting) ]]; then
182
- if [ -f " /usr/lib/systemd/system/sshd.service" ] || [ -f " /lib/systemd/system/sshd.service" ]; then
183
- systemctl restart sshd.service
184
- else
185
- systemctl restart ssh.service
186
- fi
187
- fi
188
- elif [[ ` /sbin/init --version` =~ upstart ]]; then
189
- if [ -f " /etc/init.d/sshd" ]; then
190
- service sshd restart
191
- else
192
- service ssh restart
193
- fi
194
- else
195
- if [ -f " /etc/init.d/sshd" ]; then
196
- /etc/init.d/sshd restart
197
- else
198
- /etc/init.d/ssh restart
199
- fi
200
- fi
152
+ ./install_restart_sshs.sh
0 commit comments