Contents
1.SSHによるリモート接続の設定
SSHはサーバーへリモートで接続するためのサービスで、基本的にはOSインストール直後に動作していますが、デフォルトの設定ではややセキュリティに難があります。
ここではデフォルトの設定を変更してssh接続のセキュリティを高める設定を行います。
1.1 SSHサービスの設定ファイル変更
SSHサービスの設定を変更するために設定ファイルを変更します。
SSHサービスの設定ファイルは"/etc/ssh/sshd_config"になります。
1 |
# vi /etc/ssh/sshd_config |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
1 # $OpenBSD: sshd_config,v 1.104 2021/07/02 05:11:21 dtucker Exp $ 2 3 # This is the sshd server system-wide configuration file. See 4 # sshd_config(5) for more information. 5 6 # This sshd was compiled with PATH=/usr/local/bin:/usr/bin:/usr/local/sbin:/ usr/sbin 7 8 # The strategy used for options in the default sshd_config shipped with 9 # OpenSSH is to specify options with their default value where 10 # possible, but leave them commented. Uncommented options override the 11 # default value. 12 13 # To modify the system-wide sshd configuration, create a *.conf file under 14 # /etc/ssh/sshd_config.d/ which will be automatically included below 15 Include /etc/ssh/sshd_config.d/*.conf 16 17 # If you want to change the port on a SELinux system, you have to tell 18 # SELinux about this change. 19 # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER 20 # 21 Port 2244 22 #AddressFamily any 23 ListenAddress 0.0.0.0 24 #ListenAddress :: 25 26 #HostKey /etc/ssh/ssh_host_rsa_key 27 #HostKey /etc/ssh/ssh_host_ecdsa_key 28 #HostKey /etc/ssh/ssh_host_ed25519_key 29 30 # Ciphers and keying 31 #RekeyLimit default none 32 33 # Logging 34 #SyslogFacility AUTH 35 #LogLevel INFO 36 37 # Authentication: 38 39 #LoginGraceTime 2m 40 PermitRootLogin prohibit-password 41 #StrictModes yes 42 #MaxAuthTries 6 43 #MaxSessions 10 |
21行目「#」を削除し「Port 22」今回は「Port 2244」に変更して進めていきます
23行目「#ListenAddress 0.0.0.0」の「#」を削除します
40行目「#PermitRootLogin prohibit-password」「#」を削除します
rootユーザーはユーザー名が既に判明しているためパスワードが判明すると、管理者権限でサーバーへログイン出来るため、これを拒否する設定を行います。
SSH の再起動
1 |
# systemctl restart sshd.service |
このままでは次に再起動したときSSHによるリモート接続ができなくなるので、次のファイアウォールの設定でSSHポート2244番を解放してください。
2.ファイアウォール(firewalld)の設定方法
AlmaLinuxではファイアウォールはfirewalldがデフォルトに設定されており、OSインストール時に有効になっています。
「firewalld」について簡単に説明すると、通信制御のポリシーを設定する場合、事前に定義されたゾーンに対して通信の許可・遮断ルールを適用し、そのゾーンを各NIC(ネットワークアダプタ)に割り当てていくという方式になっています。
2.1 「firewalld」を制御するための「firewall-cmd」コマンド使用方法
1)「fierwalld」の状態や設定内容を確認するためのコマンド
①firewalld稼働状況確認
「firewalld」が動作している場合は「running」、停止している場合は「not running」と表示されます
1 2 |
# firewall-cmd --state running |
または
Active: active (running)と表示される
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 |
# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset> Active: active (running) since Sun 2025-06-15 10:21:13 JST; 35min ago Invocation: 1cac90b3529443c99f1db32a552bc72a Docs: man:firewalld(1) Main PID: 850 (firewalld) Tasks: 2 (limit: 10479) Memory: 46.2M (peak: 47.9M) CPU: 498ms CGroup: /system.slice/firewalld.service mq850 /usr/bin/python3 -sP /usr/sbin/firewalld --nofork --nopid Jun 15 10:21:13 localhost systemd[1]: Starting firewalld.service - firewalld - > Jun 15 10:21:13 localhost systemd[1]: Started firewalld.service - firewalld - d> |
➁「--permanent」オプションについて
サーバの再起動や「firewalld」サービスの再起動で設定が消えてしまわないようにするためには、
「--permanent」オプションを使用して設定を行う必要があります。その際、「--permanent」オプションを指定して設定を行った場合は、そのままでは「firewalld」に設定が反映されないため「fiewall-cmd --reload」で設定を反映させる必要があります
例としてHTTPサービスをシステムを再起動しても初期化されず恒久的に利用するためには
1 2 |
# firewall-cmd --add-service=http --permanent # firewall-cmd --reload |
➂起動・停止方法
「firewalld」は「systemd」で制御されているので、起動と停止には「systemctl」コマンドを使用
1 2 3 4 |
firewalldの起動 # systemctl start firewalld firewalldの停止 # systemctl stop firewalld |
2.2 変更したSSHポート2244番を解放する
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 |
# firewall-cmd --add-port=2244/tcp --permanent # firewall-cmd --reload # firewall-cmd --list-all public (default, active) target: default ingress-priority: 0 egress-priority: 0 icmp-block-inversion: no interfaces: ens160 sources: services: cockpit dhcpv6-client ssh ports: 2244/tcp protocols: forward: yes masquerade: no forward-ports: source-ports: icmp-blocks: rich rules: |
2244 port が追加されている
3.Windowsからリモート接続
Windowsでの設定
Windowsからリモート接続するための設定を始めます、ターミナルエミュレーターは「Tera Term」を使用します。
Tera Termを起動し、起動画面のキャンセルをした後、Tera Termメニューの「File」から「New Connection」を選択する。

「サーバーのIPアドレス」「TCPポート番号」の箇所は各自で設定したものを入力します。最後に「OK」をクリック

「OK」をクリックすると、セキュリティの確認の画面になるので「Continue」をクリック

次の画面になるので、「User name」Passphrase」を入力し、「OK」をクリック

情報が正しければ正常にログインできるはずです。
4.NTP サーバーの設定
サーバの時刻を日本標準時に同期させるNTP サーバーを構築します
①Chrony のインストールと設定
1 |
# dnf -y install chrony |
1 2 3 4 |
# vi /etc/chrony.conf 3行目 : コメントアウトにして、その下に追加 #pool 2.almalinux.pool.ntp.org iburst pool ntp.nict.jp iburst |
➁Chrony を再起動し、システム再起動後もChronyを有効化
1 2 |
# systemctl enable chronyd.service # systemctl restart chronyd.service |
③firewallでNTPポート解放
1 2 |
# firewall-cmd --add-service=ntp --permanent # firewall-cmd --reload |
④chronyd のステータス( 動作 )の確認
1 2 3 4 5 6 7 |
# chronyc sources MS Name/IP address Stratum Poll Reach LastRx Last sample =============================================================================== ^- ntp-a2.nict.go.jp 1 6 17 22 +732us[ +732us] +/- 5589us ^* ntp-b2.nict.go.jp 1 6 17 22 -607us[ -38us] +/- 6426us ^- ntp-a3.nict.go.jp 1 6 17 22 -419us[ -419us] +/- 6584us ^- ntp-k1.nict.jp 1 6 17 22 -525us[ -525us] +/- 3528us |
*印がついていたら同期ができています。