forked from jaekwon-park/docker-sshd-ldap
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathentrypoint.sh
53 lines (42 loc) · 1.81 KB
/
entrypoint.sh
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
#!/bin/bash
echo -e "BASE ${LDAP_BASE}\nURI ${LDAP_SERVER}" > /etc/nslcd.conf
echo -e "binddn $ADMIN_DN\nbindpw $ADMIN_DN_PASS" >> /etc/nslcd.conf
for item in passwd shadow group; do
sed -i "s/^${item}:.*/${item}: ldap compat /g" /etc/nsswitch.conf
done
#sed -i "s/^Port 22/Port 2222/g" /etc/ssh/sshd_config
# clear motd
sed -i "s/^PrintLastLog yes/PrintLastLog no/g" /etc/ssh/sshd_config
sed -i "s/^PermitRootLogin without-password/PermitRootLogin no/g" /etc/ssh/sshd_config
sed -i "s/PasswordAuthentication yes/d" /etc/sshd_config
echo -e "\nForceCommand /usr/local/bin/record_ssh.sh" >> /etc/ssh/sshd_config
echo "" > /etc/motd
sed -i "s/ADMIN_DN /$ADMIN_DN/g" /etc/profile.d/userlist.sh
sed -i "s/ADMIN_DN_PASS/$ADMIN_DN_PASS/g" /etc/profile.d/userlist.sh
sed -i "s/LDAP_BASE/$LDAP_BASE/g" /etc/profile.d/userlist.sh
# ssh public key access config
if [[ $(grep -c "AuthorizedKeysCommand " /etc/ssh/sshd_config ) -eq 0 ]]; then
echo "AuthorizedKeysCommand /ldap_auth/ldap_auth.sh" >> /etc/ssh/sshd_config
fi
if [[ $(grep -c "AuthorizedKeysCommandUser " /etc/ssh/sshd_config ) -eq 0 ]]; then
echo "AuthorizedKeysCommandUser nobody" >> /etc/ssh/sshd_config
fi
if [[ $(grep -c "AuthorizedKeysFile /dev/null" /etc/ssh/sshd_config ) -eq 0 ]]; then
echo "AuthorizedKeysFile /dev/null" >> /etc/ssh/sshd_config
fi
if [[ $(grep -c "PasswordAuthentication no" /etc/ssh/sshd_config ) -eq 0 ]]; then
echo "PasswordAuthentication no" >> /etc/ssh/sshd_config
fi
echo "BASTION_SERVER_IP $BASTION_SERVER_IP" > /BASTION_SERVER
echo "BASTION_SERVER_PORT $BASTION_SERVER_PORT" >> /BASTION_SERVER
echo "BASTION_ID $BASTION_ID" >> /BASTION_SERVER
echo "REGION $REGION" >> /BASTION_SERVER
if /usr/sbin/nslcd ; then
echo "run nslcd"
fi
if /usr/sbin/rsyslogd; then
echo "run rsyslogd"
fi
if /usr/sbin/sshd -D ; then
echo "run sshd"
fi