Skip to content

Commit

Permalink
Make servers secure
Browse files Browse the repository at this point in the history
  • Loading branch information
piroor committed Apr 10, 2015
1 parent 85610da commit 80e9986
Show file tree
Hide file tree
Showing 3 changed files with 0 additions and 89 deletions.
34 changes: 0 additions & 34 deletions scripts/reset.sh

This file was deleted.

24 changes: 0 additions & 24 deletions scripts/setup-front.sh
Expand Up @@ -3,8 +3,6 @@
# # curl https://raw.githubusercontent.com/piroor/system-admin-girl-handson/master/scripts/setup-front.sh | bash

STATIC_IP_ADDRESS=192.168.0.100
ACCEPT_PORT_FROM=20000
ACCEPT_PORT_TO=29999


echo 'Setting up this computer as the "front"...'
Expand Down Expand Up @@ -59,30 +57,9 @@ echo 'Restarting interfaces...'
service network restart


echo "Allowing accesses for all ports $ACCEPT_PORT_FROM to $ACCEPT_PORT_TO..."
# iptablesの設定を追加して、ポートを開放する。
# リモートフォワードで他のコンピュータからの接続を受け付けるためには、
# ポートが開放されている必要がある。

IPTABLES_CONFIG=/etc/sysconfig/iptables
IPTABLES_CONFIG_BACKUP=~/iptables.bak.$(date +%Y-%m-%d_%H-%M-%S)
IPTABLES_ACCEPT_LINE="-A INPUT -m state --state NEW -m tcp -p tcp --dport $ACCEPT_PORT_FROM:$ACCEPT_PORT_TO -j ACCEPT"

mv $IPTABLES_CONFIG $IPTABLES_CONFIG_BACKUP
cat $IPTABLES_CONFIG_BACKUP | \
sed -r -e "s/$IPTABLES_ACCEPT_LINE//" \
-e "/.+--dport 22 .+$/a $IPTABLES_ACCEPT_LINE" \
> $IPTABLES_CONFIG

service iptables restart


echo 'Configuring sshd...'
# SSH経由での直接のrootログインを禁止する。
# パスワード認証を許可する。(話を簡単にするため)
# リモートフォワードでループバック以外のアドレスでもバインドを許可する。
# See also: http://qiita.com/FGtatsuro/items/e2767fa041c96a2bae1f
# http://blog.cles.jp/item/5699

SSHD_CONFIG=/etc/ssh/sshd_config
SSHD_CONFIG_BACKUP=~/sshd_config.bak.$(date +%Y-%m-%d_%H-%M-%S)
Expand All @@ -92,7 +69,6 @@ cat $SSHD_CONFIG_BACKUP | \
sed -r -e 's/^# *PermitRootLogin +yes/PermitRootLogin no/' \
-e 's/^( *PasswordAuthentication +no)/#\1/' \
-e 's/^#( *PasswordAuthentication +yes)/\1/' \
-e 's/^#? *GatewayPorts +no/GatewayPorts clientspecified/' \
> $SSHD_CONFIG

service sshd restart
Expand Down
31 changes: 0 additions & 31 deletions scripts/setup-relay.sh
Expand Up @@ -2,19 +2,10 @@
# Run as root, like:
# # curl https://raw.githubusercontent.com/piroor/system-admin-girl-handson/master/scripts/setup-relay.sh | bash

ACCEPT_PORT_FROM=20000
ACCEPT_PORT_TO=29999


echo 'Setting up this computer as the "relay"...'


echo 'Downloading scripts to configure connections...'

curl -O https://raw.githubusercontent.com/piroor/system-admin-girl-handson/master/scripts/reset.sh
chmod +x ~/reset.sh


echo 'Creating a new user "user"...'

# rootでログインせずに済むように、作業用のユーザーを作成する。
Expand All @@ -33,30 +24,9 @@ chown -R user:user ~user/.ssh
chmod 600 ~user/.ssh/authorized_keys


echo "Allowing accesses for all ports $ACCEPT_PORT_FROM to $ACCEPT_PORT_TO..."
# iptablesの設定を追加して、ポートを開放する。
# リモートフォワードで他のコンピュータからの接続を受け付けるためには、
# ポートが開放されている必要がある。

IPTABLES_CONFIG=/etc/sysconfig/iptables
IPTABLES_CONFIG_BACKUP=~/iptables.bak.$(date +%Y-%m-%d_%H-%M-%S)
IPTABLES_ACCEPT_LINE="-A INPUT -m state --state NEW -m tcp -p tcp --dport $ACCEPT_PORT_FROM:$ACCEPT_PORT_TO -j ACCEPT"

mv $IPTABLES_CONFIG $IPTABLES_CONFIG_BACKUP
cat $IPTABLES_CONFIG_BACKUP | \
sed -r -e "s/$IPTABLES_ACCEPT_LINE//" \
-e "/.+--dport 22 .+$/a $IPTABLES_ACCEPT_LINE" \
> $IPTABLES_CONFIG

service iptables restart


echo 'Configuring sshd...'
# SSH経由での直接のrootログインを禁止する。
# パスワード認証を許可する。(話を簡単にするため)
# リモートフォワードでループバック以外のアドレスでもバインドを許可する。
# See also: http://qiita.com/FGtatsuro/items/e2767fa041c96a2bae1f
# http://blog.cles.jp/item/5699

SSHD_CONFIG=/etc/ssh/sshd_config
SSHD_CONFIG_BACKUP=~/sshd_config.bak.$(date +%Y-%m-%d_%H-%M-%S)
Expand All @@ -66,7 +36,6 @@ cat $SSHD_CONFIG_BACKUP | \
sed -r -e 's/^# *PermitRootLogin +yes/PermitRootLogin no/' \
-e 's/^( *PasswordAuthentication +no)/#\1/' \
-e 's/^#( *PasswordAuthentication +yes)/\1/' \
-e 's/^#? *GatewayPorts +no/GatewayPorts clientspecified/' \
> $SSHD_CONFIG

service sshd restart
Expand Down

0 comments on commit 80e9986

Please sign in to comment.