# 安裝一台新的 Debian 指南

# 新增管理 user 帳號

建立一個用來管理 server 的 admin 帳號,因為一般不會使用 root 帳號來管理 server 。

adduser [username]

# 更新 Debian

apt-get update; apt-get upgrade

# 安裝一些好用的 util

apt-get install htop vim zsh ntpdate git tmpreaper ncdu

# 安裝 Oh My Zsh

Oh My Zsh 是強化 zsh 的輔助程式,有主題、有外掛,增加使用 shell 的效率。

sh -c "$(curl -fsSL https://raw.github.com/ohmyzsh/ohmyzsh/master/tools/install.sh)"

可以透過 .zshrc 設定檔設定你的 zsh

這邊是院長用的設定,有分為 一般 user (opens new window)root user (opens new window)

curl https://gist.githubusercontent.com/onlinemad/e0444bc8dc50b6fea810/raw/662a2c3655c8cb524baff0148be48db092060143/root.zshrc > .zshrc

# 調整 locales

我會調整成 zh_TW.UTF8

dpkg-reconfigure locales

# 增加 user 到 sudo 群組

vigr

sudo 這個群組後面加上 username

sudo:x:27:[username]

# 編輯 sudo 設定檔

vi /etc/sudoers

%sudo 這邊的設定取消註解

# Allow members of group sudo to execute any command
%sudo   ALL=(ALL:ALL) ALL

# 設定時區

選擇 Asia → Taiwan

tzselect
dpkg-reconfigure tzdata

# 對時

ntpdate -u pool.ntp.org

# 設定 cronjob 定時對時

每天對一次就可以了

crontab -e
0	0	*	*	*	ntpdate -u pool.ntp.org

# 關閉 SSH root 登入

vi /etc/ssh/sshd_config

設定改為 no

PermitRootLogin no

重啟 ssh server

service sshd restart

# 設定 tmpreaper

tmpreaper 是可以定時刪除 /tmp 下面檔案的輔助程式,院長有好幾次翻車都是因為 /tmp 滿了。

vi /etc/tmpreaper.conf

SHOWWARNING 這個設定註解起來,這樣就會開始運作了,預設是清除超過 7 天的檔案。

# SHOWWARNING=true

# 開啟 cron log

vi /etc/rsyslog.conf

cron.* 這段的註解取消

cron.* 

重啟 rsyslog

service rsyslog restart

# 除不需要的 service

netstat -ln 看有哪些 port 是在 LISTEN 狀態,不需要的就把這些 service 關閉或是移除,院長這邊會都關到只剩下 SSH 的 port 22 。

# Port 25

Port 25 是 mail service 在用的,沒用到寄信功能就關掉吧

apt-get remove exim4 exim4-base exim4-config exim4-daemon-light

# Port 111

Port 111 是 NFS service 在用的,沒用到 NFS 檔案分享的功能就關掉吧

systemctl stop rpcbind
systemctl disable rpcbind
systemctl mask rpcbind
systemctl stop rpcbind.socket
systemctl disable rpcbind.socket

# 參考資料

Last Updated: 2022-2-3 16:43:56
贊助商連結
    贊助商連結
    (adsbygoogle = window.adsbygoogle || []).push({});