Skip to content

Instantly share code, notes, and snippets.

@TechPreacher
Last active November 8, 2024 06:00
Show Gist options
  • Select an option

  • Save TechPreacher/1d8f497f59b7ac363780c9c662aab1c4 to your computer and use it in GitHub Desktop.

Select an option

Save TechPreacher/1d8f497f59b7ac363780c9c662aab1c4 to your computer and use it in GitHub Desktop.
Ubuntu Server 24.04 Know-how

Ubuntu Server 24.04 Know-how

Network configuration with cloud-init / set static IP

Source:

Find your interface name

ip address show

Edit / create the cloud-init network configuration file

sudo nano /etc/cloud/cloud.cfg.d/50-curtin-networking.cfg

or

sudo nano /etc/netplan/51-my-network-yaml

To set a static IP address, use the addresses key, which takes a list of (IPv4 or IPv6), addresses along with the subnet prefix length (e.g. /24). Gateway and DNS information can be provided as well:

network:
  version: 2
  ethernets:
    eth0:
      addresses:
        - 192.168.1.9/24
      gateway4: 192.168.1.1
      nameservers:
          addresses: [192.168.1.1, 8.8.8.8, 8.8.4.4]

You can find more configuration options at https://netplan.io/examples

Reload the cloud-init configuration. This will reboot your server.

sudo cloud-init clean -r

or

sudo netplan apply

Set Screen Timeout

Source:

Create a file:

sudo nano /etc/systemd/system/enable-console-blanking.service

And put this into the file:

[Unit]
Description=Enable virtual console blanking

[Service]
Type=oneshot
Environment=TERM=linux
StandardOutput=tty
TTYPath=/dev/console
ExecStart=/usr/bin/setterm -blank 1

[Install]
WantedBy=multi-user.target

Then change the file rights and enable the service:

sudo chmod 664 /etc/systemd/system/enable-console-blanking.service
sudo systemctl enable enable-console-blanking.service

And reboot the server. Now the screens blanks after 1 minute without keypresses, even before the login.

Editing the Terminal Font size

Source:

sudo vi /etc/default/console-setup

edit content: FONTSIZE="16x32"

Save, exit and reboot.

Changing display resolution

Source:

Add:

video=HDMI-A-1:1920x1080M@60

as a parameter to the kernel.

Adding parameters to the Kernel

Configuring APC BackUPS Devices in Ubuntu

Source:

When using systemd: This example assumes you are using a APC Smart-UPS 750 via USB.

First, install the apcupsd package via a terminal:

sudo apt-get -y install apcupsd

Next, backup the original configuration files:

sudo cp /etc/apcupsd/apcupsd.conf /etc/apcupsd/apcupsd.conf.bak

Next, edit the configuration files:

sudo nano /etc/apcupsd/apcupsd.conf
UPSNAME smartups750
UPSCABLE usb
UPSTYPE usb
DEVICE 
POLLTIME 60
sudo cp /etc/default/apcupsd /etc/default/apcupsd.bak
sudo nano /etc/default/apcupsd
ISCONFIGURED=yes

Now one may check the status of the UPS via a terminal:

apcaccess status
APC      : 001,027,0660
DATE     : 2015-09-26 18:39:09 -0500  
HOSTNAME : pc
VERSION  : 3.14.12 (29 March 2014) debian
UPSNAME  : smartups750
CABLE    : USB Cable
DRIVER   : USB UPS Driver
UPSMODE  : Stand Alone
STARTTIME: 2015-09-26 18:39:08 -0500  
MODEL    : Smart-UPS 750 
STATUS   : ONLINE 
BCHARGE  : 100.0 Percent
TIMELEFT : 51.0 Minutes
MBATTCHG : 5 Percent
MINTIMEL : 3 Minutes
MAXTIME  : 0 Seconds
ALARMDEL : 30 Seconds
BATTV    : 27.1 Volts
NUMXFERS : 0
TONBATT  : 0 Seconds
CUMONBATT: 0 Seconds
XOFFBATT : N/A
STATFLAG : 0x05000008
MANDATE  : 2010-07-08
SERIALNO : XXXXXXXXXXXX
NOMBATTV : 24.0 Volts
FIRMWARE : COM 02.1 / UPS.05.D
END APC  : 2015-09-26 18:39:19 -0500  

In order to run apctest, one must first stop apcupsd via a terminal:

sudo systemctl stop apcupsd

Otherwise, one may see the following error:

sudo apctest
2015-09-26 18:57:38 apctest 3.14.12 (29 March 2014) debian
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
apctest FATAL ERROR in apctest.c at line 335
Unable to create UPS lock file.
  If apcupsd or apctest is already running,
  please stop it and run this program again.
apctest error termination completed

Then execute:

sudo apctest
2015-09-26 18:59:38 apctest 3.14.12 (29 March 2014) debian
Checking configuration ...
sharenet.type = Network & ShareUPS Disabled
cable.type = USB Cable
mode.type = USB UPS Driver
Setting up the port ...
Doing prep_device() ...

You are using a USB cable type, so I'm entering USB test mode
Hello, this is the apcupsd Cable Test program.
This part of apctest is for testing USB UPSes.

Getting UPS capabilities...SUCCESS

Please select the function you want to perform.

1)  Test kill UPS power
2)  Perform self-test
3)  Read last self-test result
4)  View/Change battery date
5)  View manufacturing date
6)  View/Change alarm behavior
7)  View/Change sensitivity
8)  View/Change low transfer voltage
9)  View/Change high transfer voltage
10) Perform battery calibration
11) Test alarm
12) View/Change self-test interval
 Q) Quit

Select function number:

Once done, start apcupsd:

sudo systemctl start apcupsd

Enabling and configuring UFW Firewall

Source:

Creating a Virtual Host in NGINX

Source:

Install NGINX

If NGINX is not already installed on your server, you can install it using the package manager of your Linux distribution. For Ubuntu or Debian-based systems, use the following commands:

sudo apt update
sudo apt install nginx

Start and Enable NGINX

Ensure NGINX is running and set to start on boot using the systemctl commands:

sudo systemctl start nginx
sudo systemctl enable nginx

Create a Directory for Your Website

Create a directory structure for your website files. This is where you will store your website's content. Use your actual domain name in place of 'your_domain':

sudo mkdir -p /var/www/your_domain/html

Assign ownership and set the correct permissions:

sudo chown -R $USER:$USER /var/www/your_domain/html
sudo chmod -R 755 /var/www

Create a New Configuration File for Your Website

Create a new configuration file in the /etc/nginx/sites-available/ directory. This file will contain the server block settings for your domain:

sudo nano /etc/nginx/sites-available/your_domain

Insert the following configuration, ensuring you replace 'your_domain' with your actual domain name and adjust the document root if necessary:

server {
    listen 80;
    server_name your_domain www.your_domain;

    root /var/www/your_domain/html;
    index index.html;

    location / {
        try_files $uri $uri/ =404;
    }
}

Enable the File by Creating a Link

Activate the server block by linking the file you just created to the sites-enabled directory:

sudo ln -s /etc/nginx/sites-available/your_domain /etc/nginx/sites-enabled/

Test NGINX Configuration

It's crucial to test your NGINX configuration for any syntax errors before restarting the service:

sudo nginx -t

Restart NGINX

If the configuration test is successful, restart NGINX to apply the changes:

sudo systemctl restart nginx

Adjust the Firewall (If Necessary)

If you're using a firewall, ensure that HTTP and HTTPS traffic are permitted.

For UFW users:

sudo ufw allow 'Nginx HTTP'

For firewalld users:

sudo firewall-cmd --permanent --zone=public --add-service=http
sudo firewall-cmd --permanent --zone=public --add-service=https
sudo firewall-cmd --reload
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment