1. OS再インストール
VPSのコンパネからOSを再インストール。
今度は、最初からパケットフィルタリングの設定を行っておく。
- SSH:22 → 開放(後で閉じる)
- Web:80/443 → 開放
- メール:25/110/143/465/587/993/995 → 開放
- カスタム:(SSH用の別番号) → 開放
ここで「公開鍵の登録」が出来るが、あくまでも「管理者ユーザー(root)」用の公開鍵なので登録はしない。そもそも、rootでのログインを切るのでroot用のカギは不要。
2. 初期設定いろいろ
2.1. パッケージのアップデート
dnf -y update
2.2. 管理用一般ユーザーの追加
adduser hoge
passwd hoge
Changing password for user hoge.
New password:
Retype new password:
passwd: all authentication tokens updated successfully.
usermod -G wheel hoge
2.3. sudo関連
vi /etc/pam.d/su
#%PAM-1.0
(中略)
# Uncomment the following line to require a user to be in the "wheel" group.
#auth required pam_wheel.so use_uid
↓
auth required pam_wheel.so use_uid
2.4. セキュリティ関連のパッケージを自動アップデート
dnf -y install dnf-automatic
vi /etc/dnf/automatic.conf
===
[commands]
# What kind of upgrade to perform:
# default = all available upgrades
# security = only the security upgrades
upgrade_type = default
↓
upgrade_type = security
# Whether updates should be applied when they are available, by
# dnf-automatic.timer. notifyonly.timer, download.timer and
# install.timer override this setting.
apply_updates = no
↓
apply_updates = yes
===
systemctl enable dnf-automatic.timer
systemctl start dnf-automatic.timer
2.5. SSH関連
2.5.1. sshdの設定ファイルを変更
vi /etc/ssh/sshd_config
### root の直ログイン禁止
#PermitRootLogin yes
↓
PermitRootLogin no # コメント解除し、no に変更。
### 空パスワードの禁止
#PermitEmptyPasswords no
↓
PermitEmptyPasswords no # コメント解除。
### パスワード認証を禁止
PasswordAuthentication yes
↓
PasswordAuthentication no
### 公開鍵認証を有効に
PubkeyAuthentication yes # コメント解除
### ポート番号変更
# Port 22
↓
Port 99999 # コメント解除し、ポート番号を変更
設定ファイルを変更したら、サービスを再起動。
systemctl restart sshd
2.5.2. クライアント側で鍵ファイル生成し、サーバーにアップ
以下参照。
Macからの場合
Windowsからの場合(Teraterm使用)
2.6. ホスト名変更
hostnamectl set-hostname hogehoge.xxx
2.7. 日本語化
dnf -y install langpacks-ja
localectl set-locale LANG=ja_JP.utf8
localectl
System Locale: LANG=ja_JP.utf8
VC Keymap: jp
X11 Layout: jp
2.8. リポジトリの追加
dnf install epel-release
dnf install https://rpms.remirepo.net/enterprise/remi-release-8.rpm
普段は無効化しておき、必要な時だけリポジトリを都度指定する。
vi /etc/yum.repos.d/epel.repo
[epel]
name=Extra Packages for Enterprise Linux $releasever - $basearch
#baseurl=https://download.fedoraproject.org/pub/epel/$releasever/Everything/$basearch
metalink=https://mirrors.fedoraproject.org/metalink?repo=epel-$releasever&arch=$basearch&infra=$infra&content=$contentdir
enabled=1 ← ここを0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-EPEL-8
(以下略)
vi /etc/yum.repos.d/remi-safe.repo
[remi-safe]
name=Safe Remi's RPM repository for Enterprise Linux 8 - $basearch
#baseurl=http://rpms.remirepo.net/enterprise/8/safe/$basearch/
#mirrorlist=https://rpms.remirepo.net/enterprise/8/safe/$basearch/httpsmirror
mirrorlist=http://cdn.remirepo.net/enterprise/8/safe/$basearch/mirror
enabled=1 ← ここを0に変更
gpgcheck=1
gpgkey=file:///etc/pki/rpm-gpg/RPM-GPG-KEY-remi.el8
(以下略)