Ubuntu 24.04 LTS cloud server quick configuration.
Xiahua Liu September 28, 2024 #LinuxThis is a personal note post to remind me the steps for basic cloud server configuration on Ubuntu 24.04 LTS.
Update all packages & Linux kernel
The first thing to do is always updating everything, including the Linux kernel.
New User Configuration
If there is only a root
user, you need to add a non-root sudo user for security reasons:
Network Configuration
First make sure networkd
is running.
Then go to /etc/netplan
and check if there is existing configuration yaml file, you need to create one if not.
The yaml content:
network:
version: 2
renderer: networkd
ethernets:
eth0:
dhcp4: no
dhcp6: no
addresses:
- <server_ipv4>/24
- <server_ipv6>/64
routes:
- to: default
via: <setver_gateway_ipv4>
- to: default
via: <setver_gateway_ipv6>
nameservers:
addresses:
- 1.1.1.1
- 1.0.0.1
- 2606:4700:4700::1111
- 2606:4700:4700::1001
You don't need addresses
and routes
if your provider supports dhcp4: yes
or dhcp6: yes
.
Enable DNSSEC
and DNSOverTLS
Enable:
DNSSEC=yes
yes
And restart
SSH Configuration
Add SSH public key
Copy and paste the public key to server:
Configure sshd_config
- Listen on un-conventional SSH port (instead of 22).
- Disable root login.
- Disable passwod authentication.
<newport>no
no
Configure ssh.socket
Because Ubuntu 22.10 and later uses socket-based activation.
You need to edit the ssh.socket
trigger to change the ListenPort
and ListenAddress
settings:
Update SSH client configuration
After you have changed the server settings, make sure to update the settings on the client side:
An example ssh client config file:
<my_server_name>
<ip1>, <ip2>, <ip3>, ...
<user_name>
<ssh_port>
~/.ssh/id_<keyfile>
Restart and test new SSH settings
You want to restart and test the new SSH settings before moving on.
On the client side:
Make sure client can login without any problems. Go back if it doesn't work.
Update nftables
First remove iptables
and ufw
, we are going to use nftables
only.
Add basic nft rules
Edit /etc/nftables.conf
.
ruleset
inet filter {
input {
filter hook input priority filter; policy drop;
<ssh_port> accept
dport : accept, related : accept, invalid : drop }
state vmap { established lo accept
}
forward {
filter hook forward priority filter; policy drop;
}
output {
filter hook output priority filter; policy accept;
}
}
Make sure the <ssh_port>
is correct or you will lose the active SSH session immediately after nftables
restarts.
If it works and you didn't lose the connection, enable it in systemd. Otherwise, reboot to undo the changes.
(Optional) Install and configure fail2ban
This step is optional, but adds more security to our server.
&&
The configuration is simple:
Make sure you have installed nftables
and uninstalled iptables
, ufw
, etc. before installing the fail2ban
package. It will automatically use nftables
as ban actions.