前提
- Proxmox VE 9.0.9
- Fedora Server 42
はじめに
本記事では、Proxmox上で動作するFedoraを使用し、ポータブルSSDを活用した快適なファイル同期環境の構築方法をご紹介します。
ファイル共有にはSambaとSyncthingを使用しています。ポータブルSSDを共有先として利用する目的は、必要なときに取り外してWindows環境でもデータを確認するためです。
Fedora Server 42をダウンロード
下記のリンクからFedora Server 42
のISOをダウンロードする。
ProxmoxにISOをアップロード
Proxmoxで仮想マシン(VM)を作成
Proxmox VEのWEB GUIの右上にあるCreate VMを押下し設定を進めていきます。
Generalタブ
OSタブ
ISO imageにFedora Server 42
を選択する。
Systemタブ
Machineにq35
を指定し、BIOSにOVMF(UEFI)
を指定する。
Disksタブ
基本的にデフォルトのままでOKです。私はDisk sizeを32GiB
から16GiB
に変更しました。
CPUタブ
基本的にデフォルトのままでOKです。私はCoresを1
から2
に変更しました。
Memoryタブ
Ballooning Deviceのチェックをオフにします。
Networkタブ
Confirmタブ
設定内容を確認し、右下のFinishボタンを押下してください。
Fedoraのインストール
作成した仮想マシン(VM)を選択し、右上にある▶ Start
ボタンを押下する。
Console
メニューから設定を進めることができます。
ネットワークとホスト名
ユーザーの作成
インストール概要
Fedoraの設定
パッケージの更新
sudo dnf upgrade -y
SSHの設定
# ---------------------
# SSH 設定ファイル
# ---------------------
# 追加設定ファイルの指定
# Include /etc/ssh/sshd_config.d/*.conf
# サーバーのポートを指定
Port 22
# サーバーが待機するIPを指定
AddressFamily inet
ListenAddress 0.0.0.0
# 特定のユーザーだけ許可
AllowUsers secureuser {ユーザ名}
# Root ユーザーのログインを無効化
PermitRootLogin no
# 空パスワードを禁止
PermitEmptyPasswords no
# パスワード認証を無効化
# PasswordAuthentication no
# 公開鍵認証のみ許可
# PubkeyAuthentication yes
# 公開鍵認証の種類をED25519のみに限定する
HostKey /etc/ssh/ssh_host_ed25519_key
# 安全なアルゴリズムのみ許可する
KexAlgorithms curve25519-sha256@libssh.org
Ciphers chacha20-poly1305@openssh.com
MACs hmac-sha2-512-etm@openssh.com
# 逆引きDNSを無効化
UseDNS no
# ユーザーセッションのタイムアウト
ClientAliveInterval 300 # 5分間操作なしの場合接続切断
ClientAliveCountMax 0
# 接続失敗に対する制限
MaxAuthTries 3 # 最大3回の認証試行
MaxSessions 1 # 同時セッション数の制限
# バージョンの制限
Protocol 2
# 安全なタイムスタンプを強制
UsePAM yes
# ログインのグレース期間を設定
LoginGraceTime 20
# 転送・トンネリングを無効化
AllowAgentForwarding no
AllowTcpForwarding no
X11Forwarding no
PermitTunnel no
# Allow client to pass locale environment variables
AcceptEnv LANG LC_*
# SFTPを有効にする
# Subsystem sftp /usr/lib/openssh/sftp-server
{ユーザ名}はSSHでログインするものに変更してください。
SSHの設定ファイルのチェックを実施
sudo sshd -t
Firewalldの設定
# カスタムゾーンの作成
sudo firewall-cmd --permanent --new-zone=custom
sudo firewall-cmd --reload
# SSH、Samba、cockpit、Syncthingを許可
sudo firewall-cmd --permanent --zone=custom --add-rich-rule='rule family=ipv4 source address="192.168.0.0/16" port protocol="tcp" port="22" accept'
sudo firewall-cmd --permanent --zone=custom --add-rich-rule='rule family=ipv4 source address="192.168.0.0/16" port protocol="tcp" port="445" accept'
sudo firewall-cmd --permanent --zone=custom --add-rich-rule='rule family=ipv4 source address="192.168.0.0/16" port protocol="tcp" port="8384" accept'
sudo firewall-cmd --permanent --zone=custom --add-rich-rule='rule family=ipv4 source address="192.168.0.0/16" port protocol="tcp" port="9090" accept'
sudo firewall-cmd --permanent --zone=custom --add-rich-rule='rule family=ipv4 source address="192.168.0.0/16" port protocol="tcp" port="22000" accept'
# デフォルトゾーンの設定
sudo firewall-cmd --set-default-zone=custom
sudo firewall-cmd --reload
# ルールを確認
sudo firewall-cmd --list-all
自動更新の設定
dnf-automatic パッケージをインストール
sudo dnf install dnf-automatic -y
dnf-automatic 設定ファイル作成
apply_updates = yes
download_updates = yes
upgrade_type = default
サービスを有効にする
sudo systemctl enable --now dnf-automatic.timer
以下の設定は、任意設定になります。
Kernelの設定
# カーネルポインタ制限
kernel.kptr_restrict=2
# ASLR(アドレス空間配置のランダム化)を強制
kernel.randomize_va_space=2
# dmesg出力制限
kernel.dmesg_restrict=1
# 非特権BPF無効
kernel.unprivileged_bpf_disabled=1
# ptrace制限
kernel.yama.ptrace_scope=2
# 非特権ユーザ名前空間の無効化
kernel.unprivileged_userns_clone=0
# BPF JIT強化
net.core.bpf_jit_harden=2
# SYNクッキー有効
net.ipv4.tcp_syncookies=1
# IPv4 rp_filter有効
net.ipv4.conf.all.rp_filter=1
net.ipv4.conf.default.rp_filter=1
net.ipv4.conf.all.accept_redirects=0
net.ipv4.conf.default.accept_redirects=0
net.ipv4.conf.all.secure_redirects=0
net.ipv4.conf.default.secure_redirects=0
# IPv4送信リダイレクト無効
net.ipv4.conf.all.send_redirects=0
net.ipv4.conf.default.send_redirects=0
# IPv4ソースルート無効
net.ipv4.conf.all.accept_source_route=0
net.ipv4.conf.default.accept_source_route=0
# IPv6を無効
net.ipv6.conf.all.disable_ipv6 = 1
net.ipv6.conf.default.disable_ipv6 = 1
# mmap ASLR強化
vm.mmap_rnd_bits=32
vm.mmap_rnd_compat_bits=16
# シンボリック/ハードリンク保護
fs.protected_symlinks=1
fs.protected_hardlinks=1
# FIFO/通常ファイル保護
fs.protected_fifos=2
fs.protected_regular=2
設定内容の反映
sudo sysctl -p
カーネルの起動オプションに以下を追加
# カーネル起動時に適用するオプションを指定
# quiet : ブート時の出力を抑制
# slab_nomerge : スラブアロケータの統合機能を無効にする
# init_on_alloc=1 : メモリアロケーション時にゼロ初期化を行う(セキュリティ向上)
# init_on_free=1 : メモリ解放時にゼロ初期化を行う(セキュリティ向上)
# page_alloc.shuffle=1 : メモリアロケーションの乱数化により、予測不能性の向上
# ipv6.disable=1 : IPv6機能を無効化(環境に応じて必要な場合は解除)
GRUB_CMDLINE_LINUX_DEFAULT="quiet slab_nomerge init_on_alloc=1 init_on_free=1 page_alloc.shuffle=1 ipv6.disable=1"
設定内容の反映
sudo update-grub
Sambaの設定
Sambaのインストール
sudo dnf install samba -y
Sambaユーザの作成
sudo pdbedit -a '{ユーザ名}'
{ユーザ名}は好きなものに変更してください。
smb.confの設定
下記のように設定を変更する。
[global]
# Network settings
bind interfaces only = yes
hosts allow = 192.168.0.0/16
# Charset
unix charset = UTF-8
# Security settings
encrypt passwords = true
smb encrypt = required
restrict anonymous = 2
min protocol = SMB3
ntlm auth = no
security = user
invalid users = root daemon ftp network nobody ntp dnsmasq logd ubus syncthing
map to guest = Never
null passwords = no
passdb backend = tdbsam
smb ports = 445
server signing = mandatory
client signing = mandatory
guest ok = no
# Locking and connection settings
strict locking = yes
max connections = 2
deadtime = 10
enable core files = no
# NetBIOS and spool settings
disable netbios = yes
disable spoolss = yes
# Socket options
socket options = IPTOS_LOWDELAY TCP_NODELAY
# Printer settings
load printers = No
printcap name = /dev/null
printing = bsd
[SSD]
path = /mnt/ssd/
directory mask = 0755
create mask = 0644
writable = yes
pathは自由に設定してください。今回はポータブルSSDを利用するため、マウントポイント/mnt/ssd/
を設定しています。
Sambaサービスを有効化
sudo systemctl enable smb
USBポートのパススルー設定
左側のメニューのHardware
を選択し、左上のAdd
をクリックし、USB Device
を選択します。
ポータブルSSDを挿入しているUSB Portを選択してAdd
を押下します。
インストール時に使用したCD/DVD Drive
をRemove
しておきます。
マウントポイントの作成
下記のコマンドを実行して、ssd
ディレクトリを作成します。
sudo mkdir /mnt/ssd/
sudo mount -t exfat /dev/sdb1 /mnt/ssd
Windowsでも外した際に中身を確認できるようにするため、exfatでフォーマットしています。
自動マウント
UUIDを知る必要があるため、下記のコマンドでマウントしたいUUIDを調べる
$ sudo blkid
/dev/sdb1: UUID="0E94-3399" BLOCK_SIZE="512" TYPE="exfat" PARTUUID="d3582af9-01"
/dev/sda2: UUID="e56c361d-1936-49b8-9220-fa9fe03b9121" BLOCK_SIZE="4096" TYPE="ext4" PARTUUID="e7d09a8d-36ff-4d57-acf2-bbf67c9c4c31"
/dev/sda1: UUID="E356-4AEF" BLOCK_SIZE="512" TYPE="vfat" PARTUUID="195af5f4-d99e-454a-9ebb-2e1b4a21ae45"
再起動後に自動的にマウントするために、fstabを編集する。
UUID=0E94-3399 /mnt/ssd exfat defaults,uid={ユーザ名},gid={ユーザ名},context="system_u:object_r:samba_share_t:s0" umask=0000 0 0
{ユーザ名}は使用しているものを設定してください
SELinuxの設定
/mnt/ssd
をSamba共有できるようにSELinuxのルールを追加
sudo semanage fcontext -a -t samba_share_t "/mnt/ssd(/.*)?"
Syncthingの設定
Syncthingをインストールする。
sudo dnf install syncthing -y
設定ファイルの変更
SyncthingのWEB GUIのアドレスを変更する。
- <address>127.0.0.1:8384</address>
+ <address>{IPアドレス}</address>
{IPアドレス}は自由に設定してください
Syncthingの自動起動を設定する。
sudo systemctl enable syncthing@{ユーザ名}.service
sudo systemctl start syncthing@{ユーザ名}.service
{ユーザ名}は使用しているものを設定してください
Syncthingを設定
http://{IPアドレス}:8384/
にアクセスし、初期設定を行う。
最後に
私はスマホではSyncthingを使ってファイル共有し、PCではSambaを使ってファイル共有しています。どちらも快適に使えているので、ぜひ試してみてください。