Net2Secure: A Leading Data Center Service Provider in India
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹2,000 FREE Cloud Credits! Claim Now
Grab the Freedom Deal: ₹1,000 FREE Cloud Credits! Claim Now
+91 9953046498 sales@net2secure.com Support Login | Register

⮚ KB ⮚ How to Secure a Linux VPS Server: Ubuntu VPS Security...

How to Secure a Linux VPS Server: Ubuntu VPS Security Guide


A Linux VPS gives you more control than shared hosting, but that control also means you are responsible for securing the operating system, SSH access, exposed services, applications, databases and credentials that you manage. This guide explains how to secure a Linux VPS server safely, with practical steps for Ubuntu VPS users, developers and businesses.

Quick answer: To secure a Linux VPS, first make sure you have a backup and provider-console recovery method. Then create a non-root sudo user, configure SSH keys and test them in a second session, update the OS, enable automatic security updates, allow SSH through your firewall before enabling it, restrict SSH, protect public services with HTTPS, reduce unnecessary privileges, monitor logs and maintain tested backups. Never disable password or root SSH access until you have confirmed another working administrative login.

Linux VPS Security Checklist

Use this checklist as a practical starting point for Linux VPS security. The exact controls you need will depend on your applications, threat model, compliance requirements and hosting arrangement.

Security Area Recommended Action Priority
Recovery Confirm backups and provider-console or rescue access before changing SSH or firewall settings Critical
System Updates Install current security updates and configure automatic security patching Critical
SSH Use SSH keys and test a second administrative session before disabling password authentication Critical
Root Login Use a sudo-enabled administrative user and restrict direct root SSH access after testing High
Firewall Allow only required ports; permit SSH before enabling UFW Critical
Brute-Force Protection Consider Fail2ban or an equivalent authentication-abuse control High
Web Security Use HTTPS, supported TLS settings and secure certificate/private-key permissions High
Applications Patch runtimes, frameworks, CMS software, plugins and dependencies Critical
Databases Avoid exposing database ports publicly unless there is a justified and controlled requirement High
Privileges Run applications with dedicated unprivileged accounts High
Logging Review authentication, system and application logs and configure alerts where appropriate High
Backups Maintain separate, protected backups and test restoration Critical

Before You Harden Your Linux VPS: Protect Recovery Access First

The most dangerous server-hardening mistake is locking yourself out of the machine. Before changing SSH, firewall, PAM, network or authentication settings, confirm how you will recover access if a configuration is wrong.

  • Create or verify a recent backup or snapshot appropriate for your environment.
  • Confirm that the backup can actually be restored.
  • Know whether your hosting provider offers a web console, serial console, VNC console or rescue environment.
  • Keep your current SSH session connected while testing a new configuration.
  • Open a second terminal window and verify a new login before closing the original session.
  • Record the current SSH port and firewall state before changing either.
SSH lockout warning: Never disable password authentication, direct root login or an existing authentication method until you have successfully logged in through the replacement method. If you lose all SSH access, recovery may require your VPS provider's console or rescue system.

Update Ubuntu and Enable Automatic Security Updates

Keeping supported software patched is one of the most important parts of Ubuntu server hardening. Start by refreshing package information and installing available upgrades.

sudo apt update sudo apt upgrade

If the system reports that a reboot is required after kernel or other system updates, schedule the reboot appropriately for your workload.

test -f /var/run/reboot-required && cat /var/run/reboot-required

Enable automatic security updates

Ubuntu provides unattended-upgrades for automatic update management. Verify that the package is installed and configure it through the supported package interface.

sudo apt install unattended-upgrades sudo dpkg-reconfigure unattended-upgrades

Review its logs when troubleshooting automatic updates:

sudo less /var/log/unattended-upgrades/unattended-upgrades.log

Third-party repositories may require separate configuration and should not be assumed to receive automatic security updates simply because Ubuntu security updates are enabled.

Create a Non-Root Sudo User

Routine administration should generally be performed through an individual administrative account rather than by logging in directly as root. Replace adminuser with your preferred username.

sudo adduser adminuser sudo usermod -aG sudo adminuser

Verify the account and its groups:

id adminuser

Do not disable root SSH access yet. First configure and test SSH key authentication for the new account.

Secure SSH Access on Your Ubuntu VPS

Create an SSH key on your local computer

Run the following command on your own workstation, not on the VPS:

ssh-keygen -t ed25519

Protect the private key with a strong passphrase where practical. The private key should remain on your trusted client device.

Install the public key for your new user

Where ssh-copy-id is available:

ssh-copy-id adminuser@SERVER_IP

Then test a completely new SSH session:

ssh adminuser@SERVER_IP

Confirm that sudo works:

sudo -v sudo whoami

The second command should return root after successful sudo authentication.

Do not proceed until this new SSH login works. Keep the original SSH session open while testing every authentication change.

Use an SSH configuration drop-in

Ubuntu/OpenSSH installations can support configuration fragments under /etc/ssh/sshd_config.d/. Before making changes, inspect your existing configuration because cloud images, management systems and automation tools may already provide SSH settings.

sudo grep -RniE '^(PasswordAuthentication|PermitRootLogin|PubkeyAuthentication|KbdInteractiveAuthentication)' \ /etc/ssh/sshd_config /etc/ssh/sshd_config.d/ 2>/dev/null

After confirming that public-key authentication works, a typical hardening drop-in may include:

sudo nano /etc/ssh/sshd_config.d/99-hardening.conf

Add:

PubkeyAuthentication yes PermitRootLogin no PasswordAuthentication no

Whether you should also disable keyboard-interactive authentication depends on your authentication design. Do not disable it blindly if you use PAM, multi-factor authentication or another mechanism that requires it.

Validate SSH before reloading

sudo sshd -t

If the command returns no error, reload SSH:

sudo systemctl reload ssh

Keep your existing session connected and test another fresh login before signing out.

Check the effective SSH configuration

sudo sshd -T | grep -Ei 'passwordauthentication|permitrootlogin|pubkeyauthentication|kbdinteractiveauthentication'

The effective configuration is more useful than assuming that a single line in one configuration file controls the final result.

Configure the UFW Firewall Without Locking Yourself Out

Ubuntu provides UFW as a simplified firewall-management tool. Before enabling it on a remote VPS, explicitly allow the SSH service or the actual SSH port you use.

Check your current SSH port

sudo sshd -T | grep '^port '

If SSH uses the standard OpenSSH service definition:

sudo ufw allow OpenSSH

If you deliberately configured a different SSH port, allow that exact port instead. For example, only if your SSH service is really using TCP 2222:

sudo ufw allow 2222/tcp
Important: Do not copy the custom-port example unless your SSH daemon is actually listening on that port. Changing SSH ports is not a replacement for key authentication, patching or access control.

For a typical public web server, allow the services the server actually needs:

sudo ufw allow 80/tcp sudo ufw allow 443/tcp

Review the planned rules:

sudo ufw show added

Then enable UFW:

sudo ufw enable sudo ufw status verbose

Avoid opening database, administrative panel or internal application ports to the entire internet unless that exposure is genuinely required and protected appropriately.

Add Fail2ban or Equivalent Brute-Force Protection

Fail2ban monitors configured log sources for repeated failures and can temporarily block offending addresses. It is useful as an additional defensive layer, but it does not replace SSH keys, software updates or firewall policy.

sudo apt update sudo apt install fail2ban

Keep local changes in a local configuration rather than editing the package's main jail.conf directly.

sudo nano /etc/fail2ban/jail.d/sshd.local

Example:

[sshd] enabled = true maxretry = 5 findtime = 10m bantime = 1h

Restart and check the service:

sudo systemctl restart fail2ban sudo systemctl status fail2ban sudo fail2ban-client status sudo fail2ban-client status sshd

Log backends and service names can differ between distributions and system configurations, so verify that the jail is actually detecting events on your server rather than assuming it is active merely because the package is installed.

Apply Least Privilege to Users, Services and Files

A secure Linux VPS should not run every application as root. Give each application only the permissions it needs.

  • Create dedicated service users for applications where appropriate.
  • Avoid granting sudo rights to accounts that do not need administration access.
  • Do not make application directories world-writable.
  • Keep secrets outside public web roots.
  • Protect private keys, API tokens, database credentials and environment files with restrictive permissions.
  • Remove unused user accounts and revoke old SSH keys when personnel or access requirements change.

Review sudo access

getent group sudo sudo -l

Review local users with interactive shells

awk -F: '$7 !~ /(nologin|false)$/ {print $1, $7}' /etc/passwd

Do not automatically delete unfamiliar accounts. System software and hosting-management tools may legitimately create service accounts. Investigate first.

Secure Web Applications and Databases

Operating-system hardening alone cannot secure a vulnerable application. Keep web frameworks, CMS platforms, plugins, themes, language runtimes, package dependencies and database software supported and patched.

Bind internal services conservatively

Where an application or database is used only by software on the same VPS, consider binding it to localhost or a private interface rather than exposing it publicly.

Check listening services:

sudo ss -tulpn

Investigate every unexpected listener before closing it. Some services may be required by your hosting stack or monitoring system.

Protect application secrets

Do not commit production passwords, API credentials, TLS private keys or database secrets to public source-code repositories. Use appropriate secrets-management mechanisms for your deployment model.

For Node.js, PHP, Python and other applications

Run application processes as dedicated non-root users where possible. Expose the public website through a properly configured reverse proxy such as Nginx rather than running an application development server directly on an unrestricted public port.

Protect Web Traffic with HTTPS and Modern TLS

Websites, control panels and APIs that carry credentials or sensitive data should use HTTPS. For Nginx, current releases support TLS 1.2 and TLS 1.3 configurations.

A simplified Nginx HTTPS server block may look like this:

server { listen 443 ssl; server_name example.com www.example.com; ssl_certificate /path/to/fullchain.pem; ssl_certificate_key /path/to/private-key.pem; ssl_protocols TLSv1.2 TLSv1.3; # Your application/reverse-proxy configuration goes here. }
Certificate paths, reverse-proxy settings and TLS configuration depend on your application and certificate-management method. Test the Nginx configuration before reloading it.
sudo nginx -t sudo systemctl reload nginx

Protect the TLS private key with restrictive filesystem permissions and do not distribute it like a public certificate.

Important Docker Firewall Security Caveat

Docker modifies Linux firewall rules for container networking. A common mistake is assuming that blocking a port with UFW automatically prevents a Docker-published port from being reachable.

Docker users: Published Docker ports can be handled before normal UFW filtering. Review Docker's firewall documentation before relying on UFW to protect published container services.

For example, this command normally publishes port 3000 on the host's available interfaces:

docker run -p 3000:3000 your-image

If a service only needs to be reachable locally through a reverse proxy, binding to loopback can reduce unintended exposure:

docker run -p 127.0.0.1:3000:3000 your-image

Container networking requirements vary. Review published ports, Docker network modes and the host firewall together rather than treating them as separate security systems.

docker ps --format 'table {{.Names}}\t{{.Ports}}' sudo ss -tulpn

Monitor Logs, Authentication and System Activity

Hardening reduces risk, but monitoring helps you detect attempted or successful misuse.

Review SSH and authentication activity

sudo journalctl -u ssh --since "24 hours ago" sudo last sudo lastb

Availability of lastb and its underlying logs can vary by system configuration.

Review failed system services

systemctl --failed

Review recent high-priority system events

sudo journalctl -p warning --since "24 hours ago"

Review active network listeners

sudo ss -tulpn

For production or business-critical environments, consider forwarding important logs to a separate protected logging platform so an attacker who compromises the VPS cannot easily destroy the only copy of the evidence.

Maintain Backups That Can Actually Be Restored

Backups are part of security, not only disaster recovery. A useful backup strategy protects the information needed to rebuild the application, including application data, databases and essential configuration.

  • Keep at least one backup logically separated from the VPS.
  • Protect backup credentials separately from application credentials where practical.
  • Encrypt sensitive backup data appropriately.
  • Use retention or immutability controls where suitable.
  • Test restoration rather than assuming a successful backup job equals a recoverable backup.
  • Document recovery steps and required credentials.

Provider snapshots can be useful, but do not automatically assume they satisfy your application's full backup, retention or disaster-recovery requirements.

Linux VPS Security Audit Commands

These commands provide a quick operational review. They are not a complete vulnerability assessment or compliance audit.

Check Ubuntu version

cat /etc/os-release

Check pending package upgrades

sudo apt update apt list --upgradable

Check exposed TCP/UDP services

sudo ss -tulpn

Check firewall status

sudo ufw status verbose

Check SSH effective security settings

sudo sshd -T | grep -Ei 'port|permitrootlogin|passwordauthentication|pubkeyauthentication|kbdinteractiveauthentication'

Check Fail2ban

sudo fail2ban-client status

Check failed services

systemctl --failed

Check disk usage

df -h

Check recent logins

last

Check running processes

ps aux --sort=-%cpu | head -20

A command returning clean-looking output does not prove that a server is uncompromised. Use these checks as part of ongoing administration rather than as a security guarantee.

What to Do If You Suspect Your Linux VPS Is Compromised

If you observe an unknown administrator, unexplained SSH keys, suspicious processes, cryptocurrency-mining activity, unexpected outbound traffic, altered application files or unexplained account changes, treat the event as a potential security incident.

  1. Preserve relevant evidence and logs before deleting files or making large changes, where your incident-response requirements permit it.
  2. Isolate or restrict the affected workload if continued connectivity creates additional risk.
  3. Rotate credentials that may have been exposed, including API keys, database passwords and administrative credentials.
  4. Investigate the initial access path rather than only removing the visible malware.
  5. Patch the exploited vulnerability or configuration weakness.
  6. For a confirmed compromise, rebuilding from a known-good system image can be safer than assuming every unauthorized persistence mechanism has been found.
  7. Restore validated application data from appropriate backups.
  8. Review logs and monitoring data to understand scope and recurrence.
If the VPS handles regulated, financial, healthcare, customer or other sensitive information, your organization may also have contractual, legal or regulatory incident-reporting requirements. Follow the requirements applicable to your organization and jurisdiction.

Securing Linux VPS Hosting for Businesses in India

Indian startups, developers, agencies, SaaS businesses and eCommerce teams often use Linux VPS environments for websites, APIs, development stacks, Node.js applications, databases and other server workloads. The same hardening principles apply regardless of where the administrator is based: minimize exposed services, protect remote administration, patch software, control privileges and maintain recoverable backups.

When comparing Linux VPS hosting in India, evaluate more than RAM, CPU and price. Ask who is responsible for operating-system security, firewall rules, backups, monitoring, application patches and incident response. Root access gives administrators extensive control, but it also means responsibility for many operating-system and application security decisions may remain with the customer unless a managed service states otherwise.

Need a Linux VPS for Your Next Deployment?

Explore Net2Secure's Linux and Ubuntu VPS pages to compare available configurations and confirm the features, management scope and security responsibilities that apply to your selected service.

You can also compare VPS Hosting options for additional workloads.

Test a VPS Environment Before a Production Deployment

A trial environment can be useful for validating your SSH configuration, firewall rules, application stack and deployment process before committing a production workload. Trial resources, root access, server location, backups, expiry rules and eligibility should always be confirmed for the specific trial you receive.

Evaluate Your Linux VPS Setup

Before uploading sensitive or production data, confirm the current trial conditions, included resources, permissions, backup coverage and expiry arrangements directly with Net2Secure.

Linux VPS Security: What Hosting Protects and What You Must Configure

Security Responsibility Typical Consideration
Physical infrastructure Normally handled by the infrastructure provider
Hypervisor and host platform Normally handled by the infrastructure provider
Ubuntu package updates May be your responsibility on an unmanaged/root-access VPS
SSH configuration Usually administrator responsibility unless explicitly managed
UFW/firewall policy inside the VPS Usually administrator responsibility unless explicitly managed
Application and CMS updates Usually customer/application-owner responsibility
Database security Usually application/server administrator responsibility
Backup configuration Must be confirmed with the provider; never assume coverage
Incident response Responsibilities should be defined before an incident occurs

The exact responsibility model depends on whether your service is unmanaged, managed or covered by another support agreement. Confirm the applicable Net2Secure service description and terms rather than assuming every VPS includes operating-system management.

Frequently Asked Questions About Linux VPS Security

How do I secure a Linux VPS server?

Start with backup and recovery access, install operating-system security updates, create a sudo-enabled non-root user, configure SSH keys, test a new SSH session, restrict unnecessary SSH authentication, configure a firewall, patch applications, use HTTPS, monitor logs and maintain tested backups. Make changes gradually so you do not lock yourself out.

How do I secure SSH on an Ubuntu VPS?

Configure public-key authentication for a non-root administrative user and verify that it works in a separate SSH session. Then validate the SSH configuration before disabling password authentication or direct root SSH login. Keep recovery-console access available in case a configuration error blocks remote access.

Should I disable root SSH login on a Linux VPS?

Direct root SSH login is commonly restricted after a working sudo-enabled administrative account and SSH key have been tested. Do not disable your only working login method. Confirm your provider's console or recovery process before changing remote-access settings.

Is UFW enough to secure an Ubuntu VPS?

No. UFW helps restrict network access, but VPS security also depends on patching, SSH configuration, application security, permissions, HTTPS, monitoring and backups. Docker users must additionally review Docker firewall behavior because published container ports can interact with firewall rules differently from ordinary host services.

Do I need Fail2ban if I use SSH keys?

SSH keys significantly improve remote authentication security, while Fail2ban can provide an additional layer against repeated authentication attempts. It should be treated as supplementary protection rather than a replacement for secure authentication and patching.

How often should I update my Ubuntu VPS?

Security updates should be applied promptly according to the risk and operational requirements of your server. Ubuntu provides unattended-upgrades for automatic security updates, but administrators should still monitor update results and plan reboots or application maintenance when required.

Is Linux VPS hosting secure for Node.js applications?

A Linux VPS can provide an appropriate environment for Node.js when the operating system, Node.js runtime, dependencies, SSH access, firewall, reverse proxy, TLS configuration and application permissions are maintained securely. Run the application with least privilege and avoid exposing internal application ports unnecessarily.

Can I test Linux VPS security before moving my production website?

A VPS trial or staging environment can be useful for testing SSH access, firewall rules, packages and deployment procedures. Net2Secure publishes VPS trial and Linux VPS trial pages; confirm the current eligibility, resources, permissions, backup coverage and expiry conditions before uploading data.

Official Security References

This guide is an editorial hardening checklist, not a substitute for the documentation of the software installed on your server. Review the official sources relevant to your exact Ubuntu, OpenSSH, Nginx, Docker and application versions.

Final Takeaway

Securing a Linux VPS is an ongoing operational process rather than a one-time command. Begin with recovery access, keep Ubuntu and your application stack patched, use strong SSH authentication, expose only required network services, apply least privilege, encrypt web traffic, monitor logs and maintain recoverable backups.

Experience VPS Hosting Before You Buy

Choose your preferred VPS trial and test the right server environment for your requirements.

☁

VPS Server Trial

Test cloud VPS performance, server resources and application compatibility.

Start VPS Trial →
🐧

Linux VPS Hosting Trial

Explore Linux VPS for websites, development and application hosting.

Try Linux VPS →
💻

Windows VPS Trial

Test Windows VPS for remote desktop access and business applications.

Try Windows VPS →

Trial eligibility, availability and applicable terms may vary.


Abhay Pratap Singh

By Abhay Pratap Singh

Abhay Singh is a digital marketing strategist, technology writer, and SEO specialist with a passion for helping businesses grow through data-driven digital solutions. He specializes in search engine optimization (SEO), web hosting technologies, cybersecurity trends, cloud computing, website performance optimization, and emerging digital innovations.

With years of experience in content strategy and technical SEO, Abhay has authored numerous in-depth guides, tutorials, and industry insights that help businesses, website owners, and IT professionals navigate the evolving digital landscape. His expertise spans website optimization, DNS management, web hosting infrastructure, cybersecurity best practices, and AI-driven digital marketing strategies.

View all of Abhay Pratap Singh's posts.

Contact Us

Latest Articles

We use cookies

By continuing to browse this site, you are agreeing to the use of cookies to enhance your experience.

EXCLUSIVE CLOUD OFFER • GET ₹2,000 FREE CLOUD CREDITS!

Claim ₹2,000 Credits

Signup with Net2Secure and make your first recharge of ₹2,000 to get additional ₹2,000 add-on credits.

Only for New Customers • Terms Apply

Get ₹2,000
Free Cloud Credits!

Supercharge your workloads with Net2Secure enterprise cloud infrastructure. High speed, zero upfront commitment!

₹2,000 FREE CLOUD CREDITS
✦
✦
  • Get ₹2,000 Wallet Bonus on first recharge
  • High-Speed Cloud Server Deployment
  • 24/7 Dedicated Server Support & 99.95% Uptime