ssh のポートを変更する

AWS Debian

遅まきながら、ssh のポートを 22 から変更する。
これ、手順を間違えると、二度とログインできなくなる。

sshd_config の修正

root@aws:/etc/ssh# mv sshd_config{,.orig}
root@aws:/etc/ssh# cp sshd_config{.orig,}
root@aws:/etc/ssh# vi sshd_config
root@aws:/etc/ssh# diff -u sshd_config{.orig,}
--- sshd_config.orig    2017-10-08 22:15:06.399137062 +0900
+++ sshd_config 2017-12-26 18:41:41.077867930 +0900
@@ -11,6 +11,7 @@
 # default value.

 #Port 22
+Port 内緒
 #AddressFamily any
 #ListenAddress 0.0.0.0
 #ListenAddress ::
@@ -30,6 +31,7 @@

 #LoginGraceTime 2m
 #PermitRootLogin prohibit-password
+PermitRootLogin no
 #StrictModes yes
 #MaxAuthTries 6
 #MaxSessions 10
root@aws:/etc/ssh#

sshd の再起動

root@aws:/etc/ssh# systemctl restart ssh
root@aws:/etc/ssh#
ここでこのセッションを切断してはならない

新しいポートを開く

セキュリティグループで新しいポートを追加

ssh クライアントから接続

新しいポートに接続できることを確認。
ここで、ようやく最初のセッションを閉じる。

セキュリティグループから ssh を削除

念のため、再起動して新しいポートでログインできることを確認



メールサーバの構築(3)ポート開放と対外連携
山下康成の
雲の上

rsync のインストール

Copyright (C) 2003-2018 Yasunari Yamashita. All Rights Reserved.
yasunari @ yamasita.jp 山下康成@京都府向日市/東京都新宿区