forked from widdix/aws-ec2-ssh
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
8477494
commit d0f82f9
Showing
5 changed files
with
94 additions
and
132 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
#!/bin/bash -e | ||
|
||
# In order to support SELinux in Enforcing mode, we need to tell SELinux that it | ||
# should have the nis_enabled boolean turned on (so it should expect login services | ||
# like PAM and sshd to make calls to get public keys from a remote server) | ||
# | ||
# This is observed on CentOS 7 and RHEL 7 | ||
|
||
# Capture the return code and use that to determine if we have the command available | ||
retval=0 | ||
which getenforce > /dev/null 2>&1 || retval=$? | ||
|
||
if [[ "$retval" -eq "0" ]]; then | ||
retval=0 | ||
selinuxenabled || retval=$? | ||
if [[ "$retval" -eq "0" ]]; then | ||
setsebool -P nis_enabled on | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
#!/bin/bash -e | ||
|
||
if grep -q '#AuthorizedKeysCommand none' "$SSHD_CONFIG_FILE"; then | ||
sed -i "s:#AuthorizedKeysCommand none:AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE}:g" "$SSHD_CONFIG_FILE" | ||
else | ||
if ! grep -q "AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE}" "$SSHD_CONFIG_FILE"; then | ||
echo "AuthorizedKeysCommand ${AUTHORIZED_KEYS_COMMAND_FILE}" >> "$SSHD_CONFIG_FILE" | ||
fi | ||
fi | ||
|
||
if grep -q '#AuthorizedKeysCommandUser nobody' "$SSHD_CONFIG_FILE"; then | ||
sed -i "s:#AuthorizedKeysCommandUser nobody:AuthorizedKeysCommandUser nobody:g" "$SSHD_CONFIG_FILE" | ||
else | ||
if ! grep -q 'AuthorizedKeysCommandUser nobody' "$SSHD_CONFIG_FILE"; then | ||
echo "AuthorizedKeysCommandUser nobody" >> "$SSHD_CONFIG_FILE" | ||
fi | ||
fi |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
#!/bin/bash -e | ||
|
||
# Restart sshd using an appropriate method based on the currently running init daemon | ||
# Note that systemd can return "running" or "degraded" (If a systemd unit has failed) | ||
# This was observed on the RHEL 7.3 AMI, so it's added for completeness | ||
# systemd is also not standardized in the name of the ssh service, nor in the places | ||
# where the unit files are stored. | ||
|
||
# Capture the return code and use that to determine if we have the command available | ||
retval=0 | ||
which systemctl > /dev/null 2>&1 || retval=$? | ||
|
||
if [[ "$retval" -eq "0" ]]; then | ||
if [[ ($(systemctl is-system-running) =~ running) || ($(systemctl is-system-running) =~ degraded) || ($(systemctl is-system-running) =~ starting) ]]; then | ||
if [ -f "/usr/lib/systemd/system/sshd.service" ] || [ -f "/lib/systemd/system/sshd.service" ]; then | ||
systemctl restart sshd.service | ||
else | ||
systemctl restart ssh.service | ||
fi | ||
fi | ||
elif [[ $(/sbin/init --version) =~ upstart ]]; then | ||
if [ -f "/etc/init.d/sshd" ]; then | ||
service sshd restart | ||
else | ||
service ssh restart | ||
fi | ||
else | ||
if [ -f "/etc/init.d/sshd" ]; then | ||
/etc/init.d/sshd restart | ||
else | ||
/etc/init.d/ssh restart | ||
fi | ||
fi |