50% off 全プラン、期間限定。料金は $2.48/mo
Security

Secure linux vps

By Parnian R. 7 min read Updated Feb 15, 2026

デジタル時代において、Linux Virtual Private Server (VPS) を保護することが重要です
はデータとインフラストラクチャを保護するうえで不可欠です。この
comprehensive guide explores methods to protect your Linux VPS against
cyber threats.

Keep Your System
Updated

One of the most important aspects of securing your Linux VPS is
システムを常に最新の状態に保つことが重要です。古いソフトウェアは
悪意のある攻撃者に悪用される可能性のある脆弱性が含まれている。その対策方法は以下の通りだ。
do it:

Use Package Manager

ほとんどのLinux配布版にはパッケージマネージャーが含まれています。例えば、
Debian ベースのシステムを使用しており、以下のコマンドが実行できます
パッケージを更新・アップグレードするには:

sudo apt update
sudo apt upgrade

CentOS システムを使用している場合は、yum を使用してください。

sudo yum update

Set Up Automatic
Updates

Set Up Automatic Updates with unattended-upgrades on
Debian-based Systems:

Debian ベースのシステム (Ubuntu など) では、以下を使用できます
unattended-upgrades パッケージを使用して更新プロセスを自動化します。

  1. Install unattended-upgrades:
sudo apt install unattended-upgrades
  1. Configure the automatic update settings. Edit the configuration
    file:
sudo nano /etc/apt/apt.conf.d/50unattended-upgrades
  1. Enable automatic updates for security-related packages:
Unattended-Upgrade::Allowed-Origins {
    "${distro_id}:${distro_codename}-security";
    "${distro_id}:${distro_codename}-updates";
    "${distro_id}:${distro_codename}-proposed";
    "${distro_id}:${distro_codename}-backports";
};
  1. unattended-upgrades サービスを有効化して起動します:
sudo dpkg-reconfigure -plow unattended-upgrades

このコマンドは変更の確認を求めます。「Yes」を選択して
enable automatic updates.

Set Up Automatic Updates with yum-cron on
CentOS:

CentOS では yum-cron を使用して自動アップデートを実行できます:

  1. Install yum-cron:
sudo yum install yum-cron
  1. yum-cron サービスを起動して有効にします:
sudo systemctl enable yum-cron
sudo systemctl start yum-cron

Use
Strong Passwords and SSH Keys for Secure Authentication

Securing your Linux VPS involves using strong authentication methods.
Linux または Windows クライアントから接続しているかどうかにかかわらず、以下が方法です
use strong passwords and SSH keys effectively:

Using Strong
Passwords

VPS でユーザーアカウントを作成する際は、パスワードが
complex, combining uppercase and lowercase letters, numbers, and special
characters. Avoid easily guessable passwords.

Using SSH Key
Authentication

For Linux Client:

  1. Linux クライアントで SSH キーペアを生成するには、ssh-keygen を使用します
    command:
ssh-keygen -t rsa -b 2048

The public key, by default, will be stored in ~/.ssh/id_rsa.pub.

  1. 公開鍵を VPS にコピーします。
ssh-copy-id user@your_server_ip
  1. Disable password-based SSH login on the VPS in the SSH server
    configuration file (/etc/ssh/sshd_config):
PasswordAuthentication no

For Windows Client:

  1. Windows では、同様の機能を実現するには PowerShell を使用してください。
ssh-keygen
  1. PowerShell を使用して公開鍵を VPS にコピーします。置き換えてください
    IP-ADDRESS-OR-FQDN with the remote server’s
    address:
type $env:USERPROFILE\.ssh\id_rsa.pub | ssh root@{IP-ADDRESS-OR-FQDN} "cat >> .ssh/authorized_keys"
  1. Disable password-based SSH login on the VPS in the SSH server
    configuration file (/etc/ssh/sshd_config):
PasswordAuthentication no

Implement a Firewall

Securing your Linux VPS involves setting up a firewall to control
インバウンドおよびアウトバウンドトラフィック。ファイアウォールの実装方法は以下の通りです。
enhance security:

Use ufw (Uncomplicated Firewall) on Debian/Ubuntu or
firewalld on CentOS:

  1. Install the firewall management tool if not already installed.

For ufw on Debian/Ubuntu:

sudo apt install ufw

firewalld の設定(CentOS):

sudo yum install firewalld
  1. Add rules to allow SSH before enabling the firewall to prevent being
    locked out:

For ufw on Debian/Ubuntu:

sudo ufw allow OpenSSH

firewalld の設定(CentOS):

sudo firewall-cmd --permanent --add-service=ssh
  1. ファイアウォールを有効にしてデフォルトルールを設定します:

For ufw on Debian/Ubuntu:

sudo ufw enable
sudo ufw default deny incoming
sudo ufw default allow outgoing

firewalld の設定(CentOS):

sudo systemctl start firewalld
sudo systemctl enable firewalld
  1. 変更を反映させるには、ファイアウォールを再読み込みしてください。

For ufw on Debian/Ubuntu:

sudo ufw reload

firewalld の設定(CentOS):

sudo systemctl reload firewalld

ルートログインを無効化する

Linux VPS のセキュリティを確保するには、root アクセスを制限する必要があります。その方法をご説明します
セキュリティを強化するためにroot ログインを無効にする:

  1. 新しいユーザーを作成: VPS にルートユーザーとしてログインしてから、作成します
    a new user account with sudo privileges. Replace newuserwith your
    desired username:
adduser newuser
usermod -aG sudo newuser
  1. .sshディレクトリ、authorized_keysを作成し、権限を設定する
    the New User:
mkdir -p /home/newuser/.ssh
touch /home/newuser/.ssh/authorized_keys
chmod 600 /home/newuser/.ssh/authorized_keys
chown -R newuser:newuser /home/newuser/.ssh
  1. Make sure to generate and copy the public key to your
    VPS.

  2. 新しいユーザーでログインします。

  3. Disconnect from the VPS (if you’re connected as root) and log
    新しいユーザーアカウントを使用してログインし直します。これにより、以下を実行できるようになります
    administrative tasks using sudo.

  4. Edit SSH Configuration:

VPS 上の SSH サーバー設定ファイルを開きます。このファイルは
usually located at /etc/ssh/sshd_config:

sudo nano /etc/ssh/sshd_config

PermitRootLogin という行を探し、これを no に設定します:

PermitRootLogin no

ファイルを保存してテキストエディターを終了します。

  1. Restart SSH Service:

この変更を加えた後、SSH サービスを再起動する必要があります。
new settings to take effect:

On Debian/Ubuntu:

sudo systemctl restart ssh

On CentOS:

sudo systemctl restart sshd

Harden SSH
Configuration

Securing your Linux VPS involves further hardening the SSH
configuration for added security and ensuring that UFW rules are up to
設定を強化し、UFW を更新する方法は次のとおりです。
rules:

  1. UFW で新しい SSH ポートを許可します:

UFW (Uncomplicated Firewall) を使用している場合は、まず新しい SSH ポートを許可します。
デフォルトポートを変更する前に:

# Allow the new SSH port (e.g., 2222)
sudo ufw allow 2222/tcp
  1. Remove OpenSSH from UFW Rules:

SSH ポートを変更した後、古い OpenSSH を削除する必要があります
service (default port 22) from the UFW rules to ensure that only the new
SSH port is allowed:

# Remove the old OpenSSH service (default port 22)
sudo ufw delete allow OpenSSH
  1. Change the SSH Port:

デフォルトでは、SSH はポート 22 を使用しています。デフォルトポートを変更すると、以下が追加されます
extra layer of security by making it harder for automated bots to find
your SSH server.

Open the SSH server configuration file:

sudo nano /etc/ssh/sshd_config

Find the line that reads Port 22 and change the port number to a
different, unused port, for example, 2222:

Port 2222
  1. Enable Key Reauthentication:

You can set a time limit for key reauthentication to further secure
SSH セッション。つまり、SSH セッションを放置した場合、
unattended, it will automatically expire after a certain time.

Add or modify the following lines in the SSH server configuration
file, then save it:

ClientAliveInterval 300
ClientAliveCountMax 2
  1. Reload UFW Rules and SSH Service:
sudo ufw reload
sudo systemctl restart ssh
  1. 必要な変更を行った後、新しい SSH を確立できます
    connection using the following command:
ssh -p <new_port> user@your_server_ip

Implement Fail2Ban

Securing your Linux VPS involves protecting it from brute-force login
攻撃および他の種類の悪意のある活動。Fail2Ban は有用な
このツール。Fail2Ban の実装方法は次のとおりです:

  1. Install Fail2Ban:

Start by updating your package list to ensure you have the latest
available packages:

For Debian-based systems (e.g., Ubuntu):

sudo apt update

For CentOS:

sudo yum update

Install Fail2Ban:

For Debian-based systems:

sudo apt install fail2ban

For CentOS:

sudo yum install fail2ban
  1. Configure Fail2Ban:

Fail2Ban’s main configuration file is located at
/etc/fail2ban/jail.confオーバーライドを作成できます
file at /etc/fail2ban/jail.local to customize settings
デフォルト設定を変更せずに。このファイルを開きます:

sudo nano /etc/fail2ban/jail.local

Add the following configuration to ban IP addresses for 10 minutes
(600 seconds) after six failed login attempts. Adjust the parameters as
needed:

[sshd]
enabled = true
maxretry = 6
findtime = 600
bantime = 600

ファイルを保存してテキストエディターを終了します。

  1. Start and Enable Fail2Ban:

Fail2Ban を起動し、ブート時に起動するように設定します:

sudo systemctl start fail2ban
sudo systemctl enable fail2ban
  1. Check Fail2Ban Status:

You can check the status of Fail2Ban to ensure it’s working as
expected:

sudo fail2ban-client status

SSH サービスを監視していることが表示されます。

The 6 essential methods discussed here provide a robust defense
潜在的な脆弱性から保護します。システムを最新の状態に保つことで、
employing strong authentication, configuring firewalls, hardening SSH,
および Fail2Ban を実装することで、VPS を強化し、安心を維持します
デジタルの世界で。ご質問がある場合は、お気軽に
hesitate to contact our support team by submitting a
ticket
.

Share

Need help with something else?

Median response time under 1 hour. Real humans, not bots.