From 80e99860239d7e1813e19caeb61fabc81a070762 Mon Sep 17 00:00:00 2001 From: Piro / YUKI Hiroshi Date: Sat, 11 Apr 2015 03:13:26 +0900 Subject: [PATCH] Make servers secure --- scripts/reset.sh | 34 ---------------------------------- scripts/setup-front.sh | 24 ------------------------ scripts/setup-relay.sh | 31 ------------------------------- 3 files changed, 89 deletions(-) delete mode 100644 scripts/reset.sh diff --git a/scripts/reset.sh b/scripts/reset.sh deleted file mode 100644 index 4a4079e..0000000 --- a/scripts/reset.sh +++ /dev/null @@ -1,34 +0,0 @@ -#!/bin/bash -# Run as root, like: -# # ~/reset.sh - - -echo 'Disallowing accesses for large number ports...' -# iptablesの設定を削除して、余計なポートを閉じる。 - -IPTABLES_CONFIG=/etc/sysconfig/iptables -IPTABLES_CONFIG_BACKUP=~/iptables.bak.$(date +%Y-%m-%d_%H-%M-%S) - -mv $IPTABLES_CONFIG $IPTABLES_CONFIG_BACKUP -cat $IPTABLES_CONFIG_BACKUP | \ - sed -r -e "/--dport [0-9]+:[0-9]+/d" \ - > $IPTABLES_CONFIG - -service iptables restart - - -echo 'Configuring sshd...' -# リモートフォワードでループバック以外のアドレスでのバインドを禁止する。 - -SSHD_CONFIG=/etc/ssh/sshd_config -SSHD_CONFIG_BACKUP=~/sshd_config.bak.$(date +%Y-%m-%d_%H-%M-%S) - -mv $SSHD_CONFIG $SSHD_CONFIG_BACKUP -cat $SSHD_CONFIG_BACKUP | \ - sed -r -e 's/^GatewayPorts (clientspecified|yes)/GatewayPorts no/' \ - > $SSHD_CONFIG - -service sshd restart - - -echo 'Done.' diff --git a/scripts/setup-front.sh b/scripts/setup-front.sh index d875025..d4a105a 100644 --- a/scripts/setup-front.sh +++ b/scripts/setup-front.sh @@ -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"...' @@ -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) @@ -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 diff --git a/scripts/setup-relay.sh b/scripts/setup-relay.sh index f02f7b9..a067436 100644 --- a/scripts/setup-relay.sh +++ b/scripts/setup-relay.sh @@ -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でログインせずに済むように、作業用のユーザーを作成する。 @@ -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) @@ -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