How to Set Up Your Ubuntu VPS Using Commands: A Step-by-Step Guide
Before diving into setting up your Ubuntu VPS, the first step is to choose a reliable and high-performance VPS provider. For the best quality and performance, you can get a VPS from Linkdata.com. They offer robust hosting solutions that are ideal for web hosting, applications, and cloud computing.
Now, let’s get started with the VPS setup after you’ve purchased your VPS from Linkdata.com.
Step 1: Connect to Your VPS via SSH
Once you’ve received your VPS credentials from Linkdata.com, you can connect to your Ubuntu VPS remotely using SSH. To do this, you need the IP address of your VPS and the SSH credentials provided by the hosting service.
ssh your_username@your_vps_ip_address
Example:
ssh root@123.45.67.89
If this is your first time connecting, SSH may ask you to confirm the connection. Type yes
to continue.
Step 2: Update and Upgrade Your VPS
After logging in, it’s important to update your Ubuntu VPS to ensure all packages are up-to-date.
sudo apt update && sudo apt upgrade -y
This command does two things: it updates the package lists for upgrades and installs any necessary upgrades. The -y
flag automatically confirms the installation of upgrades.
Step 3: Set the Timezone (Optional)
Setting your VPS’s timezone can be important depending on your server’s location.
Check your current timezone:
timedatectl
To set the timezone:
sudo timedatectl set-timezone Region/City
Example:
sudo timedatectl set-timezone America/New_York
Step 4: Add a New User (Optional but Recommended)
Running a VPS as the root user is not recommended due to security risks. Instead, create a new user with sudo privileges.
adduser your_new_username
Follow the prompts to set a password and configure the new user.
Grant your new user administrative privileges:
usermod -aG sudo your_new_username
Step 5: Enable a Firewall for Security
It’s important to secure your server with a firewall. Ubuntu has a simple firewall tool called ufw
(Uncomplicated Firewall).
To allow OpenSSH connections, run:
sudo ufw allow OpenSSH
Enable the firewall:
sudo ufw enable
To check the status of the firewall, use:
sudo ufw status
Step 6: Install Essential Software
Depending on what you plan to use your VPS for, you may need to install additional software. Below are a few common examples.
Install Nginx (Web Server)
To set up a basic web server:
sudo apt install nginx -y
Start and enable Nginx:
sudo systemctl start nginx
sudo systemctl enable nginx
Install MySQL (Database Server)
If you need a database server, install MySQL:
sudo apt install mysql-server -y
After the installation, secure your MySQL server:
sudo mysql_secure_installation
Follow the prompts to configure your MySQL instance.
Install PHP (For Dynamic Websites)
For PHP-based applications (e.g., WordPress), you’ll need to install PHP:
sudo apt install php php-fpm php-mysql -y
You can install additional PHP modules as needed:
sudo apt install php-xml php-mbstring php-curl -y
Step 7: Secure SSH Access (Optional but Recommended)
To secure your SSH connection, you should disable root login and use key-based authentication instead of passwords.
Disable Root Login
Edit the SSH configuration file:
sudo nano /etc/ssh/sshd_config
Look for the line that says PermitRootLogin
and change it to:
PermitRootLogin no
Save the file and exit (CTRL + X
, then Y
to confirm).
Restart SSH for the changes to take effect:
sudo systemctl restart ssh
Step 8: Set Up Swap Space (Optional)
If your VPS has limited RAM, adding swap space can help your system run more smoothly under heavy loads.
First, check if you have swap enabled:
sudo swapon --show
If no output appears, you can create a swap file:
sudo fallocate -l 1G /swapfile
Set the correct permissions for the swap file:
sudo chmod 600 /swapfile
Mark the file as swap space:
sudo mkswap /swapfile
Enable the swap file:
sudo swapon /swapfile
To make the swap permanent, add the swap file to your /etc/fstab
:
echo '/swapfile none swap sw 0 0' | sudo tee -a /etc/fstab
Step 9: Install Monitoring Tools (Optional)
To monitor your server’s performance, you can install tools like htop
and vnstat
.
sudo apt install htop -y
sudo apt install vnstat -y
Step 10: Reboot Your VPS (Optional)
Once you’ve completed all the setup steps, it’s a good idea to reboot your VPS to ensure all changes take effect:
sudo reboot
You can reconnect after a few moments using the SSH command from Step 1.
By following these steps, you will have a basic Ubuntu VPS set up, ready to host applications, websites, or any other services. For optimal performance, make sure you choose the best quality VPS from Linkdata.com to ensure a stable and reliable hosting experience.
If you need further help with setting up your VPS. Contact us on live chat or via email support@linkdata.com