2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

Linux ubuntu SSH ポート変更 ファイアウォール設定

Last updated at Posted at 2021-08-18

手順

  1. configファイル内 Port番号を変更 (本記事のサンプルは2222へ変更)
  2. ファイアウォール設定変更 (ufw 使用)
  3. ファイアウォールの再読み込みとLinuxの再起動

contigファイル Port番号変更

sshd_config
sudo vi /etc/ssh/sshd_config

変更前 変更後
#Port 22 port 任意のポート番号
  • 任意のポート番号に変更する。例)port 2222
  • 「# 」はコメントを意味する為、消す。

ファイアウォール設定変更

root権限付与
sudo su

uwf:Uncomplicated FireWall

ufw は Ubuntu Firewall の略……ではなく、
Uncomplicated Firewall (複雑じゃないファイアウォール)の略です。
iptables の操作が複雑なので、それを簡単に操作するためのラッパーです。

ufwの状態確認
sudo ufw status
sudo ufw status numbered 
ufw有効 ufw無効 (デフォルト値)
Status: active Status: inactive
 
ufw起動(すべてのポートを拒否)
sudo ufw enable

Command may disrupt existing ssh connections. Proceed with operation (y|n)? y
【ポイント】
→実行(y)しても現在接続中の通信は切断されない。

SSH(ポート2222)を許可
ufw allow 2222
ルール1を削除
sudo ufw delete 1

ファイアウォールの再読み込みとLinuxの再起動

ufw再読み込み
ufw reload
Linux再起動
sudo reboot

これを行わないと、Linaxログイン時ソケットエラー10061が発生する可能性がある。

参考ページ

2
5
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
2
5

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?