Debianサーバ標準初期設定メモ

226

久しぶりにdebianサーバを立てたので、初期設定の手順をメモしておきます

Root でログインしてリポジトリのアップデート、パッケージのアップグレード

apt-get update
apt-get upgrade

作業ユーザー作成

adduser newuser

エディタを vimに

update-alternatives --set editor /usr/bin/vim.basic

visualmodeを殺すため、~/.vimrc に下記を追加(root, 新ユーザーともに)

:syntax on
set mouse-=a

sshの最初の設定

vim /etc/ssh/sshd_config

変更点 PermitRootLogin no

systemctrl restart sshd

最低限必要なパッケージのインストール。debian12は rsyslogが入っていない!

apt-get install aptitude sudo fish zsh dnsutils telnet rsyslog

作業ユーザーをsudoに追加

visudo 
追加点       newuser     ALL=(ALL:ALL) NOPASSWD:ALL

以下に従ってフィルタを作成。v6も忘れずに。

iptables と netfilterを勉強し直す(ゼロからのfirewall構築)その1

sshd鍵のコピー
local側

scp ./localhost_rsa.pub user@newserver:~/.ssh/

server側

mkdir .ssh
chmod -c 700  .ssh
cd .ssh 
cat localhost_rsa.pub >> authorized_keys
chmod -c 600  authorized_keys
rm  localhost_rsa.pub

sshdの設定変更

sudo vi /etc/ssh/sshd.config

変更点

Port [newport]
PermitRootLogin no
Allowusers newuser1 newuser2
PubkeyAuthentication yes
AuthorizedKeysFile      .ssh/authorized_keys .ssh/authorized_keys2
PasswordAuthentication no
PermitEmptyPasswords no

追加点

Allowusers username
ChallengeResponseAuthentication no

Debianにはひどい罠があるのでこれも修正しないといけない

vi /etc/ssh/sshd_config.d/50-cloud-init.conf 
PasswordAuthentication no
systemctrl restart sshd

シェルの変更

chsh -s /usr/bin/fish

ほかサーバから必要なものコピー

scp -P [portnumber] ~/.config/fish/functions/fish_* [new server address]:/home/username/.config/fish/functions/  

DNSへの追加
マスタ側

 vi /etc/nsd/zone/domain.zone
あれこれ書き足す
nsd-control reload

スレーブ側

 nsd-control transfer && nsd-control write

swapの設定

dd if=/dev/zero of=/swapfile bs=1M count=1024 (1MBブロックで1024MB)
chmod 600 /swapfile  
mkswap /swapfile

vi /etc/fstab
追加   /swapfile       swap    swap    default 0       0
swapon -a

ここまでやったら寝ましょう。