Trust Your Technolust

Author: supernatural

Installation and Configuration of Golang 1.21.4 on Debian 12 x64

As the world of software development constantly advances, it’s vital for developers and system administrators to keep their tools up-to-date. This article provides a detailed walkthrough of two scripts designed specifically for Debian 12 x64 systems. The first script covers the download and extraction of Go (Golang) version 1.21.4, and the second script sets up the Go environment for a user named ‘debian’.

Script 1: Downloading and Extracting Golang 1.21.4 on Debian 12 x64

This script is tailored for Debian 12 x64 users. It automatically downloads and extracts Go 1.21.4 to the directory /usr/lib/go-1.21. Execution with root privileges is assumed, achievable either as the root user or using sudo.

#!/bin/bash

# Ensuring wget is installed
apt-get update
apt-get install -y wget

# Downloading Golang 1.21.4
wget https://go.dev/dl/go1.21.4.linux-amd64.tar.gz -P /tmp

# Extracting the tarball to /usr/lib/go-1.21
tar -C /usr/lib -xzf /tmp/go1.21.4.linux-amd64.tar.gz
mv /usr/lib/go /usr/lib/go-1.21

# Cleaning up the downloaded tarball
rm /tmp/go1.21.4.linux-amd64.tar.gz

echo "Golang 1.21.4 has been successfully downloaded and extracted on Debian 12 x64."

This script ensures a clean and conflict-free installation in a dedicated directory, ideal for version management and system stability.

Script 2: Configuring the Go Environment for the ‘debian’ User on Debian 12 x64

The second script is designed to configure the Go environment for a specific user, in this case, ‘debian’. It sets the necessary environment variables and updates the user’s PATH to include the Go binary.

#!/bin/bash

# Target user for Go configuration
TARGET_USER=debian

# Adding Go binary to PATH in .bashrc
echo "export PATH=/usr/lib/go-1.21/bin:\$PATH" | sudo tee -a /home/$TARGET_USER/.bashrc

# Setting Go environment variables
echo "export GOROOT=/usr/lib/go-1.21" | sudo tee -a /home/$TARGET_USER/.bashrc
echo "export GOPATH=/home/$TARGET_USER/go" | sudo tee -a /home/$TARGET_USER/.bashrc
echo "export GOBIN=\$GOPATH/bin" | sudo tee -a /home/$TARGET_USER/.bashrc

# Applying changes
source /home/$TARGET_USER/.bashrc

echo "Golang environment has been successfully set for user 'debian' on Debian 12 x64."

This script makes Go readily accessible for the ‘debian’ user, enabling them to start using Go immediately after the setup. It’s an essential step for maintaining a clean and efficient development environment.


Together, these scripts demonstrate a practical approach to setting up and managing Go environments on Debian 12 x64 systems. They are designed to provide a straightforward and error-free installation and configuration process, enhancing productivity and ensuring consistency across different setups.

Effortlessly Delete Restricted Folders in Windows: A PowerShell Guide for Administrators

TLDR Summary:

This guide provides a step-by-step PowerShell solution for Windows 11 administrators to forcefully delete folders that are otherwise inaccessible due to permission restrictions. It involves taking ownership of the folder, granting full control to the administrator, and then deleting it.

This method is particularly useful when encountering errors like “You require permission from S-1-5-21-xxxx to make changes to this folder.”


Navigating file permissions in Windows 11 can sometimes be a challenging task, especially when trying to delete a folder that denies access. This guide walks administrators through a PowerShell method to bypass these restrictions and delete such folders. It’s particularly helpful when encountering the error “You require permission from S-1-5-21-xxxx to make changes to this folder.”

Opening PowerShell as Administrator:
Start by launching PowerShell with administrative rights. This is crucial for the commands to work, as they require elevated privileges. You can do this by searching for PowerShell in the Start Menu, right-clicking on it, and selecting “Run as administrator”.

Taking Ownership of the Folder:
The first command involves taking ownership of the folder. This is necessary because, without ownership, you cannot change the folder’s permissions. The command takeown is used for this purpose, and it should be executed as follows, replacing Path\To\Folder with the actual path of your folder:

takeown /f "Path\To\Folder" /r /d y

Granting Full Control to the Administrator:
After taking ownership, the next step is to modify the folder’s permissions to grant yourself full control. This step is done using the icacls command. Replace Path\To\Folder with your folder’s path:
icacls "Path\To\Folder" /grant Administrators:F /t
Here, /grant specifies the operation, Administrators:F gives full control to the Administrators group, and /t applies these changes to all items in the folder recursively.

Deleting the Folder Verbosely:
With ownership and permissions set, you can now delete the folder. For this, use the Remove-Item cmdlet in PowerShell with the -Verbose flag for detailed output. The command should be like this:

Remove-Item -Path "Path\To\Folder" -Recurse -Force -Verbose

Script for Automation

For convenience, here’s a script that automates the above steps. Just set the $folderPath variable to the desired folder path:

$folderPath = "Path\To\Folder"  # Replace with your folder path

# Taking ownership
takeown /f $folderPath /r /d y

# Granting full control
icacls $folderPath /grant Administrators:F /t

# Deleting the folder verbosely
Remove-Item -Path $folderPath -Recurse -Force -Verbose

Conclusion
This PowerShell method offers a reliable solution for administrators to handle permission-restricted folders in Windows 11. It’s a valuable tool for system management and troubleshooting, ensuring smooth operation and maintenance.

Creating Custom Swap Space and Adding to FStab on Debian 12

Automating Swap File Creation on Server Images with Insufficient Swap

There are myriad server images available from cloud providers that, while optimized for various tasks, sometimes lack the swap space configurations adequate for personal use-cases. Swap space is essentially a ‘backup’ for RAM. If your system runs out of RAM, it will start using the swap space. This prevents system crashes, but accessing data in swap is slower than RAM.

While adjusting swap space sounds technical, you can automate this process with a simple script. Let’s dive into how this script can be an indispensable tool for setting up your server.

Understanding the Need for Swap

Before diving into the script, it’s important to understand why having a proper swap space matters:

  1. Performance Safety Net: If your applications consume all the available RAM, they can use the swap as an overflow.
  2. Help with Memory Spikes: Temporary spikes in memory usage won’t bring the system to a standstill.
  3. Versatility: Especially crucial for those who juggle multiple applications or workloads on their server.

Prerequisites

  1. Root Access: The script needs elevated privileges to make system-level changes.
  2. Backup: Ensure you’ve backed up any crucial data from your server. While the script is safe to use, it’s always best practice to prepare for unforeseen issues.
  3. Basic Bash Knowledge: Familiarity with Bash is helpful if you want to tweak the script or understand its internals.

The Script: Automating the Process

The heart of the solution is a Bash script. It not only creates the swap file but also sets it up so that the swap file is utilized after a system reboot.

The script performs the following steps:

  1. Allocates a 16GB Swap File: While 16GB is a general recommendation, you can adjust it based on your needs.
  2. Sets Up Proper Permissions: Ensures that the swap file is secure.
  3. Formats and Activates the Swap: Makes it ready for system use.
  4. Ensures Persistence: Adds the swap file to the fstab file, so it’s used after reboots.
  5. Verification: A crucial step to ensure that the swap has been activated and that there are no obvious issues with the fstab entries.

Using the Script

#!/bin/bash

# Ensure script is run as root
if [[ $EUID -ne 0 ]]; then
    echo "This script must be run as root"
    exit 1
fi

# 1. Create a 16GB swap file
fallocate -l 16G /swapfile

# 2. Set the appropriate permissions
chmod 600 /swapfile

# 3. Format the file as swap
mkswap /swapfile

# 4. Activate the swap
swapon /swapfile

# 5. Add to /etc/fstab for persistence after reboot
grep -q "/swapfile" /etc/fstab || echo "/swapfile none swap sw 0 0" >> /etc/fstab

# 6. Verify the swap is active
free -h | grep Swap

# 7. Verify that the fstab file is without syntax errors
echo "Checking /etc/fstab for errors..."
if ! mount -a -O no_netdev,nofail 2>&1 | grep -q "mount:"; then
    echo "/etc/fstab seems to be fine."
else
    echo "There might be an error in /etc/fstab! Please check manually."
fi

Conclusion

Servers are powerful tools, but every tool can benefit from a bit of customization. By leveraging this script, you can ensure that your server is better equipped to handle memory-intensive tasks or unexpected spikes in memory usage. Whether you’re running a personal project or setting up a new server for development, having ample swap space can make a significant difference in performance and stability.

© 2024 TL;DR Tips

Theme by Anders NorénUp ↑