This tutorial provides a comprehensive, beginner-friendly guide to setting up a CentOS VPS, covering initial server configuration, software installation, and basic security measures.
centos
Large
VPS
3
vCPU
12 GB
Memory
120 GB
NVMe Disk
6144 GB
Traffic
29.90€
/month
* Up to 6 vCPU, 36GB RAM, 360GB NVMe Disk Space and 1Gbit/s Network Speed
#### Prerequisites
Before you begin, ensure you have:
- A CentOS VPS (This guide is tested with CentOS 8)
- A user account with sudo privileges
- Basic familiarity with the command line
#### Step 1: Connect to Your VPS
First, connect to your VPS using SSH:
```bash
ssh your_username@your_server_ip
```
Replace `your_username` with your actual username and `your_server_ip` with your server's IP address.
#### Step 2: Update Your System
Before installing any software, ensure your system is up-to-date:
```bash
sudo dnf update -y
```
This command updates all installed packages to their latest versions.
#### Step 3: Set the Hostname
Set a hostname for your server for easier identification:
```bash
sudo hostnamectl set-hostname your_hostname
```
Replace `your_hostname` with your desired hostname.
#### Step 4: Create a New User
For security reasons, it's best not to use the root account for everyday tasks. Create a new user:
```bash
sudo adduser new_username
```
Set a password for the new user:
```bash
sudo passwd new_username
```
Grant the new user sudo privileges:
```bash
sudo usermod -aG wheel new_username
```
Replace `new_username` with your desired username.
#### Step 5: Configure SSH Access
For added security, you can disable root login and change the default SSH port:
Open the SSH configuration file:
```bash
sudo nano /etc/ssh/sshd_config
```
Find and modify the following lines:
```
#Port 22
#PermitRootLogin yes
```
Uncomment and change them to:
```
Port 2222
PermitRootLogin no
```
Save and exit the file. Restart SSH to apply the changes:
```bash
sudo systemctl restart sshd
```
**Note:** Ensure you have allowed the new port in your firewall settings.
#### Step 6: Configure the Firewall
CentOS uses `firewalld` for firewall management. Start and enable `firewalld`:
```bash
sudo systemctl start firewalld
sudo systemctl enable firewalld
```
Allow SSH traffic on the new port:
```bash
sudo firewall-cmd --permanent --add-port=2222/tcp
sudo firewall-cmd --reload
```
Allow HTTP and HTTPS traffic if you plan to host a web server:
```bash
sudo firewall-cmd --permanent --add-service=http
sudo firewall-cmd --permanent --add-service=https
sudo firewall-cmd --reload
```
#### Step 7: Install Essential Software
Depending on your needs, you may want to install some essential software packages. Here are a few examples:
- **Nano text editor:**
```bash
sudo dnf install nano -y
```
- **Git version control:**
```bash
sudo dnf install git -y
```
- **Nginx web server:**
```bash
sudo dnf install nginx -y
sudo systemctl start nginx
sudo systemctl enable nginx
```
#### Step 8: Secure Your Server
Security is crucial for any server. Here are a few basic steps:
- **Install Fail2Ban:**
Fail2Ban helps protect your server from brute-force attacks.
```bash
sudo dnf install epel-release -y
sudo dnf install fail2ban -y
sudo systemctl start fail2ban
sudo systemctl enable fail2ban
```
- **Set up automatic updates:**
Keeping your system updated is vital for security.
```bash
sudo dnf install dnf-automatic -y
sudo systemctl enable --now dnf-automatic.timer
```
#### Step 9: Monitor Your Server
Monitoring your server helps you ensure it runs smoothly and can alert you to potential issues. Install and configure basic monitoring tools:
- **Install htop for system monitoring:**
```bash
sudo dnf install htop -y
```
- **Install and configure logwatch:**
Logwatch provides detailed reports on your server's logs.
```bash
sudo dnf install logwatch -y
sudo nano /etc/cron.daily/0logwatch
```
Edit the file to ensure Logwatch sends daily email reports.
#### Conclusion
You have successfully set up your CentOS VPS, installed essential software, and configured basic security measures. Regularly monitor your server and keep it updated to ensure optimal performance and security.
**Additional Resources:**
- **CentOS Documentation:** [https://www.centos.org/docs/](https://www.centos.org/docs/)
- **DNF Documentation:** [https://dnf.readthedocs.io/en/latest/](https://dnf.readthedocs.io/en/latest/)