First steps after buying a VPS

Congratulations on purchasing your new Virtual Private Server (VPS)! This powerful tool offers you a dedicated slice of server resources, providing flexibility and control over your web hosting environment. Whether you’re planning to host websites, run applications, or develop software, a VPS can handle a variety of tasks with ease. However, if you’re wondering “I bought a VPS, now what?”, you’re not alone. The initial setup and configuration can seem daunting, especially if you’re new to server management.

This article is part of Rackset’s Server Administration guides — browse the rest of the category for more in-depth tutorials on this topic.

In this article, we will guide you through the first essential steps after provisioning your VPS. We’ll cover everything from securing your server and setting up SSH access to installing necessary software and configuring your firewall. By the end of this guide, you’ll have a solid foundation to start leveraging your VPS for your specific needs. Let’s dive into the process and turn your newly acquired server into a robust, secure, and efficient environment tailored to your requirements.

Update Your VPS Packages

Once your VPS is provisioned, the first critical step is to update your system packages. Keeping your server software up-to-date ensures you have the latest security patches and features, which is essential for maintaining a secure and efficient environment.

Connect to Your VPS

To begin updating your VPS, you’ll need to connect to it via SSH. Use the following command in your terminal, replacing username and server_ip with your actual VPS username and IP address:

ssh username@server_ip

Update Package Lists

Once connected, the next step is to update the package lists. This ensures your package manager is aware of the latest versions available. Use the appropriate command based on your Linux distribution:

  • Ubuntu/Debian:
    sudo apt update
  • CentOS/RHEL:
    sudo yum check-update

Upgrade Installed Packages

After updating the package lists, proceed to upgrade the installed packages to their latest versions. This can be done with the following commands:

  • Ubuntu/Debian:
    sudo apt upgrade
  • CentOS/RHEL:
    sudo yum update

Reboot If Necessary

Some updates, particularly those involving the kernel or critical system components, may require a reboot to take full effect. If you’re prompted to reboot, you can do so with:

sudo reboot

Completing these steps ensures your VPS is running the latest software, providing a stable and secure foundation for your applications and services.

Create a Non-Root Sudo User

First steps after provisioning a VPS

After provisioning your VPS, it’s crucial to enhance its security by creating a non-root user with sudo privileges. This minimizes the risk of accidental system-wide changes and protects your server from unauthorized access. Follow these steps to create and configure a non-root sudo user:

Step 1: Log in to Your VPS

First, access your VPS using SSH. Open your terminal and execute the following command, replacing your_ip_address with your server’s IP:

ssh root@your_ip_address

Step 2: Add a New User

Once logged in, create a new user account by running the command below. Replace newuser with your desired username:

For projects that need guaranteed resources and full root control, a VPS is the right step up from shared hosting. With VPS hosting you get dedicated CPU/RAM, NVMe storage, a dedicated IP and high uptime, deployed in minutes.

adduser newuser

You will be prompted to set a password and fill in some optional information. Ensure you choose a strong password.

Step 3: Grant Sudo Privileges

To allow the new user to execute commands with superuser privileges, add them to the sudo group:

usermod -aG sudo newuser

Step 4: Test the New User

To ensure the new user and sudo privileges are correctly set up, switch to the new user account:

su - newuser

Now, test the sudo access by running a command that requires elevated privileges:

sudo apt update

If prompted, enter the password for newuser. If the command executes successfully, your setup is complete.

Conclusion

By creating a non-root sudo user, you’ve taken an essential step towards securing your VPS. This practice limits the potential damage from accidental commands and enhances your server’s overall security posture.

Set Up SSH Keys and Harden SSH

After provisioning your VPS, securing access to your server is a critical step. Using SSH keys instead of passwords enhances security by adding an extra layer of protection. Here’s how you can set up SSH keys and harden your SSH configuration.

Generate SSH Keys

  1. Open your terminal (Linux/Mac) or use a tool like PuTTYgen (Windows).
  2. Generate a new SSH key pair by running the following command:
    ssh-keygen -t rsa -b 4096 -C "your_email@example.com"
  3. Follow the prompts to save the key pair. By default, they are saved in ~/.ssh/id_rsa and ~/.ssh/id_rsa.pub.

Copy the Public Key to Your VPS

  • Use ssh-copy-id to transfer your public key to the VPS:
    ssh-copy-id user@your_vps_ip
  • Alternatively, manually copy the contents of id_rsa.pub to the ~/.ssh/authorized_keys file on your VPS.

Harden SSH Configuration

  1. Edit the SSH configuration file on your VPS:
    sudo nano /etc/ssh/sshd_config
  2. Change the default SSH port to a non-standard port by modifying:
    #Port 22
    Port 2222
  3. Disable root login by setting:
    PermitRootLogin no
  4. Allow only SSH key authentication:
    PasswordAuthentication no
  5. Restart the SSH service to apply changes:
    sudo systemctl restart sshd

By following these steps, you significantly improve the security of your VPS, protecting it from unauthorized access.

Configure a Firewall

Setting up your new server

After provisioning your VPS, configuring a firewall is a critical step to secure your server from unauthorized access and potential threats. A firewall acts as a barrier between your server and the internet, allowing you to control the incoming and outgoing traffic based on predetermined security rules. Here’s how to get started:

1. Install a Firewall Application

Most VPS servers support popular firewall applications like UFW (Uncomplicated Firewall) for Ubuntu or Firewalld for CentOS. To install UFW on Ubuntu, use the following command:

sudo apt-get install ufw

For CentOS, you can install Firewalld with:

For heavy workloads and maximum performance, a dedicated bare-metal server gives you an entire physical machine. Rackset’s dedicated server deliver full hardware, root access and configurable port speeds for the most demanding sites and apps.

sudo yum install firewalld

2. Enable the Firewall

Once installed, the firewall needs to be enabled to start protecting your VPS. For UFW, execute:

sudo ufw enable

For Firewalld, use:

sudo systemctl start firewalld

3. Configure Firewall Rules

Setting up rules is essential to define which traffic should be allowed or blocked. Here’s how to allow SSH, HTTP, and HTTPS traffic:

  • UFW:
    • Allow SSH: sudo ufw allow ssh
    • Allow HTTP: sudo ufw allow http
    • Allow HTTPS: sudo ufw allow https
  • Firewalld:
    • Allow SSH: sudo firewall-cmd --permanent --add-service=ssh
    • Allow HTTP: sudo firewall-cmd --permanent --add-service=http
    • Allow HTTPS: sudo firewall-cmd --permanent --add-service=https
    • Reload to apply changes: sudo firewall-cmd --reload

4. Verify Firewall Status

It’s important to verify that your firewall is active and the rules are applied correctly:

  • For UFW, check the status with: sudo ufw status
  • For Firewalld, use: sudo firewall-cmd --state

By configuring a firewall, you establish a fundamental layer of security for your VPS, safeguarding it against external threats.

Add Swap Space

After purchasing and provisioning your VPS, adding swap space can enhance the performance of your server, especially if you’re running applications with high memory demands. Swap space acts as an overflow area for your system’s RAM, allowing it to handle more processes than physical memory alone can manage. Here’s how you can add swap space to your VPS.

Check Current Swap Space

Before adding swap space, it’s crucial to determine if your VPS already has some configured. You can check the current swap space using the following command:

sudo swapon --show

If no output is returned, it means there is no swap space currently configured.

Create a Swap File

  1. Decide the size of the swap file you need. A common practice is to set swap space to be equal to or double the amount of RAM.
  2. Create a swap file with the fallocate command. For example, to create a 2GB swap file, use:
sudo fallocate -l 2G /swapfile

Secure the Swap File

Set the correct permissions to ensure that only the root user can read and write to this file:

sudo chmod 600 /swapfile

Set Up the Swap Area

Convert the file into swap space using the following command:

sudo mkswap /swapfile

Enable the Swap File

Activate the swap file so that the system can start using it immediately:

If you need this service, Rackset’s team provides professional cloud server with full support so you can rely on the quality and get set up quickly.

sudo swapon /swapfile

Make the Swap File Permanent

To ensure the swap file is used after a system reboot, add it to /etc/fstab:

echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab

Verify the Swap Space

Finally, verify that the swap space is active:

sudo swapon --show

You should see the swap file listed, confirming that it is active and ready for use.

Set Timezone and Hostname

Once you have provisioned your VPS, one of the first steps to take is setting the correct timezone and hostname. These configurations are crucial for system logs, scheduled tasks, and network identification. Rackset makes it straightforward to manage these settings through its user-friendly control panel.

Setting the Timezone

The correct timezone ensures that your system logs and scheduled tasks are accurately timed. Follow these steps to set the timezone on your VPS:

  1. Log into your VPS via SSH. You can use a terminal or an SSH client like PuTTY.
  2. To list all available timezones, execute the following command:
    timedatectl list-timezones
  3. Choose the appropriate timezone for your location.
  4. Set the timezone by running:
    sudo timedatectl set-timezone Your_Timezone

    Replace Your_Timezone with the desired timezone, such as America/New_York.

  5. Verify the change by using:
    timedatectl

Rackset’s VPS hosting supports all standard timezones, ensuring your server is perfectly aligned with your local time.

Configuring the Hostname

The hostname is a label that identifies your server on the network. Here’s how to configure it:

  1. Check your current hostname by entering:
    hostname
  2. To change the hostname, use the command:
    sudo hostnamectl set-hostname Your_Hostname

    Replace Your_Hostname with your desired server name.

  3. Update the /etc/hosts file with the new hostname. Open the file in a text editor:
    sudo nano /etc/hosts
  4. Replace any occurrence of the old hostname with the new one and save the file.
  5. Verify the hostname change:
    hostnamectl

With Rackset’s intuitive control panel, managing your server’s hostname is simplified, allowing easy integration with your existing network infrastructure.

Need expert help from Rackset?

Want this done fast, professionally and hassle-free? Rackset’s experienced team and full support are here to help you get the best result.

Buy VPS hosting

Conclusion

Setting up your VPS may initially seem daunting, but by following these first eight steps, you can establish a secure and efficient server environment tailored to your needs. From securing your server and updating your system to configuring firewalls and backups, each step is crucial in ensuring your VPS runs smoothly and securely. Remember, the key to a successful VPS setup lies in continuous monitoring and regular maintenance, keeping you prepared for any challenges that may arise.

As you continue to build and expand your online presence, Rackset is here to support you with robust hosting solutions and expert guidance every step of the way. Whether you’re a seasoned developer or a beginner, our services are designed to meet your needs and help your projects thrive.

Frequently Asked Questions

What is the first thing I should do after buying a VPS?

The first thing you should do after buying a VPS is to log in using SSH. Securing your server by updating the default password and configuring basic firewall rules is essential to protect your VPS from unauthorized access.

How do I secure my VPS?

To secure your VPS, start by changing the default SSH port and disabling root login. Additionally, install a firewall like UFW or iptables to manage incoming and outgoing traffic effectively.

Why is updating the server software important?

Updating your server software is crucial because it ensures that your VPS has the latest security patches and performance improvements. Regular updates help protect your server from vulnerabilities and potential exploits.

How can I set up a domain on my VPS?

To set up a domain on your VPS, you need to configure DNS settings to point your domain to your VPS’s IP address. Then, set up a web server like Apache or Nginx to handle incoming web traffic for your domain.

What is the role of a control panel in managing a VPS?

A control panel simplifies the management of your VPS by providing a user-friendly interface for tasks like managing domains, databases, and email accounts. Popular control panels like cPanel or Plesk can help streamline server administration and website management.

Leave a Reply

Your email address will not be published. Required fields are marked *

Count: 74 - Average: 4.7

Rating Submitted.