Configure Remote Access for MongoDB on Ubuntu

sudo nano /etc/mongod.conf

Find the network interfaces section, then the bindIp value:

. . .
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1

. . .

Append a comma to this line followed by your MongoDB server’s public IP address:

. . .
# network interfaces
net:
  port: 27017
  bindIp: 127.0.0.1,mongodb_server_ip

. . .

Please note that this should be the IP address of the server on which you’ve installed MongoDB, not the IP address of your trusted remote machine.

sudo systemctl restart mongod

References
https://www.digitalocean.com/community/tutorials/how-to-configure-remote-access-for-mongodb-on-ubuntu-20-04

ASP.NET Authentication with Identity in a Web API with Bearer Tokens & Cookies in .NET 8

We’ll use the in-memory database for this example.

dotnet add package Microsoft.AspNetCore.Identity.EntityFrameworkCore
dotnet add package Microsoft.EntityFrameworkCore.InMemory
dotnet add package Swashbuckle.AspNetCore.Filters
class MyUser : IdentityUser {}
public class DataContext : IdentityDbContext<MyUser>
{
    public DataContext(DbContextOptions<DataContext> options) : base(options)
    {

    }
}

Program.cs

using Microsoft.EntityFrameworkCore;
using Swashbuckle.AspNetCore.Filters;
using WebApplication1;
using WebApplication1.Data;

var builder = WebApplication.CreateBuilder(args);

builder.Services.AddControllers();
builder.Services.AddEndpointsApiExplorer();
builder.Services.AddSwaggerGen(options =>
{
    options.AddSecurityDefinition("oauth2", new Microsoft.OpenApi.Models.OpenApiSecurityScheme
    {
        In = Microsoft.OpenApi.Models.ParameterLocation.Header,
        Name = "Authorization",
        Type = Microsoft.OpenApi.Models.SecuritySchemeType.ApiKey
    });

    options.OperationFilter<SecurityRequirementsOperationFilter>();
});


builder.Services.AddDbContext<DataContext>(options => options.UseInMemoryDatabase("AppDb"));
builder.Services.AddAuthentication();
builder.Services.AddIdentityApiEndpoints<MyUser>()
    .AddEntityFrameworkStores<DataContext>();


var app = builder.Build();

if (app.Environment.IsDevelopment())
{
    app.UseSwagger();
    app.UseSwaggerUI();
}

app.MapIdentityApi<MyUser>();

app.UseHttpsRedirection();

app.UseAuthorization();

app.MapControllers();

app.Run();

In Swagger

References
https://www.youtube.com/watch?v=8J3nuUegtL4
https://devblogs.microsoft.com/dotnet/whats-new-with-identity-in-dotnet-8/

Install .NET 8 on Ubuntu 22.04 using Microsoft package feed

Remove the existing .NET packages from your distribution. You want to start over and ensure that you don’t install them from the wrong repository.

sudo apt remove 'dotnet*' 'aspnet*' 'netstandard*'

Configure your package manager to ignore the .NET packages from the distribution’s repository. It’s possible that you’ve installed .NET from both repositories, so you want to choose one or the other.

touch /etc/apt/preferences
nano /etc/apt/preferences
Package: dotnet* aspnet* netstandard*
Pin: origin "<your-package-source>"
Pin-Priority: -10

Make sure to replace <your-package-source> with your distribution’s package source, for example, on Ubuntu you may use archive.ubuntu.com in the US.

Use the apt-cache policy command to find the source:

apt-cache policy '~ndotnet.*' | grep -v microsoft | grep '/ubuntu' | cut -d"/" -f3 | sort -u
# Get Ubuntu version
declare repo_version=$(if command -v lsb_release &> /dev/null; then lsb_release -r -s; else grep -oP '(?<=^VERSION_ID=).+' /etc/os-release | tr -d '"'; fi)

# Download Microsoft signing key and repository
wget https://packages.microsoft.com/config/ubuntu/$repo_version/packages-microsoft-prod.deb -O packages-microsoft-prod.deb

# Install Microsoft signing key and repository
sudo dpkg -i packages-microsoft-prod.deb

# Clean up
rm packages-microsoft-prod.deb

# Update packages
sudo apt update
sudo apt-get update && \
  sudo apt-get install -y dotnet-sdk-8.0

References
https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu-2204
https://learn.microsoft.com/en-us/dotnet/core/install/linux-ubuntu
https://learn.microsoft.com/en-us/dotnet/core/install/linux-package-mixup?pivots=os-linux-redhat

Install NVIDIA Driver and sign the Kernel module on Fedora 39

sudo dnf install kmodtool akmods mokutil openssl

sudo kmodgenca -a
sudo mokutil --import /etc/pki/akmods/certs/public_key.der

You will be asked to enter a password, it doesn’t have to be very strong, just make sure to remember it. You’ll only need it once during  these steps.

sudo reboot

After reboot you will see MOK Manager interface and will be asked to enroll the key.
First select “Enroll MOK“.
Then “Continue“.
Hit “Yes” and enter the password.
Then select “OK” and your device will reboot again.

sudo dnf install gcc kernel-headers kernel-devel akmod-nvidia xorg-x11-drv-nvidia xorg-x11-drv-nvidia-libs xorg-x11-drv-nvidia-libs.i686
sudo akmods --force
sudo dracut --force
sudo reboot
lsmod | grep -i nvidia

References
https://blog.monosoul.dev/2022/05/17/automatically-sign-nvidia-kernel-module-in-fedora-36/
https://rpmfusion.org/Howto/NVIDIA#Current_GeForce.2FQuadro.2FTesla

Deploy applications in Run as Administrator mode in Windows using PyInstaller and Inno Setup

PyInstaller

venv\Scripts\pyinstaller.exe --noconsole --onefile --icon=images/icons8-anki-512.ico --manifest=MyAnki.exe.manifest --uac-admin -n MyAnki app.py

MyAnki.exe.manifest

<?xml version="1.0" encoding="UTF-8" standalone="yes"?>
<assembly xmlns="urn:schemas-microsoft-com:asm.v1" manifestVersion="1.0">
  <trustInfo xmlns="urn:schemas-microsoft-com:asm.v3">
    <security>
      <requestedPrivileges>
        <requestedExecutionLevel level="requireAdministrator" uiAccess="false" />
      </requestedPrivileges>
    </security>
  </trustInfo>
</assembly>

inno_setup.iss

[Setup]
PrivilegesRequired=admin

 

Setting Up Apache2 with Advanced Features on Ubuntu

In the modern world of web development, Apache2 stands as one of the most robust, reliable, and widely used web servers. This blog post aims to guide you through the installation and configuration of Apache2 on an Ubuntu system, enabling a range of advanced features to maximize its capabilities.

Prerequisites

  • Ubuntu Server (18.04/20.04/22.04 LTS recommended)
  • Terminal access (SSH or direct)
  • Sudo privileges

Step 1: Installing Apache2

Open your terminal and run the following command to install Apache2:

apt-get -y install apache2

The -y flag automatically confirms the installation, saving you from having to do so manually.

Step 2: Enabling Modules

Apache2 is highly modular, allowing you to enable or disable various features according to your needs. To enable a range of advanced modules, execute the following commands:

sudo a2enmod proxy
sudo a2enmod ssl
sudo a2enmod proxy_http
sudo a2enmod proxy_ajp
sudo a2enmod rewrite
sudo a2enmod deflate
sudo a2enmod headers
sudo a2enmod proxy_balancer
sudo a2enmod proxy_connect
sudo a2enmod proxy_html
sudo a2enmod remoteip
sudo a2enmod proxy_fcgi
sudo a2enmod proxy_wstunnel
sudo a2enmod expires

Important: Remember to restart the Apache server after installing new modules for the changes to take effect

Step 3: Editing Configuration File

To apply custom configurations to Apache2, you’ll need to edit its main configuration file. Use the nano editor to open it:

nano /etc/apache2/apache2.conf

Here you can add or modify directives according to your specific needs. After making the desired changes, save and exit the file.

Step 4: Managing the Apache2 Service

After making all the changes, it’s important to restart the Apache2 service for the new configurations to take effect:

sudo systemctl restart apache2

Additionally, you can stop or start Apache2 using the following commands:

  • To stop the service:
    sudo systemctl stop apache2
  • To start the service:
    sudo systemctl start apache2

Conclusion

You’ve successfully installed Apache2 and enabled a host of advanced features, setting a solid foundation for whatever web-based projects you plan to host. This flexible, modular setup ensures you have all the tools you need to build a robust, high-performance web server.

Configure Hysteria on Ubuntu Server

Install or update to the latest version:

bash <(curl -fsSL https://get.hy2.sh/)

Remove Hysteria:

bash <(curl -fsSL https://get.hy2.sh/) --remove
nano /etc/hysteria/config.yaml
listen: :443 

acme:
  domains:
    - example.com    
  email: [email protected] 

auth:
  type: password
  password: password

quic:
  initStreamReceiveWindow: 8388608 
  maxStreamReceiveWindow: 8388608 
  initConnReceiveWindow: 20971520 
  maxConnReceiveWindow: 20971520 
  maxIdleTimeout: 30s 
  maxIncomingStreams: 1024 
  disablePathMTUDiscovery: false 

acl:
  inline: 
    - reject(geoip:ir)
  # geoip: GeoLite2-Country.mmdb 


disableUDP: false
udpIdleTimeout: 60s

+ Take a look at the differences between Hysteria 2 and Hysteria 1 at https://hysteria.network/docs/misc/2-vs-1/
+ Check out the quick server config guide at https://hysteria.network/docs/getting-started/Server/
+ Edit server config file at /etc/hysteria/config.yaml
+ Start your hysteria server with systemctl start hysteria-server.service
+ Configure hysteria start on system boot with systemctl enable hysteria-server.service

References
https://v2.hysteria.network/docs/getting-started/Installation/