A few weeks ago, I was looking for a way to streamline Debian VPS setup. I wanted to ‘automate’ the configuration of a new Debian VPS or Virtual private server, using a method that could be replicated across different computers. By referencing several guides, and generous assistance from AI chat tools, I came up with a script. This guide provides a step-by-step explanation of this script that automates the setup of a Debian VPS.
Summary (Hindi): यह गाइड एक स्क्रिप्ट की कदम-दर-कदम व्याख्या प्रदान करती है जो डेबियन VPS की सेटअप को स्वचालित करती है। स्क्रिप्ट सिस्टम को अपडेट करती है, उपकरण स्थापित करती है, फ़ायरवॉल को कॉन्फ़िगर करती है, और SSH सर्वर की सेटअप करती है। यह एक VPS पर डेबियन स्थापना और कमांड लाइन उपयोग का धारणा करती है।
Introduction:Streamline Debian VPS Setup with a Custom Script
Setting up a Debian Virtual Private Server (VPS) can be a daunting task, especially for beginners. This guide simplifies the process by providing a script that automates the setup. This script assumes that you have a Debian installation on your VPS and are comfortable using the command line.
Creating custom script for Debian Linux for new VPS install
Debian Linux is one of the most popular and widely used operating systems for virtual private servers (VPS). Whether you are a beginner or an experienced user, setting up a new VPS with Debian Linux can be a daunting task. The default installation of Debian Linux provides a solid foundation, but it may not always meet the specific needs and requirements of every user. This is where custom scripts come into play.
The need to set up a custom script
Setting up a custom script for your Debian Linux VPS install is crucial to optimize your server’s performance and ensure it meets your specific requirements. By tailoring a script to your needs, you can automate repetitive tasks, streamline processes, and enhance security measures.
Building blocks of the script for Debian VPS setup
Once the Debian operating system has been installed on a new VPS, it is crucial to ensure that the system is up to date and secure. The first step for debian VPS setup involves performing essential upgrades to patch any vulnerabilities and keep the system running smoothly. Additionally, the installation of essential tools such as curl, ufw, and rclone is necessary to enhance the functionality and versatility of the server.
What does the script do?
Step1: The script begins by updating the .bashrc file for the user with several useful aliases.
Step2: The script then updates the Debian installation.
Step3: The script installs several useful tools: curl, wget, rclone, neofetch, ufw and fortune.
Step4: The script then configures the Uncomplicated Firewall (UFW).
Step5: The script updates the SSH server configuration.
Note: You can access the below script by visiting this page.
Bash Script for customizing Debian VPS Setup
Notes:
- This script assumes a Debian installation on a VPS
- Assumption: User has logged on to VPS via SSH and is familiar with command-line usage.
#!/bin/bash
# Step1: Update .bashrc for user with aliases
cat << EOF >> /home/user/.bashrc
alias dl='cd ~/Downloads'
alias doc='cd ~/Documents'
alias egrep='egrep --color=auto'
alias fgrep='fgrep --color=auto'
alias ghar='cd ~'
alias grep='grep --color=auto'
alias apti='sudo apt-get -y install'
alias aptu='sudo apt-get update && sudo apt-get -y upgrade'
alias ll='ls -alFh'
alias ls='ls --color=auto'
alias ping='ping -c6'
alias ping6='ping6 -c6'
alias rsync='ionice -c2 -n7 rsync'
EOF
# Update the source for your_username
source /home/user/.bashrc
# Step2: Update the Debian installation
sudo aptu
# Step3: Install curl, wget, rclone, ufw
sudo apti curl wget rclone neofetch ufw fortune
# Step4: Configure ufw
sudo ufw default deny incoming
sudo ufw default allow outgoing
sudo ufw enable
sudo ufw allow 80/tcp,443/tcp,22,21,53/udp
#sudo ufw allow custom port (optional)
#sudo ufw allow xxxx
sudo sed -i 's/IPV6=no/IPV6=yes/g' /etc/default/ufw
sudo ufw reload
# Step5: Update /etc/ssh/sshd_config
sudo sed -i 's/#PermitRootLogin prohibit-password/PermitRootLogin prohibit-password/g' /etc/ssh/sshd_config
sudo echo 'ClientAliveInterval 20' >> /etc/ssh/sshd_config
sudo echo 'ClientAliveCountMax 30' >> /etc/ssh/sshd_config
sudo sed -i 's/#X11Forwarding yes/X11Forwarding no/g' /etc/ssh/sshd_config
sudo echo 'Port xxxx' >> /etc/ssh/sshd_config
sudo systemctl restart sshd
Explanation of each step in the above script
Step1: Update .bashrc for user with aliases
This command appends the following lines to the .bashrc file in the user’s home directory.
Step2: Update the Debian installation
This line updates the list of available packages and upgrades the installed packages.
Step3: Install curl, wget, rclone, ufw
This line installs the curl, wget, rclone, neofetch, ufw and fortune packages.
Step4: Configure ufw
This line sets the default policy for incoming connections to deny.
Step5: Update /etc/ssh/sshd_config
This line enables password-based authentication for the root user.
Key Takeaways
- Automating the setup process can save time and reduce errors.
- Aliases can make common commands easier to type.
- Regular system updates and firewall configuration are essential for security.
- Changing the default SSH port can enhance security.
Conclusion
This script provides a streamlined way for a Debian VPS setup. It automates the process of updating the system, installing tools, configuring the firewall, and setting up the SSH server.
References
This post about Debian VPS setup assumes a basic to intermediate level of familiarity with Linux and Open Source tools and command line.