Ubuntu14.04.3TLS標準サーバ用設定

Conohaでサーバを立てようとしてUbuntuを導入したけど、セキュリティ的に甘々だったので
セキュリティ設定を施した形のUbuntuの手順をまとめておこうと思って、まとめておく。
色々なサイトのつぎはぎだけど、まぁここまでしとけば大丈夫でしょう。
サーバ構築はHyper-V使ってやってます。昔みたいに物理サーバを調達しなくていいので
やりやすくはなっていますな。
次はCentOSの手順をまとめておけばどっちでも対応できますな。
いずれはDockerFileに落とし込めればいいなぁと思いつつ。
ConohaでWebサイト立ち上げる際にはApacheとか入れないといけないのでその辺は
また別途、考えるかな。


●参考サイト

●大まかな手順
1.初期設定
 (1)ホームディレクトリのアクセス権限設定
 (2)追加ユーザへのホームディレクトリアクセス制限設定

2.SSH関連設定
 (1)sshlogin用ユーザ追加
 (2)sshログイン可能ユーザ限定
 (3)ssh_config修正
 (4)ssh再起動

3.OS関連セキュリティ強化
 (1)カーネルのセキュリティ設定
 (2)不要サービス停止
 (3)SELinuxをOFFにする

4.ネットワーク関連防御設定
 (1)host.allowとhosts.denyファイルの修正
 (2)IPSpoofing防止
 (3)パケットソースフィルタリング及び偽装IPのログ排出
 (4)ファイアウォールの設定

5:セキュリティツール導入
 (1)logwatchインストール
 (2)chkrootkitインストール
 (3)改ざん検知ツールインストール
 (4)Fail2banインストール
 (5)Clamvインストール

6:その他ツール類設定
 (1)NTPインストール
 (2)SNMPインストール
 (3)デフォルトエディタの変更

7:最新パッチ適用

8:ホスト名設定、IPアドレス固定化

9:再起動

●実際の作業
1.初期設定
(1)ホームディレクトリのアクセス権限設定
sudo chmod 750 $HOME
[sudo] password for hoge: 
hoge@ubuntutestsrv:~$ ls -ld $HOME
drwxr-x--- 3 hoge hoge 4096 11月 21 11:42 /home/hoge

(2)追加ユーザへのホームディレクトリアクセス制限設定
hoge@ubuntutestsrv:~$ mkdir ~/confbk
hoge@ubuntutestsrv:~$ sudo cp /etc/adduser.conf ~/confbk
hoge@ubuntutestsrv:~$ sudo sed -i "s/DIR_MODE=0755/DIR_MODE=0750/g" /etc/add user.conf
hoge@ubuntutestsrv:~$ diff ~/confbk/adduser.conf /etc/adduser.conf
56c56
< DIR_MODE=0755
---
> DIR_MODE=0750


2.SSH関連設定
(1)sshlogin用ユーザ追加
hoge@ubuntutestsrv:~$ sudo adduser sshloginuser
ユーザー `sshloginuser' を追加しています...
新しいグループ `sshloginuser' (1001) を追加しています...
新しいユーザー `sshloginuser' (1001) をグループ `sshloginuser' に追加しています...
ホームディレクトリ `/home/sshloginuser' を作成しています...
`/etc/skel' からファイルをコピーしています...
新しい UNIX パスワードを入力してください: 
新しい UNIX パスワードを再入力してください: 
passwd: password updated successfully
Changing the user information for sshloginuser
Enter the new value, or press ENTER for the default
 Full Name []: 
 Room Number []: 
 Work Phone []: 
 Home Phone []: 
 Other []: 
以上で正しいですか? [Y/n] y
hoge@ubuntutestsrv:~$ ls -ld /home/sshloginuser
drwxr-x--- 2 sshloginuser sshloginuser 4096 11月 21 11:52 /home/sshloginuser

(2)sshログイン可能ユーザ限定
・configバックアップ
hoge@ubuntutestsrv:~$ sudo cp /etc/ssh/sshd_config ~/confbk/
hoge@ubuntutestsrv:~$ echo "AllowGroups sshlogin" | sudo tee -a /etc/ssh/ssh d_config
AllowGroups sshlogin
hoge@ubuntutestsrv:~$ diff /etc/ssh/sshd_config ~/confbk/sshd_config
89d88
< AllowGroups sshlogin


・ユーザ追加
hoge@ubuntutestsrv:~$ sudo addgroup XXXXX
グループ `XXXXX' (GID 1002) を追加しています...
完了。
hoge@ubuntutestsrv:~$ sudo gpasswd -a XXXXX XXXXX
Adding user sshloginuser to group XXXXX

・ssh接続ユーザがsudoでコマンドを実行できないことを確認(ssh接続ユーザで再接続して実行)
XXXXX@ubuntutestsrv:~$ sudo sshloginuser
XXXXX@ubuntutestsrv:~$ sudo /etcservice ssh restart
[sudo] password for sshloginuser: 
sudo: 1 incorrect password attempt

(3)ssh_config修正
XXXXX@ubuntutestsrv:~$ su - hoge
hoge@ubuntutestsrv:~$ sudo vi /etc/ssh/sshd_config
[sudo] password for hoge: 

・編集内容
※下記のPortの後を22から別の番号へ修正
# What ports, IPs and protocols we listen for
Port XXXXX

※PermitRootLogin noを追記しその上をコメントアウト
# Authentication:
LoginGraceTime 120
#PermitRootLogin without-password
PermitRootLogin no

・servicesファイルのsshポート番号修正

hoge@ubuntutestsrv:~$ sudo vi /etc/services
[sudo] password for hoge:

※sshの箇所の右の番号を修正して保存
ssh             XXXXX/tcp                               # SSH Remote Login Protocol
ssh             XXXXX/udp

(4)ssh再起動
hoge@ubuntutestsrv:~$ sudo sshd -t
hoge@ubuntutestsrv:~$ service ssh restart
hoge@ubuntutestsrv:~$ sudo service ssh restart
ssh stop/waiting
ssh start/running, process 1530


※TeraTermでssh接続可能ユーザでしかログインできないことを確認
※TeraTermで22番ポートで接続した際にエラーとなることを確認


3.OS関連セキュリティ強化
(1)カーネルのセキュリティ設定(1になっていればOK)
hoge@ubuntutestsrv:~$ sudo cat /proc/sys/net/ipv4/tcp_syncookies
1

(2)不要サービス停止
・sysv-rc-confのインストール
hoge@ubuntutestsrv:~$ sudo apt-get -y install sysv-rc-conf
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~停止~
libcurses-ui-perl (0.9609-1) を設定しています ...
sysv-rc-conf (0.99-7) を設定しています ...

・不要サービス停止
hoge@ubuntutestsrv:~$ sudo sysv-rc-conf


※GUI画面が立ち上がるので下記のサービスのXを取り消す
dns-clean
grub-common
ondemand
pppd-dns
rc.local
rsync

(3)SELinuxをOFFにする
・設定ツールインストール
hoge@ubuntutestsrv:~$ sudo apt-get install selinux-utils
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~中略~
man-db (2.6.7.1-1ubuntu1) のトリガを処理しています ...
selinux-utils (2.2.2-1ubuntu0.1) を設定しています ...

・無効化コマンド実行
hoge@ubuntutestsrv:~$ sudo setenforce 0
setenforce: SELinux is disabled


4.ネットワーク関連防御設定
(1)host.allowとhosts.denyファイルの修正
・host.allow編集
hoge@ubuntutestsrv:~$ sudo vi /etc/hosts.allow

※下記を追記して保存(自ネットワークからのみ許可)
ALL:192.168.1.

・hosts.denyを編集
hoge@ubuntutestsrv:~$ sudo vi /etc/hosts.deny

※下記を追記して保存(sshdは外部から接続禁止)
sshd:ALL


(2)IPSpoofing防止
hoge@ubuntutestsrv:~$ sudo vi /etc/host.conf

※三行追記
# The "order" line is only used by old versions of the C library.
order hosts,bind
multi on
nospoof on


(3)パケットソースフィルタリング及び偽装IPのログ排出
・設定ファイル編集

hoge@ubuntutestsrv:~$ sudo vi /etc/sysctl.conf


下記内容に編集して保存する。
※IP偽装保護(コメントアウト解除)
# Uncomment the next two lines to enable Spoof protection (reverse-path filter)
# Turn on Source Address Verification in all interfaces to
# prevent some spoofing attacks
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.rp_filter=1

※SYN攻撃ブロック(コメントアウト解除)
# Uncomment the next line to enable TCP/IP SYN cookies
# See http://lwn.net/Articles/277146/
# Note: This may impact IPv6 TCP sessions too
net.ipv4.tcp_syncookies=1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 5

※リダイレクト送信無視(追加)
# Do not accept ICMP redirects (prevent MITM attacks)
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0

※ソースパケットルーティング禁止(追加)
# Do not accept IP source route packets (we are not a router)
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.default.accept_source_route = 0

※ Martiansのログ(コメント解除)
# Log Martian Packets
net.ipv4.conf.all.log_martians = 1

# ICMPブロードキャストリクエストを無視(追記)
net.ipv4.icmp_echo_ignore_broadcasts = 1

# ICMPリダイレクトを無視(追記)
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0

#IPv6無効化(追記)
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
net.ipv6.conf.lo.disable_ipv6 = 1



・設定内容確認
hoge@ubuntutestsrv:~$ sudo sysctl -p
net.ipv4.conf.default.rp_filter = 1
net.ipv4.conf.all.rp_filter = 1
net.ipv4.tcp_syncookies = 1
net.ipv4.tcp_max_syn_backlog = 2048
net.ipv4.tcp_synack_retries = 2
net.ipv4.tcp_syn_retries = 5
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.all.accept_source_route = 0
net.ipv6.conf.all.accept_source_route = 0
net.ipv4.conf.default.accept_source_route = 0
net.ipv6.conf.default.accept_source_route = 0
net.ipv4.conf.all.log_martians = 1
net.ipv4.icmp_echo_ignore_broadcasts = 1
net.ipv4.conf.all.accept_redirects = 0
net.ipv6.conf.all.accept_redirects = 0
net.ipv4.conf.default.accept_redirects = 0
net.ipv6.conf.default.accept_redirects = 0

(4)ファイアウォールの設定
・状態確認
hoge@ubuntutestsrv:~$ sudo ufw status
状態: 非アクティブ

・ポリシーの設定(外部からのパケットはSSH、http、httpsのみを許可する。)
hoge@ubuntutestsrv:~$ sudo ufw default deny
デフォルトの incoming ポリシーは 'deny' に変更しました
(適用したい内容に基づいて必ずルールを更新してください)
 sudo ufw default allow outgoing
デフォルトの outgoing ポリシーは 'allow' に変更しました
(適用したい内容に基づいて必ずルールを更新してください)
hoge@ubuntutestsrv:~$  sudo ufw logging low
ログ取得を有効にしました
hoge@ubuntutestsrv:~$ sudo ufw allow ssh
ルールを追加しました
ルールを追加しました (v6)
hoge@ubuntutestsrv:~$ sudo ufw allow http
ルールをアップデートしました
ルールをアップデートしました(v6)
hoge@ubuntutestsrv:~$ sudo ufw allow https
ルールをアップデートしました
ルールをアップデートしました(v6)

・ufw有効化と設定確認
hoge@ubuntutestsrv:~$ sudo ufw enable
Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
ファイアウォールはアクティブかつシステムの起動時に有効化されます。
hoge@ubuntutestsrv:~$ sudo ufw status
状態: アクティブ

To                         Action      From
--                         ------      ----
80                         ALLOW       Anywhere
443                        ALLOW       Anywhere
XXXXX                      ALLOW       Anywhere
80 (v6)                    ALLOW       Anywhere (v6)
443 (v6)                   ALLOW       Anywhere (v6)
XXXXX (v6)                 ALLOW       Anywhere (v6)


5:セキュリティツール導入
(1)logwatchインストール
※GUIが表示されるので[サテライト]を選択する。
hoge@ubuntutestsrv:~$ sudo apt-get install logwatch
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~中略~
logwatch (7.4.0+svn20130529rev144-1ubuntu1) を設定しています ...
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...

(2)chkrootkitインストール
・インストール
hoge@ubuntutestsrv:~$ sudo apt-get -y install chkrootkit
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
~略~
chkrootkit (0.49-4.1ubuntu1.14.04.1) を設定しています ...
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...

・自動実行スクリプト作成用ユーティリティインストール(mailコマンド用)
hoge@ubuntutestsrv:~$ sudo apt-get install mailutils
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
bin/mail.mailutils を使います
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...

・動作確認(何も出てこなくて正解)
hoge@ubuntutestsrv:~$ sudo chkrootkit | grep INFECTED
Searching for Suckit rootkit...                             Warning: /sbin/init INFECTED
hoge@ubuntutestsrv:~$ /etc/cron.daily/chkrootkit
hoge@ubuntutestsrv:~$

・コマンド退避(SCPでダウンロードしてCD-R等に退避)
hoge@ubuntutestsrv:~$ sudo su
root@ubuntutestsrv:/home/hoge# mkdir chkrootkitcmd
root@ubuntutestsrv:/home/hoge# cp /usr/bin/which chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/awk chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/cut chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/echo chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/egrep chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/find chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/head chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/id chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/ls chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/netstat chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/ps chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/strings chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/sed chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /usr/bin/ssh chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# cp /bin/uname chkrootkitcmd/
root@ubuntutestsrv:/home/hoge# chkrootkit -p chkrootkitcmd | grep INFECTED
root@ubuntutestsrv:/home/hoge# tar -cvf chkrootkit.tar chkrootkitcmd
chkrootkitcmd/
chkrootkitcmd/cut
chkrootkitcmd/strings
chkrootkitcmd/echo
chkrootkitcmd/sed
chkrootkitcmd/which
chkrootkitcmd/ps
chkrootkitcmd/id
chkrootkitcmd/netstat
chkrootkitcmd/find
chkrootkitcmd/awk
chkrootkitcmd/ssh
chkrootkitcmd/uname
chkrootkitcmd/head
chkrootkitcmd/ls
chkrootkitcmd/egrep
root@ubuntutestsrv:/home/hoge# rm -Rf chkrootkitcmd

(3)改ざん検知ツールインストール
・インストール
hoge@ubuntutestsrv:~$ sudo apt-get install -y aide
[sudo] password for hoge:
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
Creating config file /etc/cron.daily/aide with new version

・初回起動DBファイルを作成しDBファイル作成を確認(かなり時間がかかる)
hoge@ubuntutestsrv:~$ sudo nice -n 19 /usr/sbin/aideinit -y
Running aide --init...
AIDE 0.16a2-19-g16ed855 initialized AIDE database at /var/lib/aide/aide.db.new
Start timestamp: 2015-11-22 10:13:06 +0900
Verbose level: 6

Number of entries:      68864

---------------------------------------------------
The attributes of the (uncompressed) database(s):
---------------------------------------------------

/var/lib/aide/aide.db.new
  RMD160   : rNCBPybeU6zZ6i0zLnom7TXzXns=
  TIGER    : fPplBRJ2+0XGWGk0y/d1GQ9QHqM2KBtD
  SHA256   : iGlJTRQgLA3bRPVSu3U9st9c0RIVP3bo
             9JrF1+Xtfa0=
  SHA512   : H9ZIWoK58cF2T/CWFDkTGusHpEu3uHRe
             cdHOllwEPox4cq62ZCzHgO6nu+MAt8DP
             qtds9rZtDGzYSr2fhJzi3Q==
  CRC32    : 8BqgHg==
  HAVAL    : jJLVrgUKoGp7yDZeI+h84W0g9jp4asON
             nkb1cRXmfK8=
  GOST     : gIJWHQdDd/JdXwJxp2WAnb/LHxaCkU+I
             wBh5zykD0no=


End timestamp: 2015-11-22 10:15:54 +0900 (run time: 2m 48s)
hoge@ubuntutestsrv:~$ sudo ls -al /var/lib/aide/
合計 23104
drwxr-xr-x  2 root root     4096 11月 22 10:15 .
drwxr-xr-x 45 root root     4096 11月 22 10:12 ..
-rw-r--r--  1 root root    56163 11月 22 10:13 aide.conf.autogenerated
-rw-------  1 root root 11793226 11月 22 10:15 aide.db
-rw-------  1 root root 11793226 11月 22 10:15 aide.db.new

・初期DBファイル退避(ファイルはSCPでダウンロードしてCD-R等に退避)
hoge@ubuntutestsrv:~$ sudo mv /var/lib/aide/aide.db.new /var/lib/aide/aide.db
[sudo] password for hoge:
hoge@ubuntutestsrv:~$ sudo ls -al /var/lib/aide/aide.db
-rw------- 1 root root 5503941 11月 21 17:10 /var/lib/aide/aide.db
hoge@ubuntutestsrv:~$ sudo mkdir /var/lib/aide/please-dont-call-aide-without-parameters/
hoge@ubuntutestsrv:~$ sudo cp /var/lib/aide/aide.db /var/lib/aide/please-dont-call-aide-without-parameters/aide.db

・監視除外対象設定
hoge@ubuntutestsrv:~$ sudo vi /etc/aide/aide.conf

※下記を追記する。
#検出から除外するファイルパスを追記
#他にもあれば自分で追記する
!/var/log
!/root
!/home
!/mnt

・動作確認
hoge@ubuntutestsrv:~$ sudo aide --update
hoge@ubuntutestsrv:~$ sudo aide -C
WARNING: Old db contains a entry that shouldn't be there, run --init or --update
AIDE 0.16a2-19-g16ed855 found NO differences between database and filesystem. Looks okay!!
Start timestamp: 2015-11-22 11:00:13 +0900

Number of entries:      0

---------------------------------------------------
The attributes of the (uncompressed) database(s):
---------------------------------------------------

/var/lib/aide/please-dont-call-aide-without-parameters/aide.db
  MD5      : cntKWmToFl8Fp7XYyyy5lw==
  SHA1     : lagBcCapQYZPTRpwpTeB4g1pe08=
  RMD160   : L37PH7sFMkC7lWW6+1Vl0bWPj9g=
  TIGER    : nT/drJGqb9g7IUgY7IeMW+0cNfNBzrnu
  SHA256   : vSCMn84OKyeGITbAR8OcH1FlSeRrxF6l
             VYYS3ToGjyI=
  SHA512   : uKXpv/GZ4vXMxw+QE0/IiVb5pepsIVH2
             VHEBwfnjoL75Rqt/tWbYktbwNrPSpPH8
             EyNh0dhVoU+iLGSWrRLQXg==
  CRC32    : N9NLYQ==
  HAVAL    : Q+AE7lED3xJkdkFug8EoJ1Gc96WqknN7
             7Wr2tD9QwEM=
  GOST     : ouoSJwuB3103bMUXBAuUWk/dtvswkj44
             dVdin9+qDG0=
  WHIRLPOOL: 32qKnLlgg6qxmKhQ7sEE7PKjYTwjsQ1K
             6Jz/JYPRbqyuW5jOPByuKhDy1t0ljFol
             6KkkZQ5qlJ288eZVK/ssWQ==


End timestamp: 2015-11-22 11:00:13 +0900 (run time: 0m 0s)

(4)Fail2banインストール
hoge@ubuntutestsrv:~$ sudo apt-get install fail2ban
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
whois (5.1.1) を設定しています ...
ureadahead (0.100.0-16) のトリガを処理しています ...
hoge@ubuntutestsrv:~$ sudo iptables -L -v -n | grep fail2ban
 1092  121K fail2ban-ssh  tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 50022
Chain fail2ban-ssh (1 references)

(5)Clamvインストール
・インストールとアップデート
hoge@ubuntutestsrv:~$ sudo apt-get install clamav-base clamav-daemon clamav-freshclam
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...
ureadahead (0.100.0-16) のトリガを処理しています ...
hoge@ubuntutestsrv:~$ sudo /etc/init.d/clamav-freshclam start


・アップデート後の動作確認
hoge@ubuntutestsrv:~$ sudo tail /var/log/clamav/freshclam.log
Sat Nov 21 15:53:52 2015 -> --------------------------------------
Sat Nov 21 15:53:52 2015 -> freshclam daemon 0.98.7 (OS: linux-gnu, ARCH: x86_64, CPU: x86_64)
Sat Nov 21 15:53:52 2015 -> ClamAV update process started at Sat Nov 21 15:53:52 2015
hoge@ubuntutestsrv:~$ sudo /etc/init.d/clamav-freshclam start
hoge@ubuntutestsrv:~$ sudo tail /var/log/clamav/freshclam.log
Sat Nov 21 15:53:52 2015 -> --------------------------------------
Sat Nov 21 15:53:52 2015 -> freshclam daemon 0.98.7 (OS: linux-gnu, ARCH: x86_64, CPU: x86_64)
Sat Nov 21 15:53:52 2015 -> ClamAV update process started at Sat Nov 21 15:53:52 2015
Sat Nov 21 15:59:12 2015 -> Downloading main.cvd [100%]
Sat Nov 21 15:59:16 2015 -> main.cvd updated (version: 55, sigs: 2424225, f-level: 60, builder: neo)
hoge@ubuntutestsrv:~$ clamscan confbk/
confbk/adduser.conf: OK
confbk/sshd_config: OK

----------- SCAN SUMMARY -----------
Known viruses: 2424225
Engine version: 0.98.7
Scanned directories: 1
Scanned files: 2
Infected files: 0
Data scanned: 0.00 MB
Data read: 0.00 MB (ratio 0.00:1)
Time: 2.728 sec (0 m 2 s)

・スキャンを24時間に1回に修正
hoge@ubuntutestsrv:~$ sudo vi /etc/clamav/clamd.conf

※3600の部分を86400に修正
DatabaseDirectory /var/lib/clamav
#SelfCheck 3600
SelfCheck 86400

・root権限で起動させる(全ディレクトリを確認できるように)
hoge@ubuntutestsrv:~$ sudo vi /etc/clamav/clamd.conf

※Userの箇所をコメントアウト
# the default with environment variables TMPDIR/TMP/TEMP possible
#User clamav

・Clamav再起動
hoge@ubuntutestsrv:~$ sudo /etc/init.d/clamav-daemon restart
 * Stopping ClamAV daemon clamd                                          [ OK ]
 * Starting ClamAV daemon clamd                                          [ OK ]

・定期スキャンスクリプト作成
hoge@ubuntutestsrv:~$ sudo vi /etc/cron.daily/clamav
hoge@ubuntutestsrv:~$ sudo chmod 755 /etc/cron.daily/clamav
hoge@ubuntutestsrv:~$ ls -la /etc/cron.daily/clamav
-rwxr-xr-x 1 root root 755 11月 22 11:59 /etc/cron.daily/clamav


※下記の内容で新規作成
#!/bin/bash

PATH=/usr/bin:/bin

# スキャン除外設定
excludelist=/root/clamscan.exclude
if [ -s $excludelist ]; then
    for i in `cat $excludelist`
    do
        if [ $(echo "$i"|grep \/$) ]; then
            i=`echo $i|sed -e 's/^\([^ ]*\)\/$/\1/p' -e d`
            excludeopt="${excludeopt} --exclude-dir=^$i"
        else
            excludeopt="${excludeopt} --exclude=^$i"
        fi
    done
fi

# ウイルススキャン
CLAMSCANTMP=`mktemp`
clamscan --recursive --remove ${excludeopt} / > $CLAMSCANTMP 2>&1
[ ! -z "$(grep FOUND$ $CLAMSCANTMP)" ] && \

# レポートのメール送信
grep FOUND$ $CLAMSCANTMP | mail -s "Virus Found in `hostname`" root
rm -f $CLAMSCANTMP



6:その他ツール類設定
(1)NTPインストール
・インストール
hoge@ubuntutestsrv:~$ sudo apt-get install ntp
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
~略~
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...
ureadahead (0.100.0-16) のトリガを処理しています ...

・設定ファイル修正
hoge@ubuntutestsrv:~$  sudo vi /etc/ntp.conf

※server0~server3までをコメントアウトしてその下3行を追記
# Use servers from the NTP Pool Project. Approved by Ubuntu Technical Board
# on 2011-02-08 (LP: #104525). See http://www.pool.ntp.org/join.html for
# more information.
#server 0.ubuntu.pool.ntp.org
#server 1.ubuntu.pool.ntp.org
#server 2.ubuntu.pool.ntp.org
#server 3.ubuntu.pool.ntp.org
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp

※一番下に追記
# Local users may interrogate the ntp server more closely.
restrict 127.0.0.1
restrict ::1
restrict 192.168.1.0 mask 255.255.255.0 nomodify notrap


・ntp再起動
hoge@ubuntutestsrv:~$ sudo /etc/init.d/ntp restart
 * Stopping NTP server ntpd                                              [ OK ]
 * Starting NTP server ntpd                                              [ OK ]
hoge@ubuntutestsrv:~$ sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
 ntp1.jst.mfeed. 133.243.236.17   2 u   28   64    1   29.402    0.081   0.000
 ntp2.jst.mfeed. 133.243.236.17   2 u   28   64    1   28.796   -1.255   0.000
 ntp3.jst.mfeed. 133.243.236.17   2 u   27   64    1   28.828   -2.450   0.000
 golem.canonical .INIT.          16 u    -   64    0    0.000    0.000   0.000

・接続確認
※10分ほどしてから確認して追加したntpサーバに印がついていればOK
hoge@ubuntutestsrv:~$ sudo ntpq -p
     remote           refid      st t when poll reach   delay   offset  jitter
==============================================================================
+ntp1.jst.mfeed. 133.243.236.17   2 u   63   64  177   11.015   -8.622   7.447
*ntp2.jst.mfeed. 133.243.236.17   2 u   64   64  177   10.972   -9.891  10.437
+ntp3.jst.mfeed. 133.243.236.17   2 u   65   64  177   10.016  -11.203   7.084
 golem.canonical .INIT.          16 u    -   64    0    0.000    0.000   0.000

(2)SNMPインストール(今は設定ファイルは編集しない)
・インストール
hoge@ubuntutestsrv:~$ sudo apt-get install snmpd
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
状態情報を読み取っています... 完了
~略~
libc-bin (2.19-0ubuntu6.6) のトリガを処理しています ...
ureadahead (0.100.0-16) のトリガを処理しています ...
hoge@ubuntutestsrv:~$ sudo apt-get install snmp
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
man-db (2.6.7.1-1ubuntu1) のトリガを処理しています ...
snmp (5.7.2~dfsg-8.1ubuntu3.1) を設定しています ...

・動作確認
hoge@ubuntutestsrv:~$ sudo /etc/init.d/snmpd stop
 * Stopping network management services:                                        
hoge@ubuntutestsrv:~$ sudo /etc/init.d/snmpd start
 * Starting network management services:                                        
hoge@ubuntutestsrv:~$ snmpwalk -v 1 -c public localhost
iso.3.6.1.2.1.1.1.0 = STRING: "Linux ubuntutestsrv 3.19.0-25-generic #26~14.04.1-Ubuntu SMP Fri Jul 24 21:16:20 UTC 2015 x86_64"
iso.3.6.1.2.1.1.2.0 = OID: iso.3.6.1.4.1.8072.3.2.10
iso.3.6.1.2.1.1.3.0 = Timeticks: (4427) 0:00:44.27
~略~
iso.3.6.1.2.1.25.1.7.0 = INTEGER: 0
End of MIB


(3)デフォルトエディタの変更
・設定を変更(3を入力してEnter)
hoge@ubuntutestsrv:~$ sudo  update-alternatives --config editor
alternative editor (/usr/bin/editor を提供) には 4 個の選択肢があります。

  選択肢    パス              優先度  状態
------------------------------------------------------------
* 0            /bin/nano            40        自動モード
  1            /bin/ed             -100       手動モード
  2            /bin/nano            40        手動モード
  3            /usr/bin/vim.basic   30        手動モード
  4            /usr/bin/vim.tiny    10        手動モード

現在の選択 [*] を保持するには Enter、さもなければ選択肢の番号のキーを押してくだ さい: 3
update-alternatives: /usr/bin/editor (editor) を提供するために 手動モード で /usr/bin/vim.basic を使います

・変更されたか確認
hoge@ubuntutestsrv:~$ sudo  update-alternatives --config editor
alternative editor (/usr/bin/editor を提供) には 4 個の選択肢があります。

  選択肢    パス              優先度  状態
------------------------------------------------------------
  0            /bin/nano            40        自動モード
  1            /bin/ed             -100       手動モード
  2            /bin/nano            40        手動モード
* 3            /usr/bin/vim.basic   30        手動モード
  4            /usr/bin/vim.tiny    10        手動モード

現在の選択 [*] を保持するには Enter、さもなければ選択肢の番号のキーを押してくだ さい:

・nanoのアンインストール
hoge@ubuntutestsrv:~$ sudo apt-get remove nano
パッケージリストを読み込んでいます... 完了
依存関係ツリーを作成しています
~略~
install-info (5.2.0.dfsg.1-2) のトリガを処理しています ...


7:最新パッチ適用
・aptで最新パッチ適用
hoge@ubuntutestsrv:~$  sudo aptitude update
無視 http://jp.archive.ubuntu.com trusty InRelease
取得: 1 http://jp.archive.ubuntu.com trusty-updates InRelease [64.4 kB]
取得: 2 http://jp.archive.ubuntu.com trusty-backports InRelease [64.5 kB]
~略~
発見 http://security.ubuntu.com trusty-security/restricted Translation-en
発見 http://security.ubuntu.com trusty-security/universe Translation-en
hoge@ubuntutestsrv:~$

※ホスト名、IPアドレス変更前にイメージバックアップしておいた方がいい。


8:ホスト名設定、IPアドレス固定化
・IPアドレス変更
hoge@ubuntutestsrv:~$ sudo vi /etc/network/interfaces

※DHCPの箇所(上から3行をコメントアウトしIPアドレス設定を追記
# The primary network interface
#auto eth0
#iface eth0 inet dhcp

# Static Address
auto eth0
iface eth0 inet static
address X.X.X.X
network X.X.X.X
netmask X.X.X.X
broadcast X.X.X.X
gateway X.X.X.X
dns-nameservers X.X.X.X

・ホスト名変更
hoge@ubuntutestsrv:~$ sudo vi /etc/hostname

※変更後のホスト名を設定して保存する。
websrv01

hoge@ubuntutestsrv:~$ sudo vi /etc/hosts

※127.0.0.1をホスト名に書替し、固定IPアドレスのホスト名を追加
127.0.1.1       hoge
X.X.X.X      hoge.example.com


9:再起動
hoge@ubuntutestsrv:~$ sudo su
sudo: ホスト ubuntutestsrv の名前解決ができません
root@ubuntutestsrv:/home/hoge# reboot

コメント

このブログの人気の投稿

証券外務員1種勉強(計算式暗記用メモ)

GASでGoogleDriveのサブフォルダとファイル一覧を出力する

マクロ経済学(IS-LM分析)