SSH Hardening & Sudo Best Practices for a Linux VPS Sweden

0
16

AEO Answer Box

SSH hardening on a Linux VPS Sweden involves enabling key-based authentication, disabling password-based SSH access, restricting direct root login and controlling administrative privileges through sudo. Administrators can also configure a custom SSH port, firewall rules and auditd logging to reduce unnecessary network exposure and maintain records of security-related system activity.

Quick Answer

Create a dedicated administrative user, configure SSH key authentication and verify access before disabling password-based login. Restrict root access, assign appropriate sudo permissions, configure firewall rules and enable auditd logging to monitor important system changes.

Introduction

A Linux VPS running WordPress, PHP, Python or Node.js applications needs secure administrative access. Poorly configured SSH services can expose the server to automated login attempts, unauthorized access and credential-based attacks.

Developers managing a Linux VPS in Sweden can strengthen server security without installing resource-intensive security software. SSH configuration, controlled administrative permissions and system auditing provide a practical foundation for protecting production environments.

SSH Key Authentication

Replace password-based SSH access with cryptographic keys.

Sudo Access Control

Restrict administrative privileges to authorized users.

Auditd Logging

Track security-related activity and important configuration changes.

Table of Contents

  • Why SSH hardening matters
  • Creating a dedicated administrative user
  • Configuring SSH key authentication
  • Disabling password authentication and root login
  • Changing the default SSH port
  • Implementing sudo best practices
  • Configuring auditd security logging
  • Frequently Asked Questions

Why SSH Hardening Matters

SSH provides encrypted remote access to Linux servers, allowing developers to install software, deploy applications and manage system configurations.

An internet-facing SSH service can attract automated login attempts. Password-based authentication increases exposure to credential guessing, particularly when administrators reuse passwords across multiple systems.

SSH hardening reduces these risks by limiting authentication methods, controlling user privileges and recording administrative activity.

This guide uses Ubuntu 24.04 LTS as the example operating system.

Creating a Dedicated Administrative User

Avoid using the root account for routine server administration. Create an individual administrative account instead.

sudo adduser deployadmin

sudo usermod -aG sudo deployadmin

Verify that the new account has working sudo access:

su - deployadmin

sudo whoami

The expected output is root.

Keep your existing administrative session open until the new account and its SSH access have been tested successfully.

Configuring SSH Key Authentication

SSH key authentication uses a public and private key pair instead of relying on a server account password.

Generate an Ed25519 key on your local computer:

ssh-keygen -t ed25519 -C "vps-admin"

Protect the private key with a strong passphrase.

Transfer the public key to your VPS:

ssh-copy-id deployadmin@SERVER_IP

Replace SERVER_IP with your actual VPS IP address.

Test the connection:

ssh deployadmin@SERVER_IP

Never share the private key or upload it to the remote server. Ubuntu's official OpenSSH documentation provides additional guidance on key-based authentication.

Ubuntu Server documentation

Disabling Password Authentication and Root Login

Once SSH key authentication works, configure the SSH server to reject password-based access and direct root login.

Create a hardening configuration file:

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

Add the following settings:

PubkeyAuthentication yes

PasswordAuthentication no

KbdInteractiveAuthentication no

PermitRootLogin no

AuthenticationMethods publickey

MaxAuthTries 3

LoginGraceTime 30

Validate the configuration:

sudo sshd -t

Check the effective settings:

sudo sshd -T

If the configuration is correct, restart the SSH service:

sudo systemctl restart ssh

Test a new connection before closing the existing session. Review other SSH configuration files for conflicting directives.

These authentication controls are documented in the OpenSSH server configuration manual.

OpenBSD manual pages

Changing the Default SSH Port

SSH normally listens on TCP port 22. Moving the service to a different port can reduce routine automated scanning noise, although it does not prevent targeted attacks.

For example, administrators can configure port 2222:

Port 2222

If UFW is your active firewall, allow the new port before applying the change:

sudo ufw allow 2222/tcp

Ubuntu 24.04 commonly uses socket-based SSH activation. After validating the SSH configuration, reload systemd and restart the SSH socket if it is active:

sudo systemctl daemon-reload

sudo systemctl restart ssh.socket

For installations using conventional service-based activation, restart ssh.service instead.

lists.ubuntu.com

Test the new connection:

ssh -p 2222 deployadmin@SERVER_IP

Remove obsolete port 22 firewall rules only after confirming the new connection works. Remember to update any provider-level firewall rules.

Implementing Sudo Best Practices

Sudo allows authorized users to perform administrative tasks without maintaining a permanent root session.

Developers responsible for WordPress, PHP, Python or Node.js applications may only need permission to restart specific services or manage application deployments.

Edit sudo permissions safely using:

sudo visudo

For example, a separately authorized deployment account named webdeploy could receive permission to reload Nginx:

webdeploy ALL=(root) /usr/bin/systemctl reload nginx

Ensure that this account cannot modify privileged Nginx configuration files or other files that could indirectly grant administrative access.

Apply the following practices:

  • Use individual administrative accounts.
  • Avoid unrestricted passwordless sudo access.
  • Grant only the permissions required for assigned tasks.
  • Remove access when team members leave.
  • Review privileged account activity regularly.

Application service accounts should not receive administrative permissions unless genuinely necessary.

Configuring Auditd Security Logging

Auditd records security-related events and system activity according to configured audit rules.

Install the Linux audit service:

sudo apt update

sudo apt install auditd -y

sudo systemctl enable --now auditd

Create persistent audit rules:

sudo nano /etc/audit/rules.d/50-hardening.rules

Add monitoring rules for SSH and sudo configuration changes:

-w /etc/ssh/sshd_config -p wa -k ssh_config

-w /etc/ssh/sshd_config.d/ -p wa -k ssh_config

-w /etc/sudoers -p wa -k sudo_changes

-w /etc/sudoers.d/ -p wa -k sudo_changes

Load the rules:

sudo augenrules --load

Review active rules and recorded events:

sudo auditctl -l

sudo ausearch -k sudo_changes -i

sudo ausearch -k ssh_config -i

These rules monitor configuration modifications rather than recording every command executed by every administrator. Review the Linux audit rules documentation when expanding monitoring requirements.

Linux manual page

Configure log rotation and consider forwarding important audit records to a separate logging server.

Linux VPS vs Windows VPS Security

Linux VPS environments commonly use SSH for remote administration, while Windows VPS environments frequently use RDP.

Linux is a practical choice for WordPress, PHP, Python, Node.js and Nginx workloads. A Windows VPS Sweden may be preferable for traditional ASP.NET Framework, IIS and Windows-specific applications.

Both environments require restricted administrative access, regular security updates, appropriate firewall policies and activity logging.

Frequently Asked Questions

Is SSH key authentication safer than password authentication?

Generally, yes. Properly protected SSH keys reduce exposure to password guessing and credential reuse.

Does changing the SSH port prevent attacks?

No. It primarily reduces routine scanning noise and should complement stronger authentication controls.

Should developers receive unrestricted sudo access?

No. Administrative permissions should reflect individual responsibilities and operational requirements.

What is auditd used for?

Auditd records selected security events, configuration changes and system activity for administrative review.

Can SSH hardening affect website availability?

SSH configuration changes generally do not interrupt web applications, but incorrect firewall rules can block administrative access or other required connections.

Secure Your Linux VPS Hosting Environment

SSH hardening, restricted sudo privileges and security logging help administrators maintain better control over production environments. Developers hosting WordPress, PHP, Python and Node.js applications can explore configurable Linux and Windows VPS hosting environments from OnliveServer to manage their applications and server security requirements.

 

Suche
Kategorien
Mehr lesen
Health
How Zenuva CBD Gummies 1000mg Improve Your Quality of Life?
Are you struggling with joint pain and stress? If so, you've come to the right place for finding...
Von Green Life 2026-11-06 13:12:04 0 428
Health
Big Size Men Swimwear for Comfort, Style and Confidence
Choosing swimwear should be about enjoying the water, feeling comfortable, and expressing your...
Von Jasemi Work 2026-10-29 12:17:03 0 699
Andere
Cyber Incident Response Course: Developing Knowledge for Effective Cybersecurity Management
Any organisation, regardless of their size, can be the victim of cyber-attack. That means, it is...
Von Harris Jaffe 2026-08-27 10:15:11 0 1KB
Spiele
Bonus czy własne środki: z którego salda schodzi stawka
Odkąd zacząłem notować własne sesje, zauważyłem, że najwięcej nieporozumień bierze się nie z...
Von Ewa Pawlak 2026-11-25 12:17:15 0 371
Food
Japan Leads Country-Level Growth in Mycoprotein with 10.2% CAGR Through 2036
Mycoprotein Market USD 778.1 Million by 2036, Japan - CAGR 10.2%, South Korea - CAGR 8.1% NEWARK,...
Von Ajay Mane 2026-10-08 20:39:38 0 368
Uddokta 64 https://uddokta64.com