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?

More than 5 years have passed since last update.

sshd接続ポート番号変更

Posted at

手順

1. /etc/ssh/sshd_configを開く。

viで/etc/ssh/sshd_configを開きます。

2. 接続ポート番号を変更する。

/etc/ssh/sshd_configに記述されている。
Port 22 (#でコメントアウトされている場合あり)
の部分を変更します。
例. Port 56789

※ ポート番号使用範囲
一般ポート(ウェルノウン(well known)ポート) : 0~1023
登録済みポート : 1024~49151
自由に使用できるポート : 49152~65535

3. sshを再起動して設定を反映する。

次のコマンドでsshを再起動する。
service sshd restart

4. Firewall(iptables)の設定ファイルを開く。

Firewall(iptables)で新しく設定したsshd接続ポートを接続可能にするため、
vi /etc/sysconfig/iptables (さくらVPSサーバー(CentOS6.9)の場合)
コマンドを実行し、ファイルを開きます。

5. iptablesの開放ポート番号を変更する。

/etc/sysconfig/iptablesに記述されている次の赤文字の箇所を任意(/etc/ssh/sshd_configで設定した)ポート番号に変更します。

-A INPUT -m state —state NEW -m tcp -p tcp —dport 22 -j ACCEPT

6. iptablesを再起動して設定を反映する。

次のコマンドでiptablesを再起動する。
service iptables restart

まとめ

ssh接続ポート番号はデフォルトでは22なので、/etc/ssh/sshd_configを編集して、49152~65535の範囲の数値で新しい接続ポート番号を設定する。
また、新しく設定したポート番号は、Firewallで遮断されてしまうため、iptablesの設定を変更する必要がある。

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?