CentOS7 インストール後の設定

YUMパッケージ管理
[root@centos ~]# yum -y update
[root@centos ~]# yum -y groupinstall "Base" "Development tools"
[root@centos ~]# yum -y install yum-cron
[root@centos ~]# vi /etc/yum/yum-cron.conf
apply_updates = no
↓
apply_updates = yes ←自動アップデート
[root@centos ~]# systemctl start yum-cron ←yum-cron起動 [root@centos ~]# systemctl enable yum-cron ←yum-cron自動起動設定 [root@centos ~]# systemctl is-enabled yum-cron ←yum-cron自動起動設定確認 enabled
ヒント
「yum -y update」でアップデート可能な全パッケージをアップデートします。 「yum -y install yum-cron」でyum-cronをインストールします。 「yum-cron」とは、インストール済みのパッケージを毎日自動更新します。 「systemctl」とは、Systemdでサービスを管理するコマンドです。
※systemctlコマンドの使い方
[root@centos ~]# systemctl status sshd ←sshdの状態を調べる
[root@centos ~]# systemctl start sshd ←sshdを起動する
[root@centos ~]# systemctl stop sshd ←sshdを停止する
[root@centos ~]# systemctl enable sshd ←sshdの自動起動を設定する
[root@centos ~]# systemctl disable sshd ←sshdの自動起動を解除する
[root@centos ~]# systemctl is-enabled sshd ←sshdの自動起動を確認する
[root@centos ~]# systemctl reload sshd ←sshdをリロードする
[root@centos ~]# systemctl restart sshd ←sshdを再起動する
ユーザー追加
[root@centos ~]# mkdir /etc/skel/public_html ←初回のみ(ユーザー追加時public_htmlを自動複製する)
[root@centos ~]# useradd user_name
[root@centos ~]# passwd user_name
Changing password for user user_name.
New password:user_pass ←ユーザーのパスワード入力
BAD PASSWORD: The password contains the user name in some form
Retype new password:user_pass ←パスワード再入力
passwd: all authentication tokens updated successfully.
[root@centos ~]# chmod 701 /home/user_name
ヒント
「/etc/skel」以下のファイルは、新しくユーザーを追加したとき自動的に複製されます。 「useradd ユーザー名」でユーザーを追加します。 「passwd ユーザー名」でユーザーのパスワードを設定します。 「chmod」でアクセス権を変更します。
TCP Wrapper設定
[root@centos ~]# echo "sshd: ALL" >> /etc/hosts.allow
[root@centos ~]# echo "ALL: ALL" >> /etc/hosts.deny
ヒント
hosts.allowとhosts.denyは、hosts.allowが優先されます。 /etc/hosts.allowでsshdの接続を全てのホストから許可(それ以降のルールは無視される) /etc/hosts.denyで全ての接続を拒否(allowで許可されたルール以外は全て拒否される) ローカルのみアクセスを許可する場合は /etc/hosts.allowの「sshd: ALL」を「sshd: 192.168.1.」に変更。
SSH設定
[root@centos ~]# vi /etc/ssh/sshd_config
#PermitRootLogin yes
↓
PermitRootLogin no ←コメント解除&変更(rootでログインを禁止)

#PermitEmptyPasswords no
↓
PermitEmptyPasswords no ←コメント解除(空のパスワードを禁止)

AllowUsers user_name ←最終行に追加(ユーザーuser_nameのみログインを許可)
[root@centos ~]# systemctl reload sshd
ヒント
上記の設定により次回からSSHでrootのログインは禁止されます。
SELinux無効化
[root@centos ~]# getenforce
Enforcing ←SELinux有効
[root@centos ~]# setenforce 0
[root@centos ~]# getenforce
Permissive ←SELinux無効
[root@centos ~]# vi /etc/sysconfig/selinux
SELINUX=enforcing
↓
SELINUX=disabled ←変更(起動時に無効にする)
ヒント
setenforce 0でSELinuxを無効にする。 /etc/sysconfig/selinuxを編集してシステム起動時にSELinuxを無効にする。
rootになれるユーザーを限定する
[root@centos ~]# vi /etc/pam.d/su
#auth		required	pam_wheel.so use_uid
↓
auth		required	pam_wheel.so use_uid ←コメント解除
[root@centos ~]# usermod -G wheel user_name
ホストネーム変更
[root@centos ~]# vi /etc/hosts
127.0.0.1   localhost localhost.localdomain localhost4 localhost4.localdomain4
↓
127.0.0.1   localhost centos.server-manual.com localhost4 localhost4.localdomain4 ←変更(FQDNを指定)
[root@centos ~]# hostname centos.server-manual.com ←ホスト名変更 [root@centos ~]# hostname ←ホスト名確認 centos.server-manual.com
文字コードをUTF-8に変更
[root@centos ~]# localectl ←現在の文字コードを確認
   System Locale: LANG=C
       VC Keymap: n/a
      X11 Layout: n/a
[root@centos ~]# localectl set-locale LANG=ja_JP.UTF-8 ←UTF-8に変更
[root@centos ~]# localectl ←変更を確認
   System Locale: LANG=ja_JP.UTF-8
       VC Keymap: n/a
      X11 Layout: n/a
Home PageTop