1 views

実現する機能

VPS(Virtual Private Server、仮想専用サーバー)はroot権限があるので、自由に自宅サーバーを構築することができる反面、何でもありの設定が可能なのでセキュリティは最低限に設定されていると思った方が無難です。したがって、自宅サーバー並のセキュリティは自分で構築するしかありません。しかも、OSをインストールした直後に行う必要があります。そこで、以下にOSのインストール直後に行った初期設定の備忘録を掲載します。OSはCentOS7、VPSレンタルサーバーはCloudCore VPSです。

事前準備

自宅サーバーとして使用するVPS(Virtual Private Server、仮想専用サーバー)

自宅サーバーに使用するドメイン(ufuso.orgは例示なので、自分のドメインに置き換えること)

コンソール画面を開いて設定を開始

1.CloudCore VPSの場合で説明しますと、まずvpsの設定画面にログインします。赤枠1にユーザー名とパスワードを入力して、赤枠2の「ログイン」ボタンをクリック

cc01

2.設定画面が開きますので、赤枠の「リモートコンソール」をクリック

cc02

3.通常「端末」と呼ばれているコンソール画面が開きますので、下記の「初期設定作業」以下のコマンドを入力して各種設定作業をしていく手順になります。

cc04

※vps提供事業者のコンソール画面は使いづらいので、代わりに自宅PCのGNOME端末を使って、VPSに接続する方法をご紹介します。作業内容は同じですが、コマンドをコピペできるので、設定作業を大幅に短縮できます。

自宅PCのGNOME端末を使って、VPSに接続する手順

以下の黒背景部分はGNOME端末を表示しています。黄色はキーボードから入力するコマンド(コピペした方が楽ですが、コマンドは覚えられません)、緑はコマンドや処理内容の説明、白は自動表示する部分、赤は注意書きです。

tu@zorin:~$ ssh root@ufuso.org ← sshでvpsにドメイン名(例示はufuso.org)で
root接続
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
@    WARNING: REMOTE HOST IDENTIFICATION HAS CHANGED!       @
@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
IT IS POSSIBLE THAT SOMEONE IS DOING SOMETHING NASTY!
Someone could be eavesdropping on you right now (man-in-the-middle attack)!
It is also possible that a host key has just been changed.
The fingerprint for the ECDSA key sent by the remote host is
aa:bb:cc:dd:ee:ff:hh:ii:jj:kk:ll:mm:nn:oo:pp:qq.
Please contact your system administrator.
Add correct host key in /home/tu/.ssh/known_hosts to get rid of this message.
Offending ECDSA key in /home/tu/.ssh/known_hosts:4
  remove with: ssh-keygen -f "/home/tu/.ssh/known_hosts" -R ufuso.org
ECDSA host key for ufuso.org has changed and you have requested strict checking.
Host key verification failed. ← 古い秘密鍵が残っているので、これを削除しないと
接続できないようです

tu@zorin:~$ ssh-keygen -f "/home/tu/.ssh/known_hosts" -R ufuso.org ← 古い秘密鍵
を削除
# Host ufuso.org found: line 4 type ECDSA
/home/tu/.ssh/known_hosts updated.
Original contents retained as /home/tu/.ssh/known_hosts.old

tu@zorin:~$ ssh root@ufuso.org ← 改めて、sshでufuso.orgにrootで接続
The authenticity of host 'ufuso.org (123.456.78.9)' can't be established.
ECDSA key fingerprint is aa:bb:cc:dd:ee:ff:hh:ii:jj:kk:ll:mm:nn:oo:pp:qq.
Are you sure you want to continue connecting (yes/no)? yes ← yesを入力
Warning: Permanently added 'ufuso.org' (ECDSA) to the list of known hosts.
Warning: the ECDSA host key for 'ufuso.org' differs from the key for the IP address '123.456.78.9'
Offending key for IP in /home/tu/.ssh/known_hosts:4
Are you sure you want to continue connecting (yes/no)? yes ← yesを入力
root@ufuso.org's password:  ← パスワードを入力
Last failed login: Wed Jun  8 22:39:32 JST 2016 from 111.33.111.1 on ssh:notty
There were 405 failed login attempts since the last successful login.

初期設定作業

1.CentOSのアップデート(作成したユーザー名を「tu」とした場合で以下説明していきます)

[tu@ufuso ~]$ su - ← ユーザー権限tuから管理者権限rootに変更
パスワード: ← rootのpasswordを入力

[root@ufuso ~]#  ← rootへの変更が成功すると「$」記号が「#」に変化

[root@ufuso ~]# yum -y update ← インストール済パッケージの一括アップデート
インストール:
  kernel.x86_64 0:3.10.0-327.18.2.el7                                           

依存性関連をインストールしました:
  libtirpc.x86_64 0:0.2.4-0.6.el7        rpcbind.x86_64 0:0.2.0-33.el7_2       

更新:
  NetworkManager.x86_64 1:1.0.6-29.el7_2                                        
  NetworkManager-libnm.x86_64 1:1.0.6-29.el7_2                                  
  NetworkManager-team.x86_64 1:1.0.6-29.el7_2                                   
  NetworkManager-tui.x86_64 1:1.0.6-29.el7_2                                    
  avahi-autoipd.x86_64 0:0.6.31-15.el7_2.1                                      
  avahi-libs.x86_64 0:0.6.31-15.el7_2.1                                         
  bind-libs.x86_64 32:9.9.4-29.el7_2.3                                          
  bind-libs-lite.x86_64 32:9.9.4-29.el7_2.3                                     
  bind-license.noarch 32:9.9.4-29.el7_2.3                                       
  bind-utils.x86_64 32:9.9.4-29.el7_2.3                                         
  ca-certificates.noarch 0:2015.2.6-70.1.el7_2                                  
  chkconfig.x86_64 0:1.3.61-5.el7_2.1                                           
  coreutils.x86_64 0:8.22-15.el7_2.1                                            
  cronie.x86_64 0:1.4.11-14.el7_2.1                                             
  cronie-anacron.x86_64 0:1.4.11-14.el7_2.1                                     
  cyrus-sasl-lib.x86_64 0:2.1.26-20.el7_2                                       
  cyrus-sasl-plain.x86_64 0:2.1.26-20.el7_2                                     
  device-mapper.x86_64 7:1.02.107-5.el7_2.2                                     
  device-mapper-event.x86_64 7:1.02.107-5.el7_2.2                               
  device-mapper-event-libs.x86_64 7:1.02.107-5.el7_2.2                          
  device-mapper-libs.x86_64 7:1.02.107-5.el7_2.2                                
  dracut.x86_64 0:033-360.el7_2                                                 
  dracut-config-rescue.x86_64 0:033-360.el7_2                                   
  dracut-network.x86_64 0:033-360.el7_2                                         
  glibc.x86_64 0:2.17-106.el7_2.6                                               
  glibc-common.x86_64 0:2.17-106.el7_2.6                                        
  gmp.x86_64 1:6.0.0-12.el7_1                                                   
  gnutls.x86_64 0:3.3.8-14.el7_2                                                
  grub2.x86_64 1:2.02-0.34.el7.centos                                           
  grub2-tools.x86_64 1:2.02-0.34.el7.centos                                     
  httpd.x86_64 0:2.4.6-40.el7.centos.1                                          
  httpd-manual.noarch 0:2.4.6-40.el7.centos.1                                   
  httpd-tools.x86_64 0:2.4.6-40.el7.centos.1                                    
  initscripts.x86_64 0:9.49.30-1.el7_2.2                                        
  kernel-tools.x86_64 0:3.10.0-327.18.2.el7                                     
  kernel-tools-libs.x86_64 0:3.10.0-327.18.2.el7                                
  kexec-tools.x86_64 0:2.0.7-38.el7_2.1                                         
  kpartx.x86_64 0:0.4.9-85.el7_2.4                                              
  kpatch.noarch 0:0.3.1-1.el7_2                                                 
  krb5-libs.x86_64 0:1.13.2-12.el7_2                                            
  libblkid.x86_64 0:2.23.2-26.el7_2.2                                           
  libgudev1.x86_64 0:219-19.el7_2.9                                             
  libmount.x86_64 0:2.23.2-26.el7_2.2                                           
  libndp.x86_64 0:1.2-6.el7_2                                                   
  libpng.x86_64 2:1.5.13-7.el7_2                                                
  libssh2.x86_64 0:1.4.3-10.el7_2.1                                             
  libsss_idmap.x86_64 0:1.13.0-40.el7_2.4                                       
  libsss_nss_idmap.x86_64 0:1.13.0-40.el7_2.4                                   
  libteam.x86_64 0:1.17-6.el7_2                                                 
  libuuid.x86_64 0:2.23.2-26.el7_2.2                                            
  libxml2.x86_64 0:2.9.1-6.el7_2.2                                              
  libxml2-python.x86_64 0:2.9.1-6.el7_2.2                                       
  logrotate.x86_64 0:3.8.6-7.el7_2                                              
  lvm2.x86_64 7:2.02.130-5.el7_2.2                                              
  lvm2-libs.x86_64 7:2.02.130-5.el7_2.2                                         
  mariadb-libs.x86_64 1:5.5.47-1.el7_2                                          
  mod_ssl.x86_64 1:2.4.6-40.el7.centos.1                                        
  nspr.x86_64 0:4.11.0-1.el7_2                                                  
  nss.x86_64 0:3.21.0-9.el7_2                                                   
  nss-softokn.x86_64 0:3.16.2.3-14.2.el7_2                                      
  nss-softokn-freebl.x86_64 0:3.16.2.3-14.2.el7_2                               
  nss-sysinit.x86_64 0:3.21.0-9.el7_2                                           
  nss-tools.x86_64 0:3.21.0-9.el7_2                                             
  nss-util.x86_64 0:3.21.0-2.2.el7_2                                            
  ntpdate.x86_64 0:4.2.6p5-22.el7.centos.2                                      
  ntsysv.x86_64 0:1.3.61-5.el7_2.1                                              
  numactl-libs.x86_64 0:2.0.9-6.el7_2                                           
  openldap.x86_64 0:2.4.40-9.el7_2                                              
  openssh.x86_64 0:6.6.1p1-25.el7_2                                             
  openssh-clients.x86_64 0:6.6.1p1-25.el7_2                                     
  openssh-server.x86_64 0:6.6.1p1-25.el7_2                                      
  openssl.x86_64 1:1.0.1e-51.el7_2.5                                            
  openssl-libs.x86_64 1:1.0.1e-51.el7_2.5                                       
  pcre.x86_64 0:8.32-15.el7_2.1                                                 
  polkit.x86_64 0:0.112-6.el7_2                                                 
  procps-ng.x86_64 0:3.3.10-5.el7_2                                             
  python-perf.x86_64 0:3.10.0-327.18.2.el7                                      
  python-pyudev.noarch 0:0.15-7.el7_2.1                                         
  quota.x86_64 1:4.01-11.el7_2.1                                                
  quota-nls.noarch 1:4.01-11.el7_2.1                                            
  rdma.noarch 0:7.2_4.1_rc6-2.el7                                               
  selinux-policy.noarch 0:3.13.1-60.el7_2.3                                     
  selinux-policy-targeted.noarch 0:3.13.1-60.el7_2.3                            
  sos.noarch 0:3.2-35.el7.centos.3                                              
  sssd-client.x86_64 0:1.13.0-40.el7_2.4                                        
  sudo.x86_64 0:1.8.6p7-17.el7_2                                                
  systemd.x86_64 0:219-19.el7_2.9                                               
  systemd-libs.x86_64 0:219-19.el7_2.9                                          
  systemd-python.x86_64 0:219-19.el7_2.9                                        
  systemd-sysv.x86_64 0:219-19.el7_2.9                                          
  teamd.x86_64 0:1.17-6.el7_2                                                   
  tuned.noarch 0:2.5.1-4.el7_2.3                                                
  tzdata.noarch 0:2016d-1.el7                                                   
  util-linux.x86_64 0:2.23.2-26.el7_2.2                                         

完了しました!

3 インターネットプロバイダから支給されたルーターには、ファイアウォールが設定されていますが、(Virtual Private Server、仮想専用サーバー)の場合は無防備だと考えた方が無難ですので、ファイアウォールは起動させたままにします。SELinuxも有効のままにしておきます。

[root@ufuso ~]# systemctl start firewalld ← 起動済みだとは思いますが念のために
起動

[root@ufuso ~]# systemctl enable firewalld ← 自動起動の設定

[root@ufuso ~]# firewall-cmd --list-all ← 最初から通信が許可されている「public」ゾーン
で、許可されている通信を確認
public (default, active)
  interfaces: eth0
  sources: 
  services: dhcpv6-client ssh ← 許可されている「サービス」はこれだけ
  ports: 
  masquerade: no
  forward-ports: 
  icmp-blocks: 
  rich rules: 

[root@ufuso ~]# firewall-cmd --add-service=http --zone=public --permanent
 ← ウェブサーバーにするのでhttp通信を許可
success ← 成功と表示されればOK

[root@ufuso ~]# firewall-cmd --add-service=imaps --zone=public --permanent
 ← メールサーバーにもするのでimaps通信を許可
success

[root@ufuso ~]# firewall-cmd --add-service=smtp --zone=public --permanent
 ← メールサーバーにもするのでsmtp通信を許可
success

[root@ufuso ~]# firewall-cmd --add-service=ftp --zone=public --permanent
 ← WordPressでファイルのやり取りもするのでftp通信を許可
success

[root@ufuso ~]# firewall-cmd --add-service=mysql --zone=public --permanent
 ← WordPressでデータベースも使うのでmysql通信を許可
success

[root@ufuso ~]# firewall-cmd --list-services --zone=public  --permanent ← 追加した
サービスを確認
dhcpv6-client ftp http imaps mysql smtp ssh ← 追加分が表示されていればOK

[root@ufuso ~]# firewall-cmd --reload ← ファイアウォールをリロードする
success

[root@ufuso ~]# getenforce ← SELinuxの状態確認
Enforcing ← 有効であることを確認

4 管理者rootになれるユーザを制限する

[root@ufuso ~]# usermod -G wheel tu ← rootユーザーをtuに限定する

[root@ufuso ~]# vi /etc/pam.d/su ← ユーザー認証ファイルの編集

#%PAM-1.0
auth            sufficient      pam_rootok.so
# Uncomment the following line to implicitly trust users in the "wheel" group.
#auth           sufficient      pam_wheel.so trust use_uid
# Uncomment the following line to require a user to be in the "wheel" group.
auth           required     pam_wheel.so use_uid ← #を削除してrootユーザーに
なれる者を限定
auth            include         system-auth
account         sufficient      pam_succeed_if.so uid = 0 use_uid quiet
account         include         system-auth
password        include         system-auth
session         include         system-auth
session         optional        pam_xauth.so

5 RPMforgeリポジトリ導入

[root@ufuso ~]# yum -y install http://pkgs.repoforge.org/rpmforge-release/rpmforge-release-0.5.3-1.el7.rf.x86_64.rpm
 ← repoをインストール
インストール:
  rpmforge-release.x86_64 0:0.5.3-1.el7.rf                                      

完了しました!

[root@ufuso ~]# vi /etc/yum.repos.d/rpmforge.repo
 ← 1を0に(自動を手動に)編集
### Name: RPMforge RPM Repository for RHEL 7 - dag
### URL: http://rpmforge.net/
[rpmforge]
name = RHEL $releasever - RPMforge.net - dag
baseurl = http://apt.sw.be/redhat/el7/en/$basearch/rpmforge
mirrorlist = http://mirrorlist.repoforge.org/el7/mirrors-rpmforge
#mirrorlist = file:///etc/yum.repos.d/mirrors-rpmforge
enabled = 0 ← 1を0に変更
protect = 0
gpgkey = file:///etc/pki/rpm-gpg/RPM-GPG-KEY-rpmforge-dag
gpgcheck = 1

※「yum install パッケージ名」と入力しても自動でインストールされないので、上記
リポジトリを使用してインストールする場合は、以下のようにコマンドを入力すること
 yum --enablerepo=rpmforge install パッケージ名                          

6 EPELリポジトリ導入

[root@ufuso ~]# yum -y install epel-release ← epel-releaseインストール
インストール:
  epel-release.noarch 0:7-5                                                     

完了しました!
 
[root@ufuso ~]# vi /etc/yum.repos.d/epel.repo ← 1を0に(自動を手動に)編集
[epel]
name=Extra Packages for Enterprise Linux 7 - $basearch
#baseurl=http://download.fedoraproject.org/pub/epel/7/$basearch
mirrorlist=https://mirrors.fedoraproject.org/metalink?repo=epel-7&arch=$basearch
failovermethod=priority
enabled = 0 ← 1を0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-7

 
※「yum install パッケージ名」と入力しても自動でインストールされないので、上記
リポジトリを使用してインストールする場合は、以下のようにコマンドを入力すること
 yum --enablerepo=epel install パッケージ名                          

7 nux-dextop repoの追加

[root@ufuso ~]#  rpm -Uvh http://li.nux.ro/download/nux/dextop/el7/x86_64/nux-dextop-release-0-1.el7.nux.noarch.rpm 
 ← nux-dextop-release-0-1.el7.nux.noarch.rpmのインストール
警告: /var/tmp/rpm-tmp.p8qAus: ヘッダー V4 RSA/SHA1 Signature、鍵 ID 85c6cd8a: NOKEY 
準備しています...              ################################# [100%] 
更新中 / インストール中... 
   1:nux-dextop-release-0-1.el7.nux   ################################# [100%]

[root@ufuso ~]# vi /etc/yum.repos.d/nux-dextop.repo ← nux-dextop.repoの編集
[nux-dextop]
name=Nux.Ro RPMs for general desktop use
baseurl=http://li.nux.ro/download/nux/dextop/el7/$basearch/ http://mirror.li.nux.ro/li.nux.ro/nux/dextop/el7/$basearch/
enabled=0 ← 1を0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-nux.ro
protect=0


[nux-dextop-testing]
name=Nux.Ro RPMs for general desktop use - testing
baseurl=http://li.nux.ro/download/nux/dextop-testing/el6/$basearch/
enabled=0
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-nux.ro
protect=0

※「yum install パッケージ名」と入力しても自動でインストールされないので、上記
リポジトリを使用してインストールする場合は、以下のようにコマンドを入力すること
 yum --enablerepo=nux-dextop install パッケージ名                          



コメントを残す

メールアドレスが公開されることはありません。 が付いている欄は必須項目です

CAPTCHA


このサイトはスパムを低減するために Akismet を使っています。コメントデータの処理方法の詳細はこちらをご覧ください