SSHのポートを変更
手順
- sshされる側(sshd)のポート設定を変更
- sshされる側のfirewalldの設定を変更
- sshされる側のsshdとfirewalldの再起動
- sshする側からポート解放の確認とログインできることの確認
sshされる側のOS version
[root@localhost ~]# cat /etc/centos-release CentOS Linux release 7.5.1804 (Core) [root@localhost ~]#
される側のIPアドレス: 192.168.1.1 9
Port 22→99に変更
sshされる側のsshdのポート設定を変更
sshd_configのPort 22をコメントアウトし、好きなポート番号の設定を追記
[root@localhost ~]# vim /etc/ssh/sshd_config [root@localhost ~]# [root@localhost ~]# cat /etc/ssh/sshd_config |grep --color Port #Port 22 Port 99 #GatewayPorts no [root@localhost ~]#
sshされる側のfirewalldの設定を変更
[root@localhost ~]# firewall-cmd --permanent --zone=public --add-port=99/tcp [root@localhost ~]# firewall-cmd --list-ports 99/tcp [root@localhost ~]# firewall-cmd --reload
-
- permanent がないと、設定してもreloadしたらリセットされてしまう。
firewall-cmd --permanent --zone=public --remove-port=99/tcp
だと許可ポート削除。あと、firewall-cmd --list-hogehoge で基本的にhogehogeの設定確認できる。
sshされる側のsshdとfirewalldの再起動
[root@localhost ~]# systemctl restart firewalld.service [root@localhost ~]# systemctl restart sshd.service 状態確認 [root@localhost ~]# systemctl status firewalld.service [root@localhost ~]# systemctl status ssd.service (active, runningと表示されればおK)
起動時有効化するなら、systemctl enable hogehoge
sshする側からポート解放の確認とログインできることの確認
[motsuo@remote-pc ~]$ telnet 192.168.1.1 99 (正しくポート解放できていれば、refuseされない) [motsuo@remote-pc ~]$ ssh motsuo@192.168.1.1 -p 99
コメント;firewall-cmdは書式というか、コマンドのパターンを覚えれば、直観的に設定できるかも。