/Linux-Server-Config

🐧 Set up your new Linux server on Debian

Primary LanguageShell

Linux-Server-Config

Set up your new Linux server on Debian with essential instructions and scripts.

Install Essential Tools

Update the package list and install essential tools

apt update && \
apt install -y vim curl git zsh sudo locales tzdata bat

Add a New User

Note: Replace $USERNAME with your desired username.

useradd -m $USERNAME
passwd $USERNAME
usermod -aG sudo $USERNAME

Now Change to New User

Switch to the newly created user

su $USERNAME

Modify sshd Config

Note: Run ssh-copy-id before making these changes to ensure passwordless login.

sudo sh -c 'echo "PermitRootLogin no\nPasswordAuthentication no\nClientAliveInterval 30" >> /etc/ssh/sshd_config.d/custom.conf' && \
sudo systemctl restart sshd

Install Oh-My-Zsh and Plugins

Install Oh-My-Zsh

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

Clone and install Oh-My-Zsh plugins

git clone https://github.com/zsh-users/zsh-autosuggestions $ZSH_CUSTOM/plugins/zsh-autosuggestions && \
git clone https://github.com/zsh-users/zsh-syntax-highlighting.git $ZSH_CUSTOM/plugins/zsh-syntax-highlighting && \
git clone https://github.com/MichaelAquilina/zsh-you-should-use.git $ZSH_CUSTOM/plugins/zsh-you-should-use && \
sed -i 's/(git)/(git gitfast z sudo zsh-syntax-highlighting zsh-autosuggestions zsh-you-should-use docker)/g' ~/.zshrc && \
source ~/.zshrc

Create an alias for cat using batcat to enable syntax highlighting.

echo "alias cat='batcat -p --paging=never'" >> ~/.zshrc && \
source ~/.zshrc
# Optional (try the theme I modified)
mkdir -p "$(batcat --config-dir)/themes" && \
curl -o "$(batcat --config-dir)/themes"/Vim.tmTheme https://raw.githubusercontent.com/moesnow/Linux-Server-Config/main/Vim.tmTheme && \
batcat cache --build && \
echo "alias cat='batcat -p --paging=never --theme Vim'" >> ~/.zshrc && \
source ~/.zshrc

Change Locale and Localtime

Note: Replace zh_CN.UTF-8 with your desired locale, and replace Asia/Shanghai with your desired city/timezone if needed.

sudo sh -c 'echo "zh_CN.UTF-8 UTF-8" >> /etc/locale.gen' && \
sudo locale-gen && \
sudo update-locale LANG="zh_CN.UTF-8" && \
sudo ln -sf /usr/share/zoneinfo/Asia/Shanghai /etc/localtime

Set Zram

Install zram-tools and configure zramswap

sudo apt install -y zram-tools && \
sudo sh -c 'echo -e "\nALGO=zstd\nPERCENT=60" >> /etc/default/zramswap' && \
sudo systemctl reload zramswap.service

Install Speedtest

Install speedtest-cli to measure internet speed

curl -s https://packagecloud.io/install/repositories/ookla/speedtest-cli/script.deb.sh | sudo bash && \
sudo apt install -y speedtest