はじめに
何回も調べるのがめんどいのでメモ程度にまとめておく
初期設定
suコマンドでrootになれるように
pw groupmod wheel -m hoge
hogeのところを自分のユーザー名にする
rootのシェルをtcshに変更
chsh -s /bin/tcsh
vimインストール
pkg update
pkg install -y vim
初回だと
The package management tool is not yet installed on your system.
Do you want to fetch and install it now? [y/N]:
と聞かれるので y でインストールしておく
Ports Collectionのインストール
gitを用いてports collectionをインストールするためにgitをインストールする。
pkg install -y git
ports collectionのインストール
git clone https://git.FreeBSD.org/ports.git /usr/ports
/usr/portsを更新
git -C /usr/ports pull
portsのアップグレード
portupgradeを使う
cd /usr/ports/ports-mgmt/portupgrade
make install clean
NTPの設定
適当なntpサーバーを追加
/etc/ntp.conf 追記
server ntp.nict.jp
server ntp1.jst.mfeed.ad.jp
server ntp2.jst.mfeed.ad.jp
server ntp3.jst.mfeed.ad.jp
起動時にntpが自動できどうするように
/etc/rc.conf 追記
ntpd_enable="YES"
ntpd_sync_on_start="YES"
ファイアウォール設定
ipfwを使う このサイトを参考にさせて頂いた
ssh(22), dns(53)を開けとく
/usr/local/etc/ipfw.rules 新規作成
#! /bin/sh
#
IPF="ipfw -q add"
ipfw -q -f flush
#loopback
$IPF 10 allow all from any to any via lo0
$IPF 20 deny all from any to 127.0.0.0/8
$IPF 30 deny all from 127.0.0.0/8 to any
$IPF 40 deny tcp from any to any frag
# statefull
$IPF 50 check-state
$IPF 60 allow tcp from any to any established
$IPF 70 allow all from any to any out keep-state
$IPF 80 allow icmp from any to any
$IPF 100 allow tcp from any to any 22 in
$IPF 110 allow tcp from any to any 22 out
$IPF 120 allow udp from any to any 53 in
$IPF 125 allow tcp from any to any 53 in
$IPF 130 allow udp from any to any 53 out
$IPF 135 allow tcp from any to any 53 out
起動時にipfwを有効化
/etc/rc.conf 追記
firewall_enable="YES"
firewall_logging="YES"
firewall_script="/usr/local/etc/ipfw.rules"
SSHの設定
既存のコンフィグファイルがあるからバックアップ
mv /etc/ssh/sshd_config /etc/ssh/sshd_config.org
/etc/ssh/sshd_config 新規作成
Port 22
PermitRootLogin no
PubkeyAuthentication yes
AuthorizedKeysFile .ssh/authorized_keys
PasswordAuthentication no
PermitEmptyPasswords no
KbdInteractiveAuthentication no
UseDNS no
Subsystem sftp /usr/libexec/sftp-server
以下、鍵を作成したい一般ユーザーで実行
ssh-keygen -t ed25519
cat ~/.ssh/id_ed25519.pub >> ~/.ssh/authorized_keys
chmod 600 ~/.ssh/authorized_keys
chmod 700 ~/.ssh/
作成した秘密鍵はクライアント端末によしなに