1.SSHによるリモート接続の設定
デフォルトの設定を変更してssh接続のセキュリティを高める設定を行います。
1.1 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 |
# $OpenBSD: sshd_config,v 1.105 2024/12/03 14:12:47 dtucker Exp $ # This is the sshd server system-wide configuration file. See # sshd_config(5) for more information. # This sshd was compiled with PATH=/usr/local/bin:/usr/bin # The strategy used for options in the default sshd_config shipped with # OpenSSH is to specify options with their default value where # possible, but leave them commented. Uncommented options override the # default value. # To modify the system-wide sshd configuration, create a *.conf file under # /etc/ssh/sshd_config.d/ which will be automatically included below Include /etc/ssh/sshd_config.d/*.conf # If you want to change the port on a SELinux system, you have to tell # SELinux about this change. # semanage port -a -t ssh_port_t -p tcp #PORTNUMBER # Port 2244 #AddressFamily any ListenAddress 0.0.0.0 #ListenAddress :: #HostKey /etc/ssh/ssh_host_rsa_key #HostKey /etc/ssh/ssh_host_ecdsa_key #HostKey /etc/ssh/ssh_host_ed25519_key # Ciphers and keying #RekeyLimit default none # Logging #SyslogFacility AUTH #LogLevel INFO # Authentication: #LoginGraceTime 2m PermitRootLogin prohibit-password #StrictModes yes #MaxAuthTries 6 |
21行目 : #Port 22のコメントを解除し、今回は"Port 2244"に変更して進めていきます
23行目 : #ListenAddress 0.0.0.0の「#」を削除
40行目 : #PermitRootLogin prohibit-passwordの「#」を削除し、管理者権限でサーバーへログインすることを拒否する
SSH の再起動
|
1 |
# systemctl restart sshd.service |
このままでは次に再起動したときSSHによるリモート接続ができなくなるので、次のファイアウォールの設定でSSHポート2244番を解放してください。
2.ファイアウォール(firewalld)の設定方法
Fedoraではファイアウォールはfirewalldがデフォルトに設定されており、OSインストール時に有効になっています。
2.1 「firewalld」を制御するための「firewall-cmd」コマンド使用方法
①firewalld稼働状況確認
|
1 |
# firewall-cmd --state |
「firewalld」が動作している場合は「running」、停止している場合は「not running」と表示されます
または
|
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 |
# systemctl status firewalld ● firewalld.service - firewalld - dynamic firewall daemon Loaded: loaded (/usr/lib/systemd/system/firewalld.service; enabled; preset: enabled) Drop-In: /usr/lib/systemd/system/service.d └─10-timeout-abort.conf Active: active (running) since Thu 2026-04-30 08:05:00 JST; 14min ago Invocation: a3e4514a6f454e0987863ce14a88f928 Docs: man:firewalld(1) Main PID: 1150 (firewalld) Tasks: 2 (limit: 3436) Memory: 47.4M (peak: 47.5M) CPU: 853ms CGroup: /system.slice/firewalld.service └─1150 /usr/bin/python3 -sP /usr/bin/firewalld --nofork --nopid Apr 30 08:04:55 Lepard systemd[1]: Starting firewalld.service - firewalld - dynamic firewall daemon... Apr 30 08:05:00 Lepard systemd[1]: Started firewalld.service - firewalld - dynamic firewall daemon. |
※停止している場合
Active: inactive (dead)と表示され、firewalldが停止していることが分かります
➁「--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 |
# firewall-cmd --add-port=2244/tcp --permanent # firewall-cmd --reload |
3.Windowsからリモート接続
WindowsからターミナルエミュレーターTabby Terminalを使用して接続します。
ユーザー"huong"でログインする
オプション[-p 2244]でSSHポートを指定する
Clink v1.7.6.d9907d
Copyright (c) 2012-2018 Martin Ridgers
Portions Copyright (c) 2020-2024 Christopher Antos
https://github.com/chrisant996/clink
C:\Users\xxxxx>ssh huong@192.168.11.83 -p 2244
huong@192.168.11.83's password: ←ユーザーのパスワード
Web console: https://Lepard:9090/ or https://192.168.11.83:9090/
huong@Lepard:~$
