0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

サーバー作ったら最低限やること

0
Last updated at Posted at 2026-03-28
  1. root以外のユーザーの作成と設定
  2. ssh接続の確立
  3. ファイアウォールの適用

1root以外のユーザー作成と設定

  1. root以外のユーザーの作成

以下のコマンドで作成します

sudo adduser ユーザー名
sudo adduser med

コマンド打った後にパスワードの設定要求がくるためしっかり打つ

そのあとは全てEnterで大丈夫

  1. ユーザーにsudo権限付与

自分の作ったroot以外の権限ユーザーにsudoができるように割り振ります

sudo usermod -aG sudo ユーザー名
sudo usermod -aG sudo med

ssh接続の確立

  1. sshのスタート
sudo systemctl start ssh
  1. ssh.socketの停止

sshには起動方法でserviceとsocketの2種類のデーモンがあるのですが、socketは設定を上書きして悪さする可能性があるので今回は止めます詳細は以下に

ssh接続について (1)

sudo systemctl disable ssh.socket
sudo systemctl stop ssh.socket

sudo systemctl restart ssh
  1. sshのポート番号の変更

デフォルトは22番ですがセキュリティの観点から変えます
/etc/ssh/sshd_configに設定が書かれているのでnanoで編集します

sudo nano /etc/ssh/sshd_config

Portの部分を22から任意の値にしましょう(今回私は10022)

元々

image.png

変更後

image.png

  1. rootのsshログインを禁止、

rootはなんでもできてしまうので万が一sshで入られてしまうとやばいので変更します

PermitRootLogin no
と変更します

image.png

  1. 再起動して、確認

まず再起動

sudo systemctl restart ssh

次に、反映されているかの確認

以下のコマンドを打って10022と出ればおk

ss -tlnp | grep ssh

image.png

3 ファイアウォールの適用

  1. ファイアウォールの起動
sudo ufw enable
  1. ファイアウォールにルール追加
sudo ufw allow 先ほど決めた番号/tcp
sudo ufw allow 10022/tcp
  1. 適用されたか確認

以下のコマンドでルール一覧を開き任意の番号があるか確認

sudo ufw status numbered

image.png

あったらOK

終わり!!

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?