Thursday, October 31, 2024

How to Redirect URLs Using Nginx

https://www.rosehosting.com/blog/how-to-redirect-urls-using-nginx

How to Redirect URLs Using Nginx

How to redirect URLs using Nginx

URL redirection, also called URL forwarding, allows multiple URL addresses to be associated with a single page. This can include a form, the entire website, or a web application. This functionality is executed through a specialized HTTP response called an HTTP redirect. Redirecting URLs involves pointing an existing URL to a new one. This effectively communicates to your visitors and search bots that the URL has a new destination. This redirect can be either a temporary or a permanent redirection. Nginx, a web server, has gained more and more popularity over the past few years. It was initially created as a high-performance web server. Using an asynchronous event-driven architecture, Nginx can increase speed and stability when handling high traffic. This article will show you how to redirect URLs using nginx in an easy-to-follow guide.

Prerequisites

  • Linux VPS hosting with Nginx as the web server
  • SSH root access or a normal system user with sudo privileges

Redirection Types

There are only two redirection types: permanent and temporary. The permanent redirection has HTTP code 301, while the temporary redirection has HTTP code 302. The difference between 301 and 302 redirects lies in how they affect the redirection of URLs on a website. This can have a significant impact on your on-page SEO. To clarify, below is an explanation of the differences between 301 and 302 redirects in detail:

Permanent Redirect (301)

As the name indicates, a permanent redirect means the old URL will no longer be used. Visitors will be permanently redirected to the new URL. This means that when visitors access the old URL, they will be automatically redirected to the new URL.

301 redirects also tell search engines that the old URL page has been made permanent and redirected to the new URL. Search engines will pass on any link authority directly from the old URL to the new URL. A 301 redirects are usually used for website pages that have been moved to a new URL or permanently deleted. This is akin to moving your house permanently and letting everyone know your new address.

Temporary Redirect (302)

Redirect 302 is known as a “temporary redirect”. This means the old URL has been moved, and visitors are redirected to the new URL, just like with a 301.

The difference is that a 302 tells search engines that the old URL page is only temporarily redirected to the new URL. This signals to search engines that the old URL will return and will still maintain the page’s ranking of the old URL. As such, a 302 redirect is typically used for website pages that will return to the original URL after a while. Think of this as leaving your house when you go on an extended vacation and have your mail sent there.

Redirects are helpful when you send website visitors to a different URL according to the page they are trying to access. Here are some popular reasons to use them:

  • Reroute visitors from discontinued pages (which would otherwise show a 404 error) to the most similar page.
  • Keep old URLs operational after moving from one software system to another.
  • Take visitors from a short and simple, memorable URL to the correct page.
  • Redirecting outdated .html URLs or non-www to their www counterparts.
  • Retain seasonal page content with limited-time deals; the same offer will return next season. Think of Black Friday count-down timer pages.

When using Nginx as the web server, you can generally create redirects using rewrite or return directives. Incorporating a redirect map can be beneficial for extensive redirect lists.

Use RETURN Directive

We can use the return directive in the server context to redirect HTTP to HTTPS or from one domain name to another.

server {
listen 80;
server_name example.com www.example.com;
return 301 https://example.com$request_uri;
}

The following configuration should also work if you want to redirect a URL to another.

location = /blog/how-to-redirect-in-nginx {
return 301 $scheme://blog.example.com/how-to-redirect-in-nginx
}

Use REWRITE Directive

We can place both RETURN and REWRITE directives in the server and location context in the Nginx configuration file.

server {
listen 80;
server_name example.com www.example.com;
rewrite ^/(.*)$ https://example.com/$1 redirect;
}

We can use the above config to redirect HTTP to HTTPS temporarily. To change it to a permanent redirect, simply replace redirect with permanent.

Another example is to redirect a URL using rewrite, but this time, we use location context.

Need a fast and easy fix?
✔ Unlimited Managed Support
✔ Supports Your Software
✔ 2 CPU Cores
✔ 2 GB RAM
✔ 50 GB PCIe4 NVMe Disk
✔ 1854 GeekBench Score
✔ Unmetered Data Transfer
NVME 2 VPS

Now just $43 .99
/mo

GET YOUR VPS
location = /how-to-redirect-in-nginx {
rewrite ^/how-to-redirect-in-nginx?$ /redirection-in-nginx.html break;
}

Use MAP Directive

If you have many redirections, you can use Nginx MAP directive. Add the following to the top of your Nginx server block file.

map $request_uri $new_uri {
include /etc/nginx/redirect-map.conf;
}

Then, create a file /etc/nginx/redirect-map.conf, and you can put your old and new URLs there.

The file /etc/nginx/redirect-map.conf should contain something like this:

/blog/how-to-redirect-in-nginx /nginx-redirect;
/old.html /new.html;
/old-file.php /new-file.php;

Make sure to check the map file, it should contain ‘;’ at the end of each line or else it causes EOL error. Also, remember that you should restart Nginx every time you modify its configuration file to apply the changes.

That’s it! You have learned about configuring URL redirects in Nginx.

Of course, you don’t have to spend your time and follow this article to learn how to redirect URLs using Nginx. If you have an active VPS hosting service with us, you can ask our expert Linux admins to redirect URLs using Nginx for you. Simply log in to the client area, then submit a ticket. Our system administrators are available 24×7 and will take care of your request immediately.

If you liked this post on how to redirect URLs using Nginx, please share it with your friends on social media or leave a comment below.

Tags , , , , , ,

rbash – A Restricted Bash Shell Explained with Practical Examples

https://www.tecmint.com/rbash-restricted-bash-shell

rbash – A Restricted Bash Shell Explained with Practical Examples

In the world of Linux and Unix-like systems, security is crucial, especially when multiple users share a system. One way to enhance security is by using restricted shells. One such shell is rbash, or Restricted Bash.

This article will explain what rbash is, how it differs from the regular Bash shell, and provide practical examples of its usage.

What is a Shell?

Before diving into rbash, let’s clarify what a shell is.

A shell is a program that enables users to interact with the Linux system through a command-line interface. It interprets commands entered by the user and communicates with the system to execute those commands.

Bash (Bourne Again SHell) is one of the most widely used shells in Linux environments.

What is rbash?

rbash is a restricted version of the Bash shell, which is designed to limit users’ access to certain commands and features, enhancing system security.

When a user logs into a system using rbash, they cannot perform tasks that could compromise the system or other users.

Key Differences Between Bash and rbash

Following are some key differences between bash and rbash:

  • In rbash, users cannot change their directory with the cd command. They can only operate in their home directory.
  • Certain commands like exec, set, and unset are restricted, preventing users from altering the shell’s environment.
  • Users cannot change environment variables that can affect other users or system settings.
  • In rbash, users cannot redirect input or output, making it harder to execute commands that can access or manipulate files outside their designated areas.

These restrictions make rbash suitable for scenarios where you want to provide limited access to users while maintaining a level of security.

When to Use rbash

Here are some situations where using rbash is beneficial:

  • Public Terminals: In environments like libraries or schools where users need access to basic commands but should not tamper with system settings.
  • Shared Servers: On shared systems, rbash can prevent users from accessing other users’ data or critical system files.
  • Testing and Learning Environments: When teaching users basic command-line skills, rbash can help limit their actions to avoid accidental system changes.

How to Set Up rbash in Linux

Setting up rbash on your Linux system is a straightforward process, all you need to do is follow these steps:

1. Install Bash in Linux

Most Linux distributions come with Bash installed by default, you can check if it’s installed by running:

bash --version
Check Bash Version
Check Bash Version

2. Create a Restricted Shell User

You can create a user specifically for rbash.

sudo adduser anusha
Create a Restricted Shell User
Create a Restricted Shell User

After creating the user, change their default shell to rbash:

sudo usermod -s /bin/rbash restricteduser

To further restrict this user’s environment, you can create a specific directory and set it as their home directory:

sudo mkdir /home/anusha/bin

Then, you can place any scripts or commands you want the user to access inside this bin directory.

To limit the commands available to the user, set their PATH variable to only include the bin directory:

echo 'export PATH=$HOME/bin' | sudo tee -a /home/anusha/.bashrc

Now, you can log in as a restricted user:

su - anusha

How to Use rbash in Linux

Let’s explore some practical examples to illustrate how rbash works.

Example 1: Attempting to Change Directory

Once logged in as the restricted user, try changing directories:

cd /tmp

You will receive an error message like -rbash: cd: restricted, which confirms that the user cannot navigate outside their home directory.

Example 2: Running Restricted Commands

Try executing commands like exec or set:

exec bash

You will get an error like -rbash: exec: restricted, which shows that the user is restricted from executing new shell instances.

Example 3: File Redirection

Attempt to redirect output to a file:

echo "Test" > test.txt

You will receive an error message that indicates that users cannot redirect output to files.

-rbash: test.txt: restricted: cannot redirect output

Example 4: Allowed Commands

To see what commands the restricted user can execute, you can create a simple script in their bin directory.

For example, create a file named hello.sh:

echo "echo 'Hello, World!'" > /home/restricteduser/bin/hello.sh
chmod +x /home/restricteduser/bin/hello.sh

Now, when the restricted user runs:

./hello.sh

They will see Hello, World! printed on the screen, demonstrating that they can execute allowed commands.

Conclusion

In summary, rbash is a powerful tool for enhancing security in multi-user Linux environments. By restricting access to certain commands and features, it helps maintain system integrity while allowing users to perform basic tasks.

 

DTrace 2.0 Arrives On Gentoo Linux

https://ostechnix.com/dtrace-2-0-arrives-on-gentoo-linux

Exciting news for Gentoo Linux users! DTrace 2.0, the powerful dynamic tracing tool, is now available on Gentoo. This means you can now analyse and debug your system, both the kernel and userland applications, with ease. Whether you're tackling performance bottlenecks or troubleshooting unexpected behaviour, DTrace has you covered.

What is DTrace?

DTrace allows you to dynamically trace your running system, capturing valuable insights into its operation. It works by attaching to specific points in the kernel or userland applications, known as probes, and recording data when these probes are triggered. This data can include timestamps, stack traces, function arguments, and more, providing a wealth of information to help you understand your system's behaviour.

Gentoo Embraces DTrace 2.0

Gentoo has fully embraced DTrace 2.0, making it incredibly easy to get started. Simply install the dev-debug/dtrace package and you're ready to go. The newest stable Gentoo distribution kernel already has all the necessary kernel options enabled, simplifying the setup process even further. If you're compiling your kernel manually, the DTrace ebuild will guide you through the required configuration changes.

Power of eBPF

Under the hood, DTrace 2.0 for Linux leverages the Extended Berkeley Packet Filter (eBPF) engine of the Linux kernel. eBPF is a powerful and versatile technology that enables efficient and safe in-kernel program execution. By utilizing eBPF, DTrace 2.0 delivers performance and security benefits.

Getting Started with DTrace

Gentoo provides extensive documentation and resources to help you get started with DTrace. The Gentoo Wiki DTrace page offers a comprehensive overview, while the DTrace for Linux GitHub page delves into the technical details. Additionally, the original documentation for Illumos, where DTrace originated, provides valuable insights.

Learn and Explore

With DTrace 2.0 now readily available on Gentoo, there's never been a better time to explore the dynamic tracing. Gentoo's support for DTrace empowers users with a powerful toolset for understanding, analysing, and debugging their systems. Get started with DTrace today and unlock a deeper level of system knowledge!

Resource:

Wednesday, October 30, 2024

Rsnapshot: A Powerful Backup Tool Based on Rsync

https://www.tecmint.com/rsnapshot-a-file-system-backup-utility-for-linux

Rsnapshot is an open-source local/remote filesystem backup utility written in Perl, which leverages the power of Rsync and SSH to create scheduled incremental backups of Linux/Unix filesystems.

Rsnapshot only takes up the space of a single full backup plus the differences, allowing you to store backups on a local drive, external USB stick, NFS-mounted drive, or over the network to another machine via SSH.

In this article, we’ll walk you through the process of installing, setting up, and using Rsnapshot to create hourly, daily, weekly, and monthly local backups, as well as remote backups.

Installing Rsnapshot Backup in Linux

First, you need to install and enable the EPEL (Extra Packages for Enterprise Linux) repository, as Rsnapshot is not included by default in RHEL-based distributions.

sudo dnf install epel-release
sudo dnf install rsnapshot

On Ubuntu-based distributions, rsnapshot is available in the default repositories, so you can install it using the apt package manager:

sudo apt install rsnapshot

Once installed, you can verify the installation by checking the version.

rsnapshot -v

Setting Up SSH Passwordless Login

To back up remote Linux servers, you need to configure SSH for passwordless login between the backup server and the remote machine.

Generate SSH public/private key pairs by following these commands:

ssh-keygen -t rsa

Next, copy the public key to the remote server:

ssh-copy-id user@remote-server

Configuring Rsnapshot in Linux

The configuration file for rsnapshot is located in /etc/rsnapshot.conf, open this configuration file with a text editor like nano or vim:

sudo nano /etc/rsnapshot.conf
OR
sudo vi /etc/rsnapshot.conf

Some of the important settings you’ll need to configure include:

Snapshot Backup Directory

To set the directory where your backups will be stored, you need to edit the snapshot_root line in the configuration file.

snapshot_root   /data/backup/

Set Backup Intervals

Rsnapshot supports multiple backup intervals like daily, weekly, and monthly. You can set how often you want your backups by uncommenting the following lines:

interval    hourly    6
interval    daily     7
interval    weekly    4
interval    monthly   3

Set Backup Directories

To back up local directories, add the directory paths.

backup    /home/     localhost/
backup    /etc/      localhost/

For remote backups, specify the remote server and directory to back up, like so:

backup    root@remote-server:/home/     /data/backup/

Enable Remote Backups

To enable remote backups over SSH, uncomment the cmd_ssh line:

cmd_ssh    /usr/bin/ssh

If you have changed the default SSH port, update the ssh_args line to reflect the custom port (e.g., port 7851):

ssh_args    -p 7851

Exclude Files and Directories

You can exclude certain files and directories from being backed up by creating an exclude file.

sudo nano /data/backup/exclude.txt

Add exclusions in the following format:

- /var/cache
- /tmp
+ /etc
+ /home

In your rsnapshot.conf file, reference the exclude file:

exclude_file    /data/backup/exclude.txt

After configuring Rsnapshot, verify that your setup is correct by running:

sudo rsnapshot configtest

You should see the message “Syntax OK“. If there are any errors, fix them before proceeding.

Finally, you can run Rsnapshot manually using the command for the interval you want to back up:

sudo rsnapshot hourly

Automating Rsnapshot with Cron

To automate the backup process, configure cron jobs to run Rsnapshot at specific intervals by adding the following to your /etc/cron.d/rsnapshot file:

0 */4 * * *    root    /usr/bin/rsnapshot hourly
30 3 * * *     root    /usr/bin/rsnapshot daily
0 3 * * 1      root    /usr/bin/rsnapshot weekly
30 2 1 * *     root    /usr/bin/rsnapshot monthly

Setting Up Rsnapshot Reports

Rsnapshot includes a script to send backup reports via email. To set it up, copy the script and make it executable:

sudo cp /usr/share/doc/rsnapshot/utils/rsnapreport.pl /usr/local/bin/
sudo chmod +x /usr/local/bin/rsnapreport.pl

Now, edit your rsnapshot.conf file and add the --stats flag to the rsync_long_args section:

rsync_long_args --stats --delete --numeric-ids --delete-excluded

Then, add the report to your cron job to email the report:

0 */4 * * * root /usr/bin/rsnapshot hourly 2>&1 | /usr/local/bin/rsnapreport.pl | mail -s "Hourly Backup Report" you@example.com

Monitoring Rsnapshot Backups

You can monitor your backups by checking the log files. By default, Rsnapshot logs backup activities in /var/log/rsnapshot.log.

cat /var/log/rsnapshot.log
Conclusion

Rsnapshot is an excellent choice for managing backups on Linux systems. With its efficient use of rsync, you can easily back up your files locally and remotely.

Tuesday, October 29, 2024

https://www.rosehosting.com/blog/fstab-options

Fstab options: What are they, and when should you use them?

Fstab Options

What is fstab in Lunix? What are fstab options, and when should you use them? Our latest tutorial covers all the fstab details and everything you need to know about this file. Let’s get straight into it.

Table of Contents

What is fstab?

Fstab stands for files system table and is a system file found in the /etc directory on the Linux server. The fstab file lists the available disk partitions and other disk-related file systems.

The mount command reads it and automatically mounts most entries during system boot. A set of rules in the fstab command controls how the system treats different filesystems each time it introduces them. The system administrators handle the maintenance of the fstab command.

The structure of the fstab command

Fstab stands for files system table. The six-column structure of that table requires setting up parameters in each column in the correct order. We will explain the columns separately, and important to know is that they are as follows from left to right:

[Device] [Mount Point] [File System Type] [Options] [Dump] [Pass]

Let’s explain all these in more detail:

Device: The UUID of the mounted device. (sda, sdb, etc.)

Mount Point: Your root file system mounts the device on this directory. The names of the mount points must not have spaces between them.

File System Type: Type of file system. It can be vfat, ntfs, ext4, ext3, etc.

Options: Options depend on the file system. It lists any active mount options. If there are multiple options, they must be separated by commas.

Dump (Backup Operation): The backup operation can have two values, 0 OR 1. If the value is 0, then there is no backup. It is disabled. Otherwise, if it is 1, then the backup of the partition is enabled. System administrators set this field to 0, as it uses an obsolete method they should avoid.

Pass (File System Check Order): The file system check determines the partition checking order during system boot. If the value is 0, then the fsck (file system check) will not check the filesystem. If the value is higher than 0 and is 1, then the order check should be set for the root filesystem. The other partitions should be set with 2, etc.

The usage of the fstab command

System administrators use the fstab for internal devices, CD/DVD drives, and network shares. Additionally, system administrators can add removable devices to fstab. System administrators configure partitions listed in fstab to mount automatically during boot. Only root users can see and mount partitions not listed in fstab. As we already explained the structure of the fstab command, we will now look at the content of the /etc/fstab file. To do that, execute the following command:

cat /etc/fstab

You should get an output similar to this:

root@host:~# cat /etc/fstab 
# /etc/fstab: static file system information.
#
# Use 'blkid' to print the universally unique identifier for a
# device; this may be used with UUID= as a more robust way to name devices
# that works even if disks are added and removed. See fstab(5).
#
# systemd generates mount units based on this file, see systemd.mount(5).
# Please run 'systemctl daemon-reload' after making changes here.
#
#                
# / was on /dev/vda1 during installation
UUID=1fa0d2dd-2039-44cf-bd49-c2c765693d9a / ext4 errors=remount-ro 0 1     1
/dev/vda2    none    swap    sw  0   0

As you can see, the fstab has the following parameters:

Device: UUID=1fa0d2dd-2039-44cf-bd49-c2c765693d9a

Mount Point: /

File System Type: ext4

Options: errors=remount-ro

Dump (Backup Operation): 0

Pass (File System Check Order): 1

Useful Commands

There are some useful commands that you can use for listing drives, mounting, and creating mount points.

1. To get a list of all UUIDs, you can use the following command:

ls -l /dev/disk/by-uuid

You will get an output similar to this:

root@host:~# ls -l /dev/disk/by-uuid
total 0
lrwxrwxrwx 1 root root 10 Aug 10 06:34 1fa0d2dd-2039-44cf-bd49-c2c765693d9a -> ../../vda1
lrwxrwxrwx 1 root root 10 Aug 10 06:34 706a6c4b-2cb1-4de0-899d-1e858ac12204 -> ../../vda2

2. To list the drivers and relevant attached partitions, you can use the command below:

sudo fdisk -l

Giving you an output similar to the below:

root@host:~# fdisk -l
Disk /dev/vda: 80 GiB, 85899345920 bytes, 167772160 sectors
Units: sectors of 1 * 512 = 512 bytes
Sector size (logical/physical): 512 bytes / 512 bytes
I/O size (minimum/optimal): 512 bytes / 512 bytes
Disklabel type: dos
Disk identifier: 0x076a3d03

Device     Boot     Start       End   Sectors  Size Id Type
/dev/vda1  *         2048 165675008 165672961   79G 83 Linux
/dev/vda2       165675009 167772159   2097151 1024M 82 Linux swap / Solaris

3. To mount all file systems in /etc/fstab, you can use the following command:

sudo mount -a

4. To create a new mount point, using root privileges, you can use the command below:

sudo mkdir /path/to/mountpoint

5. To check the content of the fstab, we already mentioned the command in the previous paragraph:

cat /etc/fstab

Any other fstab options?

Of course. Though these are some basic fstab options for entry-level use on a Linux OS. If you have any other suggestions or questions, drop a comment down below and we’ll try to help out as soon as we can.

If you have issues using command-line code, you can always contact our technical support. All our fully-managed plans include 24/7 support, and our admins will help you immediately.

 

 https://www.rosehosting.com/blog/best-open-source-hosting-control-panels-for-2024

Best Open Source Hosting Control Panels for 2024

Best Open Source Hosting Control Panels for 2024

What are the best open-source hosting control panels in 2024? With a slew of options to choose from, we’ll cover the most popular ones to help you reach a decision. A web hosting control panel is software for system administrators, developers, and website users alike. Their primary use lies in managing the server and software on those servers, such as websites and webmail.

Managing the server via the control panel offers many features, including

  • User account management
  • Database management
  • File management
  • Domains adding and forwarding
  • Modifying PHP settings,
  • Changing DNS settings
  • Installing SSL certificates
  • Monitoring uptime
  • …and much more

Hestia Control Panel

The Hestia Control panel is a free and open-sourced hosting control panel that is a fork of the Vesta control panel. It offers a variety of features and has become a significant competitor to premium paid control panels. Using the Hestia Control panel is cost-effective because it provides almost the same features as the paid ones, such as managing user accounts, installing SSL certificates, backups, CMS installations in one click, DNS zone management, etc.

Hestia Control panel supports Ubuntu 22.04, Ubuntu 20.04, Debian 10, 11, and 12. Installation of the Hestia CP is simple: download and execute the bash script, which may take up to 15 minutes. Once the panel is installed it can be accessed on the IP address and the port 8083 using the admin username and password displayed after completion of the installation. The Hestia Control panel is modern and easy to use, and you will not regret choosing it.

Webmin

Webmin is a free and open-sourced hosting control panel developed among the oldest control panels. It offers several features, including Support for cloud and virtualized environments, Interface customization, a File manager, Backup configuration, SSH configuration, Apache management, MySQL management, FTP management, and firewall configuration. Webmin is suitable for system administrators with more experience than beginners. It is not a beginner-friendly control panel, but the offered and free features make it one of the most used open-sourced web hosting panels.

CyberPanel

The cyber panel is a free and open-sourced hosting control panel developed and powered by OpenLiteSpeed. Its interface is modern and user-friendly and has many features for managing Users, Websites, Packages, Databases, DNS, Email, FTP, Backup, Incremental Backup, SSL, and many more. One thing that makes this control panel unique is its LiteSpeed Web server, among the Apache and Nginx. Also, this control panel is suitable for developers because it offers Docker management containerization and a staging environment for websites. One-click installations exist for the most popular applications, such as WordPress, Joomla, and Drupal. On top of all, CyberPanel offers a graphic interface for Docker application management. It is entirely free, and choosing it will make your work easier.

Ajenti

Ajent is a free, open-source hosting control panel with a fast and responsive web interface. It is built to configure and monitor services such as Apache, MySQL, Nginx, FTP, File System Management, Firewall, and many more system administrator-related tasks. Ajenti supports Debian greater than Debian 9, Ubuntu 18.04 or later, and AlmaLinux 8. The interface is similar to the Webmin interface, but the one thing that makes this control panel usable is that it has a mobile-friendly interface, and you can manage your server through your mobile device.

ISPConfig

ISPConfig, is a free and open-sourced control panel. It provides a vibrant feature set such as load balancing, clustering, user and reseller management, DNS service, and Database services, and works with Apache and Nginx from the web servers. ISPConfig is best suited for system administrators and advanced users. It has vast community support and is supported on Debian 10, Debian, 11, Debian 12, Ubuntu 18.04, Ubuntu 20.04, and Ubuntu 22.04

aaPanel

aaPanel is a free and open-sourced hosting control panel that offers the most features of the other free control panels. The features are divided in categories such as Core Functions, Website Manager, Environment, System Tools, aaPanel plugin, Storage plugin, and one-click deploy website. Let’s explain these in more detail:

Core Functions: This section is about the LAMP, LEMP stacks, Database manager, FTP Manager, Crontab manager, File System etc.

Website manager: In this section, we have Backup and restore as features, PHP management, ReverseProxy, Redirects, SSL installation, etc

Environment: This section manages phpMyAdmin, MongoDB, Memcached, Tomcat, PureFTP, Redis, PM2 manager, and many more.

System Tools: The System Tools section contains a Firewall, Logs, Supervisor, and Linux Tools.

aaPanel Plugin: The aaPanel section includes features such as One-click migration, One-Click website deployment, SSH Terminal, DNS Manager, Fail2ban, etc.

Storage plugin: This is for storage only. From storage, you are offered FTP storage, AWS S3 storage, GoogleCloud Storage, and Google Drive storage.

One-click deploy website: With one-click deploy, we can install the most popular software, such as WordPress, Laravel, Joomla, Drupal, Roundcube, etc.

Conclusion

We discussed the most used and best open-source hosting control panels in the previous paragraphs. Before you choose the right control panel, you can always find a tutorial on our blog on how to install it on your computer or virtual machine and test it. Of course, suppose you do not have experience with any Linux distro and control panels. In that case, you can always contact us, and our admins will help you with any aspect of it, like installation, configuration of your control panel, etc. You simply sign up for one of our NVMe VPS plans and submit a support ticket. We are available via live chat and tickets 24/7.

If you liked this post about the Best Open-Source Hosting Control Panels for 2024, please share it with your friends or leave a comment below.

Tags , , , , , , ,

 

11 Useful X-window (GUI Based) Linux Commands – Part I

 https://www.tecmint.com/x-based-commands-for-linux

11 Useful X-window (GUI Based) Linux Commands – Part I

We, the Tecmint Team, are dedicated to creating high-quality articles about Linux and open-source topics. Since we started, we’ve put in a lot of effort to provide our readers with useful and interesting information. We’ve also created many shell programs, from fun commands to helpful tools.

Here are some of our most notable examples:

In this article, we will provide a few X-based commands that are generally available in most standard distributions today. If you find that any of the X-based commands listed below are not installed on your system, you can always use apt or yum to install the required packages.

1. xeyes Command

The xeyes command displays a graphical pair of eyes that follow your mouse movements. While it may seem more amusing than useful, its novelty makes it enjoyable to use.

Simply run xeyes in the terminal and watch the eyes track your mouse pointer.

xeyes
Xeyes - Show Graphical Pair of Eyes
Xeyes – Show a Graphical Pair of Eyes

2. xfd Command

The xfd command displays all the characters in a specified X font. It creates a window showing the name of the font being displayed.

xfd -fn fixed
Using xfd to Display Fonts
Using xfd to Display Fonts

3. xload Command

The xload command outputs a graphical representation of the system load average for the X server, which is an excellent tool for monitoring real-time average system load.

xload -highlight blue
xload - Visualize System Load on Linux
xload – Visualize System Load on Linux

4. xman Command

Most users are familiar with the man command for accessing manual pages. However, many may not know that there is an X version called xman, which provides a graphical interface for man pages.

xman -helpfile cat
Xman: A Graphical Interface for Man Pages
Xman: A Graphical Interface for Man Pages

5. xsm Command

The xsm command stands for “X Session Manager“, which acts as a session manager, grouping applications that refer to a particular state.

xsm
xsm - Managing X Sessions
xsm – Managing X Sessions

6. xvidtune Command

The xvidtune command is a video mode tuner for Xorg, which provides a client interface to the X server’s video mode extension.

xvidtune
xvidtune: A Video Mode Tuner for Xorg
xvidtune: A Video Mode Tuner for Xorg

Note: Incorrect use of this program can cause permanent damage to your monitor and/or video card. If you don’t know what you are doing, avoid making changes and exit immediately.

7. xfontsel Command

The xfontsel application provides a simple way to display the fonts known to your X server.

xfontsel
xfontsel to List Fonts on Your X Server
xfontsel to List Fonts on Your X Server

8. xev Command

The xev command stands for “X events“, which prints the content of X events, helping users understand input events generated by the X server.

xev
xev - Analyze X Events
xev – Analyze X Events

9. xkill Command

The xkill command allows you to kill a client application by clicking on its window, which can be particularly useful for terminating unresponsive applications quickly.

xkill

10. xset Command

The xset command is used to set various user preferences for the X server, that can be used to control keyboard and mouse settings, including screen saver options.

xset q

11. xrandr Command

The xrandr command is a command-line interface to the X11 Resize and Rotate extension, which can be used to set the size, orientation, and reflection of the outputs for a screen.

xrandr
Conclusion

That’s all for now! We plan to post at least one more article (Useful X-based Commands) in this series, and we are actively working on it. Until then, stay tuned and connected to Tecmint.

Don’t forget to share your valuable feedback in our comment section.

Tuesday, October 22, 2024

Introduction To ELF In Linux: A Simple Guide To Executable Files

 https://ostechnix.com/elf-in-linux

Introduction To ELF In Linux: A Simple Guide To Executable Files

If you've ever wondered how programs run on Linux, you might be surprised to learn that a special file format called ELF, or Executable and Linkable Format, is at the heart of it all.

ELF files are essential for various types of files you encounter on your system, including executable files that launch programs, object files used during the programming process, shared libraries that allow multiple programs to use the same code, and core dumps that help diagnose crashes.

In this article, we'll break down what ELF is, how it works, and why it's so important for Linux users and developers.

We'll also look at the different kinds of ELF files, explain the structure of an ELF file in simple terms, and discuss why understanding ELF can help you better navigate and manage your Linux system.

Whether you're a beginner or just curious about the technical side of Linux, this guide will help you grasp the basics of ELF and its role in making your computer run smoothly.

What is ELF in Linux

In Linux, ELF stands for Executable and Linkable Format. It is a standard file format for executables, object code, shared libraries, and core dumps. Linux, along with other UNIX-like systems, uses ELF as the main format for binary files.

Executable and Linkable Format (ELF) in Linux
Executable and Linkable Format (ELF) in Linux

Here’s a breakdown of what ELF is used for and how it works:

1. Executable Files

ELF is the format for binary executables that can be run directly by the Linux operating system. It contains machine code that the CPU can execute.

2. Object Files

These are intermediate files generated by compilers (like gcc). They contain code and data that are not yet linked into a complete program. ELF serves as the format for these files, allowing linking tools like ld to create the final executable.

3. Shared Libraries

ELF files are used for shared libraries (.so files), which allow code to be reused across different programs without including it statically in each executable.

4. Core Dumps

When a program crashes, the Linux system may generate a core dump. This is an ELF file that contains the memory and state of the program at the time of the crash, which is useful for debugging.

Structure of an ELF File

An ELF file is divided into different sections, each with specific roles:

  • Header: Contains information about how to interpret the rest of the file.
  • Program Header: Describes segments that need to be loaded into memory.
  • Section Header: Provides details about individual sections like text (code), data, and symbol tables.
  • Text Segment: Contains the actual executable code.
  • Data Segment: Contains global variables and dynamic data used by the program.

The use of ELF simplifies program development and execution because it provides a unified format for both executables and libraries.

It also supports dynamic linking, which allows programs to use shared libraries at runtime, reducing memory usage and enabling easier updates.

You now know what ELF is, and you may be wondering how to view the details of ELF files. Believe me, it's easier than you might think.

Display Information about ELF Files

You can use several commands and tools in Linux to display information about ELF files. Some of the most common ones are file, readelf, and objdump.

1. Using the file Command

The file command quickly identifies the type of a file, including whether it’s an ELF file, and provides basic information about it.

file <filename>

Example:

file /bin/ls

Sample Output:

/bin/ls: ELF 64-bit LSB pie executable, x86-64, version 1 (SYSV), dynamically linked, interpreter /lib64/ld-linux-x86-64.so.2, BuildID[sha1]=15dfff3239aa7c3b16a71e6b2e3b6e4009dab998, for GNU/Linux 3.2.0, stripped
Display Information about ELF Files
Display Information about ELF Files

2. Using the readelf Command

readelf is a more detailed tool specifically designed for examining the contents of ELF files. You can use it to display headers, section details, and more.

Basic usage:

readelf -h <filename>  # Displays ELF header information

Example:

readelf -h /bin/ls
Viewing Details of ELF File using readelf command
Viewing Details of ELF File using readelf command

You can also use different flags to get more detailed information:

  • -S: Lists the sections in the ELF file.
  • -l: Displays the program headers (used by the loader).
  • -r: Shows the relocation entries.
  • -s: Displays the symbol table (if present).

Example:

readelf -S /bin/ls  # Lists all sections

3. Using the objdump Command

objdump is a more comprehensive tool that can disassemble ELF binaries and display information about them. It shows sections, disassembled code, and more.

Basic usage:

objdump -h <filename>  # Displays the section headers

Example:

objdump -h /bin/ls
Find Information about ELF File using objdump Command
Find Information about ELF File using objdump Command

Other useful flags:

  • -d: Disassembles the file and shows machine code.
  • -x: Displays all headers, including the ELF and section headers.
  • -s: Displays the contents of all sections (in hexadecimal).

Example:

objdump -d /bin/ls  # Disassemble and view the assembly code

Summary of Tools:

  • file: Quick summary of the file type and basic ELF details.
  • readelf: Detailed ELF file structure and headers.
  • objdump: Disassembling and more in-depth inspection of sections and headers.

These tools are typically pre-installed on most Linux distributions. If you need specific information, readelf and objdump will be your most detailed options.

Analyze ELF Binaries with Binsider

Apart from the pre-installed tools, there is a new TUI tool called Binsider to view and analyze BLF binaries in Linux. Binsider offers a comprehensive suite of features, including static and dynamic analysis, allowing users to examine the structure and behaviour of binaries.

Binsider provides a user-friendly terminal interface, enabling users to inspect strings, linked libraries, perform hexdumps, and modify binary data. The tool aims to empower users with the ability to understand the inner workings of ELF binaries and identify potentially interesting data. For more details, refer the following guide:

Why ELF is Important in Linux

For the average Linux user, knowing how to examine ELF files using tools like file, readelf, or objdump may not seem essential at first. But, there are practical situations where this knowledge becomes useful. Here's how it can help in everyday tasks:

1. Identifying File Types and Troubleshooting

Purpose:

Sometimes, a file might have no extension, or its extension could be misleading. Using the file command to determine whether it's an ELF binary, script, or data file can clarify what kind of file you are dealing with.

Example:

If you downloaded a file and are unsure whether it’s a valid executable or corrupted, file will quickly tell you whether it’s a valid ELF file.

file myfile

If the file is not an ELF executable, the command can guide you in troubleshooting further (e.g., figuring out if it's a text file or needs different handling).

2. Verifying System Executables

Purpose:

Using readelf or file allows you to inspect system binaries and libraries to verify they are in the expected format. For instance, after a system upgrade or during troubleshooting, you can ensure that your important binaries (e.g., /bin/bash, /bin/ls) are intact and correctly formatted as ELF files.

Example:

If a system utility is acting strangely, checking if the file is valid and has not been corrupted or replaced can help:

file /bin/bash

3. Understanding Program Dependencies

Purpose:

The readelf -l or objdump command helps identify the shared libraries an executable depends on. If a program fails to run due to missing libraries, this information is useful for troubleshooting missing dependencies.

Example:

If a program complains about missing libraries, running:

readelf -d /usr/bin/ls | grep NEEDED

Will show which libraries are required, helping you install any missing ones.

Sample Output:

 0x0000000000000001 (NEEDED)             Shared library: [libselinux.so.1]
 0x0000000000000001 (NEEDED)             Shared library: [libc.so.6]

4. Analyzing Security and Permissions

Purpose:

Checking whether a binary is dynamically or statically linked, or whether it has unusual headers, can be useful for advanced users concerned about security.

Example:

If you suspect that a binary has been tampered with or could contain malicious code, inspecting its ELF structure using readelf could give insight into whether it behaves unexpectedly, such as having uncommon sections or unknown dependencies.

5. Debugging and Development

Purpose:

For users doing any kind of development, including scripting or compiling, knowing the ELF structure is useful for debugging. Tools like readelf help ensure that your compiled code links properly, uses the correct libraries, and behaves as expected.

Example:

When compiling your own software, you can inspect object files (.o) or the final binary:

readelf -h myprogram

6. Diagnosing Crashes or Core Dumps

Purpose:

If a program crashes and creates a core dump (an ELF file), you can inspect the core dump to analyze the state of the program at the time of the crash, making it easier to identify the cause of the failure.

Example:

If you want to analyze a core dump, running:

readelf -h <core>

provides a starting point for understanding the crash.

7. Performance Optimization

Purpose:

Advanced users looking to optimize their systems can analyze binaries to see if they’re dynamically linked or statically linked, how many sections are loaded into memory, and other performance-related characteristics.

Example:

Using objdump to inspect the machine code or linked sections of a program can help users or developers identify inefficient code.

For an average Linux user, these commands may not be used daily, but they become handy when troubleshooting system issues, verifying file integrity, understanding program dependencies, or debugging software.

Conclusion

The Executable and Linkable Format (ELF) is an important part of how Linux works. It helps your computer run programs smoothly by organizing different types of files, like executable files, object files, shared libraries, and core dumps. Understanding ELF can make it easier for you to troubleshoot issues and optimize your system.

 

Sunday, October 13, 2024

Learn MySQL: Create, Update, and Delete Data in Database

https://www.tecmint.com/basic-mysql-commands

A database is a structured set of data stored electronically. The concept of a database was known to our ancestors even when there were no computers. However, creating and maintaining such databases was a very tedious job. For instance, in a manual database of 100 pages, searching for all employees whose salaries were less than 10,000 would have been quite difficult.

In today’s world, you cannot escape databases. Right now, millions of databases are working around the world to store and fetch data of every kind, whether it be strategic data, employee records, or web technologies.

Databases are often termed as backend processes because they are neither visible to end users nor do end users interact directly with the database. Instead, they work on frontend processes like PHP, VB, ASP.NET, etc., and ask the frontend to deal with the database in the backend.

There are several database servers and clients available, such as Oracle, MySQL, MySQLi, MariaDB, and MongoDB. The syntax for all of these is more or less the same. Mastering one means gaining control over most of them, and learning the queries of a database is both easy and enjoyable.

Let’s start with simple queries on databases. We will use MySQL, which comes bundled with most Linux distributions by default. You can install it manually from the repository if it is not installed by default in your case.

A database query is a simple piece of code sent to the database to obtain custom and refined results as required.

Install MySQL Database in Linux

Use the “yum” or “apt” package manager to install the MySQL database.

sudo yum install mysql mysql-client mysql-server  (on Yum-based systems)
sudo apt install mysql mysql-client mysql-server  (on Apt-based systems)

Once installed, start the MySQL database service with:

sudo systemctl start mysqld
Or
sudo systemctl start mysql

Installing a fresh copy of the MySQL database will take you to a configuration step where you will be asked to set up an root password and answer questions regarding security settings.

sudo mysql_secure_installation

Once you finish installing and securing the server, go to your MySQL prompt.

sudo mysql -u root -p
MySQL Shell Prompt
MySQL Shell Prompt

Now, executing queries at this prompt is both educational and enjoyable.

Create a MySQL Database

Create a database named “tecmint“.

create database tecmint;

Note: The message indicates that the query was successful, meaning the database is created.

You can verify your newly created database by running:

show databases; 

Notice your database in the output below.

Create a MySQL Database
Create a MySQL Database

Create Tables in MySQL Database

Now you need to select the database to work on:

use tecmint;

Here we will create a table called “minttec” with three fields:

CREATE TABLE minttec (
    id INT(3), 
    first_name VARCHAR(15), 
    email VARCHAR(20)
);

Note: The above query returns “OK“, indicating that the table was created without any errors.

To verify the table, run the following query:

show tables; 

You can view the columns you created in the “minttec” table as follows:

Create Tables in MySQL Database
Create Tables in MySQL Database

Anyway, let me explain the types of declarations and their meanings.

  • INT is an Integer.
  • VARCHAR is a character type with a variable length as defined. The value after the type indicates the maximum length of the field in which it can store data.

Add Columns in MySQL Database

Now, we need to add a column named ‘last_name‘ after the column ‘first_name‘:

ALTER TABLE minttec ADD last_name VARCHAR(20) AFTER first_name;

Verify the change in your table:

show columns from minttec; 
Add Column in MySQL Database
Add Column in MySQL Database

Now we will add a column named ‘country‘ to the right of the email field:

ALTER TABLE minttec ADD country VARCHAR(15) AFTER email; 

Verify the column addition:

show columns from minttec; 
Verify Column in MySQL Database
Verify Column in MySQL Database

Insert Values into Fields of MySQL Database

Now let’s insert values into the fields:

INSERT INTO minttec VALUES ('1', 'Ravi', 'Saive', 'raivsaive@xyz.com', 'India');

Now let’s insert multiple values at once into the table.

INSERT INTO minttec (id, first_name, last_name, email, country) VALUES 
  ('2', 'Narad', 'Shrestha', 'narad@xyz.com', 'India'), 
  ('3', 'user', 'singh', 'user@xyz.com', 'Aus'), 
  ('4', 'tecmint', 'com', 'tecmint@gmail.com', 'India');

Verify the inserted values:

select * from minttec; 
Verify Values in MySQL Database
Verify Values in MySQL Database

The values have been inserted successfully.

Update Values in MySQL Table

Now, how about changing the last name of the user whose first name is “Narad“?

UPDATE minttec SET last_name = 'Shrestha' WHERE first_name = 'Narad';

Check to verify the changes.

select * from minttec; 
Update Values in Table
Update Values in Table

Delete Values from MySQL Table

What about deleting a row from the table? For example, let’s delete the last entry of the user whose first name is “tecmint“.

DELETE FROM minttec WHERE first_name = 'tecmint';

Now, check the entries after the deletion.

select * from minttec; 
Delete Values in Table
Delete Values in Table

Now, as you can see, the user “tecmint” has been deleted successfully.

Rename Table in MySQL

To rename a table in MySQL, you can use the RENAME TABLE statement. Let’s say you want to rename the table minttec to users. You would run the following command.

RENAME TABLE minttec TO users;

After renaming the table, you can verify the change by listing the tables in your current database:

SHOW TABLES;
Rename Table in Database
Rename Table in Database

Backup a Database

To back up a MySQL database, you can use the mysqldump command, which creates a logical backup by generating a SQL script file containing all the commands to recreate the database.

mysqldump -u root -p tecmint > tecmint_backup.sql

You can verify that the backup file was created by listing the files in your current directory:

ls -l tecmint_backup.sql

Restore a Database

To restore a MySQL database from a backup file, you can use the mysql command.

mysql -u root -p tecmint < tecmint_backup.sql

Make sure the database you are trying to restore to already exists. If it doesn’t, you can create it using:

mysql -u root -p -e "CREATE DATABASE tecmint;"
Conclusion

You have now learned the basics of creating and manipulating a MySQL database, including creating a database, creating tables, inserting records, updating records, deleting records, and dropping tables. This foundation is essential for working with databases effectively.