1. SSH Service Security Settings
Change the configuration file for the SSH service, which is "/etc/ssh/sshd_config".
In this case, we will change the default SSH port 22 to 2244.
Change /etc/ssh/sshd_config as follows
# vim /etc/ssh/sshd_config
Line 14 : Uncommented and changed to connection port 2244
Port 2244
Line 16 : Uncommented
ListenAddress 0.0.0.0
Line 34 : Uncommented(Disable password authentication for root)
PermitRootLogin prohibit-password
Restarting SSH service and setting up automatic startup
# systemctl restart sshd
# systemctl enable sshd
2. Firewall (ufw)
2.1 Install
# pacman -S ufw
# systemctl status ufw
○ ufw.service - CLI Netfilter Manager
Loaded: loaded (/usr/lib/systemd/system/ufw.service; disabled; preset: dis>
Active: inactive (dead)
You can confirm that the ufw service is stopped by displaying "Active: inactive (dead)"
2.2 Enable ufw
# systemctl enable ufw
Created symlink /etc/systemd/system/multi-user.target.wants/ufw.service → /usr/lib/systemd/system/ufw.service.
# ufw enable
Firewall is active and enabled on system startup
# systemctl start ufw
2.3 Firewall rule settings
When ufw is enabled, default firewall rules are applied.
If you enable it as is, you may lose communication with the server, so set basic rules before enabling ufw.
Incoming packets Default rule settings
First, set the rules for incoming packets. The general rule is to deny all incoming packets except for specific communications. Execute "ufw default deny incoming" to basically deny all incoming packets.
# ufw default deny incoming
Default incoming policy changed to 'deny'
(be sure to update your rules accordingly)
Outgoing packets Default rule settings
The general rule is to allow all outgoing packets. Execute "ufw default allow outgoing" to basically allow outgoing packets.
# ufw default allow outgoing
Default outgoing policy changed to 'allow'
(be sure to update your rules accordingly)
2.4 SSH Port Permissions
Enable automatic startup of ufw, but set the permission for SSH connection first, as it may prevent SSH remote connection. Set permission for SSH port 2244 changed above with the following command
# ufw allow 2244/tcp
# ufw reload
2.5 Confirmation of ufw settings
Check the rules configured in the firewall after enabling." ufw status verbose".
# ufw status verbose
Status: active
Logging: on (low)
Default: deny (incoming), allow (outgoing), disabled (routed)
New profiles: skip
To Action From
-- ------ ----
2244/tcp ALLOW IN Anywhere
2244/tcp (v6) ALLOW IN Anywhere (v6)
2.6 To disable ipv6
# vim /etc/default/ufw
Line 7 : Change
IPV6=no
# systemctl restart ufw
3. SSH connection with authentication using public key cryptography
The method is the same as in other distributions, so we omit it.
