Manually set the time on an Ubuntu server

1. Check the current time

Before setting the time, check the current system time by running:

timedatectl

This will display information about your system’s time and time zone.

2. Set the time manually

To set the time manually, use the timedatectl command in the following format:

sudo timedatectl set-time "YYYY-MM-DD HH:MM:SS"

For example, to set the date and time to October 12, 2024, 19:30:00, you would run:

sudo timedatectl set-time "2024-10-12 19:30:00"

3. Disable automatic time synchronization (if needed)

If your server is using NTP (Network Time Protocol) for automatic time synchronization, you may need to disable it before setting the time manually. To do this, run:

sudo timedatectl set-ntp off

4. Verify the new time

After setting the time, you can verify it with:

timedatectl

This will show the updated time and any other related settings.

Update Kernel arguments for better performance in Ubuntu 24.04

Here’s how you can apply these kernel parameters in Ubuntu 24.04:

  1. Edit GRUB Configuration File:

    Open the GRUB configuration file in a text editor. For example, you can use nano:

    sudo nano /etc/default/grub
    
  2. Add Kernel Parameters:

    Find the line that starts with GRUB_CMDLINE_LINUX_DEFAULT and add your parameters to the list. It should look something like this:

    GRUB_CMDLINE_LINUX_DEFAULT="quiet splash mitigations=off mem_sleep_default=s2idle nvidia-drm.modeset=1"
    

    Ensure that all parameters are enclosed within the same set of quotes.

  3. Update GRUB:

    After saving the changes, you need to update the GRUB configuration:

    sudo update-grub
    
  4. Reboot:

    Finally, reboot your system to apply the changes:

    sudo reboot
    

This will apply the desired kernel parameters on all boot entries.

Install Android ADB on Ubuntu Linux

To install Android ADB (Android Debug Bridge) on Ubuntu, you can follow these steps:

Identify the Vendor ID:

Connect your Android device to your computer and run the following command to identify the vendor ID:

lsusb

Look for the line that corresponds to your Android device. The vendor ID is the first part of the ID after ID, for example, 18d1 for Google.

Update Your Package List: Open your terminal and update the package list to ensure you have the latest information on the newest versions of packages and their dependencies.

sudo apt update

Install ADB: You can install the ADB package using the following command:

sudo apt install android-tools-adb

Verify Installation: After installation, you can verify that ADB is installed correctly by checking its version:

adb version

Add Your User to the Plugdev Group (Optional): This step ensures that you can use ADB without root permissions. It’s especially useful when working with devices.

sudo usermod -aG plugdev $USER

Then, log out and log back in to apply the changes.

Set Up Udev Rules (Optional): To communicate with your Android device over USB, you might need to set up udev rules. Create a new udev rules file:

sudo nano /etc/udev/rules.d/51-android.rules

Add the following line to the file, replacing xxxx with your device’s USB vendor ID (you can find a list of these IDs online or in the documentation for your device):

SUBSYSTEM=="usb", ATTR{idVendor}=="18d1", MODE="0666", GROUP="plugdev"

Save and close the file, then reload the udev rules:

sudo udevadm control --reload-rules

Now, you should have ADB installed and configured on your Ubuntu system. You can connect your Android device and start using ADB commands.

Using Data Recovery Tools in Linux

Stop Using the Drive

Immediately stop using the drive to prevent further data overwriting.

Identify the Overwritten Part

Determine how much data the ISO has overwritten. Typically, writing an ISO will overwrite the beginning of the drive, including the partition table and some initial sectors.

Use Data Recovery Tools

You can try using data recovery tools that work well on Linux:

  1. TestDisk: This tool can help recover lost partitions and make non-booting disks bootable again. It can also recover deleted files from FAT, NTFS, and ext2 filesystems.
  2. PhotoRec: This companion tool to TestDisk specializes in recovering lost files, including videos, documents, and archives from hard disks, CD-ROMs, and lost pictures from memory cards.
  3. ddrescue: A data recovery tool specifically designed to recover data from damaged disks. It can create a disk image and then work on the image to recover data.

Steps to Recover Data

  1. Install Recovery Tools:
    sudo apt-get install testdisk photorec gddrescue
    
  2. Create a Disk Image: It’s safer to work on a disk image rather than directly on the hard drive.
    sudo ddrescue /dev/sdX /path/to/image.img /path/to/logfile.log
    

    Replace /dev/sdX with your external hard drive’s identifier.

  3. Run TestDisk:
    sudo testdisk /path/to/image.img
    

    Follow the on-screen instructions to analyze and recover lost partitions.

  4. Run PhotoRec:
    sudo photorec /path/to/image.img
    

    This will guide you through recovering individual files.

Set Battery Charge Limit in Ubuntu

ls /sys/class/power_supply/
ls /sys/class/power_supply/BAT0
sudo sh -c "echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold"
cat /sys/class/power_supply/BAT0/status

Create Battery Charge Threshold Service

sudo nano /etc/systemd/system/battery-charge-end-threshold.service
[Unit]
Description=Set Battery Charge Maximum Limit
After=multi-user.target
StartLimitBurst=0

[Service]
Type=oneshot
Restart=on-failure
ExecStart=/bin/bash -c 'echo 60 > /sys/class/power_supply/BAT0/charge_control_end_threshold'

[Install]
WantedBy=multi-user.target
sudo systemctl enable battery-charge-end-threshold.service
sudo systemctl daemon-reload
sudo systemctl start battery-charge-end-threshold.service

References
https://ubuntuhandbook.org/index.php/2024/02/limit-battery-charge-ubuntu/

Configure Nginx for WordPress on Ubuntu

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

Navigate to /etc/nginx/sites-available. There, create a file with the name example.com. The name should be the same as your domain.

# Redirect HTTP -> HTTPS
server {
    listen 80;
    server_name www.example.com example.com;

    return 301 https://example.com$request_uri;
}

# Redirect WWW -> NON-WWW
server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name www.example.com;

    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;

    return 301 https://example.com$request_uri;
}

server {
    listen 443 ssl http2;
    listen [::]:443 ssl http2;
    server_name example.com;

    root /var/www/html/wordpress;
    index index.php;

    # SSL parameters
    ssl_protocols         TLSv1.2 TLSv1.3;
    ssl_ciphers           HIGH:!aNULL:!MD5;
    ssl_certificate /etc/letsencrypt/live/example.com/fullchain.pem;
    ssl_certificate_key /etc/letsencrypt/live/example.com/privkey.pem;
    ssl_trusted_certificate /etc/letsencrypt/live/example.com/chain.pem;
    ssl_session_timeout 1d;
    ssl_session_cache shared:MozSSL:10m;
    ssl_session_tickets off;
    ssl_prefer_server_ciphers off;
    ssl_stapling on;
    ssl_stapling_verify on;
    resolver 1.1.1.1 1.0.0.1 valid=300s;
    resolver_timeout 30s;

    # log files
    access_log /var/log/nginx/example.com.access.log;
    error_log /var/log/nginx/example.com.error.log;

    location = /favicon.ico {
    log_not_found off;
    access_log off;
    }

    location = /robots.txt {
    allow all;
    log_not_found off;
    access_log off;
    }

    location / {
    try_files $uri $uri/ /index.php?$args;
    }

    location ~ \.php$ {
    include snippets/fastcgi-php.conf;
    fastcgi_pass unix:/run/php/php8.1-fpm.sock;
    }

    location ~* \.(js|css|png|jpg|jpeg|gif|ico|svg)$ {
    expires max;
    log_not_found off;
    }
}

then create a symbolic link to the sites-enabled directory.

sudo ln -s /etc/nginx/sites-available/sample.com /etc/nginx/sites-enabled/sample.com
sudo nginx -t
nginx -s reload

References
https://www.hostinger.com/tutorials/how-to-install-wordpress-with-nginx-on-ubuntu/
https://www.nginx.com/resources/wiki/start/topics/recipes/wordpress/
https://wordpress.org/documentation/article/nginx/

Add More Security to Nginx Configuration

sudo openssl dhparam -out /etc/ssl/certs/dhparam.pem 2048
ssl_dhparam /etc/ssl/certs/dhparam.pem;

ssl_session_timeout 1d;
ssl_session_cache shared:SSL:10m;
ssl_session_tickets off;

ssl_protocols TLSv1.2 TLSv1.3;
ssl_ciphers ECDHE-ECDSA-AES128-GCM-SHA256:ECDHE-RSA-AES128-GCM-SHA256:ECDHE-ECDSA-AES256-GCM-SHA384:ECDHE-RSA-AES256-GCM-SHA384:ECDHE-ECDSA-CHACHA20-POLY1305:ECDHE-RSA-CHACHA20-POLY1305:DHE-RSA-AES128-GCM-SHA256:DHE-RSA-AES256-GCM-SHA384;
ssl_prefer_server_ciphers on;

ssl_stapling on;
ssl_stapling_verify on;
resolver 8.8.8.8 8.8.4.4 valid=300s;
resolver_timeout 30s;

add_header Strict-Transport-Security "max-age=31536000; includeSubDomains" always;
add_header X-Frame-Options SAMEORIGIN;
add_header X-Content-Type-Options nosniff;

References
https://linuxize.com/post/secure-nginx-with-let-s-encrypt-on-ubuntu-20-04/

Install Redis on Ubuntu 22.04

sudo apt install redis-server
sudo nano /etc/redis/redis.conf

Inside the file, find the supervised directive. This directive allows you to declare an init system to manage Redis as a service, providing you with more control over its operation. The supervised directive is set to no by default. Since you are running Ubuntu, which uses the systemd init system, change this to systemd

. . .

# If you run Redis from upstart or systemd, Redis can interact with your
# supervision tree. Options:
#   supervised no      - no supervision interaction
#   supervised upstart - signal upstart by putting Redis into SIGSTOP mode
#   supervised systemd - signal systemd by writing READY=1 to $NOTIFY_SOCKET
#   supervised auto    - detect upstart or systemd method based on
#                        UPSTART_JOB or NOTIFY_SOCKET environment variables
# Note: these supervision methods only signal "process is ready."
#       They do not enable continuous liveness pings back to your supervisor.
supervised systemd

. . .
sudo systemctl restart redis.service

References
https://www.digitalocean.com/community/tutorials/how-to-install-and-secure-redis-on-ubuntu-22-04