Linux - Knowledge Base Archives - Hivelocity Hosting https://www.hivelocity.net/kb/tag/linux/ Dedicated Servers, Private Cloud & Colocation Mon, 21 Oct 2024 16:32:40 +0000 en-US hourly 1 https://wordpress.org/?v=6.6 Text Editors in Linux and How to Use Them https://www.hivelocity.net/kb/text-editors-in-linux-and-how-to-use-them/ Fri, 18 Oct 2024 14:07:45 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=35251 Text editors are essential for anyone working in a Linux environment, whether you’re a system administrator, developer, or enthusiast. They allow you to quickly create, modify, and manage files from the terminal or through graphical interfaces. Linux offers a variety of editors, from lightweight command-line options like nano and vim to more feature-rich graphical editors …

Text Editors in Linux and How to Use Them Read More »

The post Text Editors in Linux and How to Use Them appeared first on Hivelocity Hosting.

]]>
Text editors are essential for anyone working in a Linux environment, whether you’re a system administrator, developer, or enthusiast. They allow you to quickly create, modify, and manage files from the terminal or through graphical interfaces. Linux offers a variety of editors, from lightweight command-line options like nano and vim to more feature-rich graphical editors like VS Code and Sublime Text. In this article, we will explore some of the most popular text editors in Linux, highlighting their unique features and providing practical usage guides. Whether you need a simple tool for quick edits or a powerful editor for complex programming, you’ll find the right fit here. We will specifically focus on vim and nano, offering detailed instructions for each

Popular Text Editors in Linux

There are quite a few options for text editors for Linux. The most popular ones are listed below for reference while this article will focus on Vim and Nano.

  • Vim: A highly configurable and powerful text editor that is an improved version of the original Vi. It offers advanced features like syntax highlighting, code folding, and a robust plugin system.

  • Nano: A user-friendly, lightweight text editor that is easy to use, making it a great choice for beginners. It provides simple commands displayed at the bottom of the interface, making navigation intuitive.

  • Emacs: A highly extensible and customizable text editor known for its powerful editing capabilities. It supports a wide range of programming languages and comes with built-in tools for version control, debugging, and more.

Vim

Vim serves as a powerful command-line text editor designed for efficient text manipulation and navigation. Its modal editing system enables users to perform tasks quickly using keyboard shortcuts. Although it has a steep learning curve, Vim offers extensive features like syntax highlighting and customizable macros, making it ideal for coding and advanced editing. Whether you are a beginner or an experienced developer, Vim equips you with the tools you need for a streamlined editing experience.

Vim Installation

Vim could be provided with your distro but might also require manual installation. Proceed with the commands below to install based on the distribution you’re using.

  • Debian/Ubuntu
    • sudo apt update
    • sudo apt install vim
  • Fedora
    • sudo dnf install vim
  • CentOS/RHEL
    • sudo yum install vim
  • Arch Linux
    • sudo pacman -S vim
  • openSUSE
    • sudo zypper install vim

Operating with Vim

  1. Once installed proceed to open the software by typing vim filename.txt. The command will create filename.txt in your current working directory and open vim to edit it. Alternatively, you can type vim /path/to/filename.txt to create the file in a specific path.
  2. Vim works in two modes, Normal mode and Insert mode. Normal mode works for reviewing while insert works for adding text to it and making changes. Proceed to press “i” on your keyboard to enter insert mode. 
    1. At this point, the bottom left of the editor will have “–INSERT–” displayed.
  3. Proceed to enter text as needed.

    Vim Text Editor
    Vim Text Editor
  4. Once done, proceed to press the “Esc” key on your keyboard to exit the Insert mode and enter Normal mode.
  5. Type :w to save the file. To save and quit type :wq!. To quit without saving changes type :q!.
  6. The content of the file can be reviewed within the editor or by using the cat command.

    Text File Output Confirmation
    Text File Output Confirmation

Additional Vim Operations

Within Normal mode there are other basic functions which can help make changes.

  • Deleting a line can be done with dd once you’re on the line you wish to remove.  
  • Undoing a change can be done with u.
  • Redoing a change can be done with Ctrl+r.
  • Searching can be done with a forward slash / and then search term so for example /search_term to search forward.
    • Searching backwards is done as such ?search_term.
    • Navigating the results is done with n to go to the next occurrence of the search term or N to go to the previous one.

GNU nano

GNU Nano is a lightweight, user-friendly command-line text editor that simplifies file editing for everyone. Its straightforward interface displays helpful commands at the bottom, guiding you through the process. With features like syntax highlighting and search functionality, Nano is perfect for quick edits and simple coding tasks, ensuring a smooth editing experience.

Nano Installation

Nano could be provided with your distro but might also require manual installation. Proceed with the commands below to install based on the distribution you’re using.

  • Debian/Ubuntu
    • sudo apt update
    • sudo apt install nano
  • Fedora
    • sudo dnf install nano
  • CentOS/RHEL
    • sudo yum install nano
  • Arch Linux
    • sudo pacman -S nano
  • openSUSE
    • sudo zypper install nano

Operating with Nano

  1. Once installed proceed to open the software by typing nano filename.txt. The command will create filename.txt in your current working directory and open nano to edit it. Alternatively, you can type nano /path/to/filename.txt to create the file in a specific path.
  2. Nano is more straightforward than Vim as it allows to write text immediately upon opening it.

    Nano Text Editor
    Nano Text Editor
  3. Once you wish to save the file, proceed to press Ctrl+O to save it. You will see a prompt that says “File Name to Write: filename2.txt.” In this case, I am saving the file in the current working directory as filename2.txt. Press “Enter” to confirm.
  4. To exit the editor press Ctrl+X.
  5. The content of the file can be reviewed within the editor or by using the cat command.

    Nano Text File Output
    Nano Text File Output

Additional Nano Operations

Nano provides the ability to perform other tasks such as the items below.

  • Searching for text can be done with Ctrl+W followed by typing the search term and pressing “Enter”.
  • Undoing changes can be done with Ctrl+Z.
  • Cutting a line is done with Ctrl+K and pasting it with Ctrl+U
  • For further help check with Ctrl+G to open the manual.

Further Assistance

For any further assistance involving text editing in Linux, do not hesitate to reach out to the Hivelocity Support team via a chat, support ticket, or phone at 888-869-4678. 

The post Text Editors in Linux and How to Use Them appeared first on Hivelocity Hosting.

]]>
TCP/IP Information in Linux https://www.hivelocity.net/kb/tcp-ip-information-in-linux/ Fri, 18 Oct 2024 14:05:30 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=35166 TCP/IP (Transmission Control Protocol/Internet Protocol) is the fundamental communication protocol suite that underpins the internet and networking in Linux-based web hosting environments. It not only ensures reliable transmission of data across networks but also enables seamless connectivity between servers, clients, and other network devices. For web hosting professionals, understanding TCP/IP in a Linux environment is …

TCP/IP Information in Linux Read More »

The post TCP/IP Information in Linux appeared first on Hivelocity Hosting.

]]>
TCP/IP (Transmission Control Protocol/Internet Protocol) is the fundamental communication protocol suite that underpins the internet and networking in Linux-based web hosting environments. It not only ensures reliable transmission of data across networks but also enables seamless connectivity between servers, clients, and other network devices. For web hosting professionals, understanding TCP/IP in a Linux environment is crucial because it empowers them to configure and troubleshoot network issues effectively, ultimately ensuring the smooth operation of hosted websites and applications. Furthermore, this article will delve into the essentials of TCP/IP within Linux, thoroughly covering key concepts such as IP addressing and routing.

TCP/IP Within a Linux OS

Overview

In this example, we will review the networking information within AlmaLinux, a RHEL-based distribution.

To display network interface details, you can use the ip addr command. Additionally, this command and its output prove particularly useful, as they help users understand which configurations are currently running and on which interface within the system. Moreover, this information aids in troubleshooting and effectively managing network settings.

ip addr Output to Display Network Interface Details

ip addr Output to Display Network Interface Details

ip addr Information Breakdown

  • Interface Information:
    • Each network interface is represented by a numbered section (e.g., 1: for lo and 2: for ens18).
    • The name of the interface follows the number. Here, lo is the loopback interface, and ens18 is the Ethernet interface.
    • The status (UP/DOWN) and the MTU (Maximum Transmission Unit) size are listed:
      • mtu 65536 for lo means it can handle packet sizes up to 65536 bytes.
      • mtu 1500 for ens18 means it can handle packet sizes up to 1500 bytes, a typical value for Ethernet.
  • Link Information:
    • link/loopback for lo indicates that it is a loopback interface, which is used for internal communication within the host.
    • link/ether for ens18 shows that this is an Ethernet interface.
    • The MAC address is listed after link/ether. For example, b6:ea:ae:71:00:c3 is the MAC address of the ens18 interface.
  • IPv4 Address:
    • The line inet 127.0.0.1/8 for lo indicates the loopback address, which is commonly used for internal server communication.
    • In contrast, inet 23.111.182.195/29 for ens18 is the public IP address assigned to this server. The /29 denotes the subnet mask, which means that this address is part of a network with up to 8 IP addresses.
  • Broadcast Address:
    • Furthermore, brd represents the broadcast address used for sending data to all devices in the network. Specifically, for ens18, brd 23.111.182.199 serves as the broadcast address within the /29 subnet.
  • Scope:
    • Additionally, scope host means that the address is limited to the host itself, which is typical for the loopback interface (127.0.0.1). On the other hand, scope global indicates that the address is publicly accessible and used for external communication, as seen with 23.111.182.195.
  • IPv6 Address:
    • inet6 shows IPv6 addresses assigned to the interface. 2604:4500:6:6db::2/64 is a global IPv6 address, while fe80::b4ea:aeff:fe71:c3/64 is a link-local address, used for communication within the local network.
  • Status and Additional Information:
    • The state keyword indicates the current state of the interface:
      • UNKNOWN for lo means it is not associated with an actual physical link.
      • UP for ens18 means the interface is active and ready to send/receive data.
    • qlen 1000 shows the queue length, which determines how many packets can be held in the queue before being processed.

Checking Routing Information

Routing is a fundamental aspect of network configuration within the TCP/IP protocol, especially on Linux servers used in web hosting. It involves determining the path that data packets take to reach their destination across interconnected networks. Proper routing is crucial because it ensures that data travels efficiently from one network to another, thereby enabling smooth communication between clients, servers, and other networked devices.

Additionally, a routing table is a set of rules that the Linux kernel uses as part of the TCP/IP protocol to determine where to forward network traffic. Specifically, each entry in the table specifies a destination network and how to reach it. Furthermore, the routing table helps the system make decisions about the most efficient routes, ensuring optimal network performance and connectivity.

To review the current routes in the system ip route command can be used. 

ip route Used to Show the Routing Table of the Linux Server
ip route Used to Show the Routing Table of the Linux Server

ip route Information Breakdown

  1. The default route is used for any network traffic that does not match a more specific route.

    1. default via 23.111.182.193 dev ens18 which indicates the default route, via the gateway IP, using dev (Network interface) ens18.

  2. The Local Network Route 23.111.182.192/29 dev ens18 proto kernel scope link src 23.111.182.195 represents the network route, with /29 as the subnet mask, the ens18 network interface, and proto kernel indicating that the kernel added the route. The src specifies the source IP used when sending packets.

  3. The link-local route handles traffic for the 169.254.0.0/16 range, which devices typically use when they cannot obtain an IP address via DHCP. You can observe this behavior even if you do not enable DHCP, thanks to the automatic functions of the network stack.

Network Configuration Files

Network configuration in Linux involving the TCP/IP protocol establishes how a system connects to networks by defining IP addresses, gateways, and DNS servers. Consequently, this configuration enables communication within local networks or with the internet, ensuring proper data routing. Moreover, tools like ifcfg files, netplan, or /etc/network/interfaces manage this across different distributions, allowing for stable and secure network connections.

Furthermore, the configuration varies between each OS, and we will detail it below according to the main OSs that Hivelocity offers.

AlmaLinux/CentOS Configuration

  • The configuration file location should be present at “/etc/sysconfig/network-scripts/ifcfg-<interface_name>”.
    • Note that AlmaLinux does come equipped with NetworkManager in some cases and might require utilizing nmtui instead of performing the in-file configuration changes.
  • You can find the example configuration below.

TYPE=Ethernet
PROXY_METHOD=none
BROWSER_ONLY=no
BOOTPROTO=none
DEFROUTE=yes
IPV4_FAILURE_FATAL=no
IPV6INIT=yes
IPV6_AUTOCONF=no
NAME=ens18
UUID=910cd91f-8798-4435-9070-dcf556b3f82b
DEVICE=ens18
ONBOOT=yes
IPADDR=192.168.1.100
PREFIX=24
GATEWAY=192.168.1.1
DNS1=8.8.8.8
DNS2=8.8.4.4
IPV6ADDR=2604:4500:6:6db::2/64
IPV6_DEFAULTGW=2604:4500:6:6db::1

Ubuntu Configuration

  • The configuration file location should be present at “/etc/netplan/*.yaml”.
    • The settings are applied using the netplan apply command.
    • Note that the spacing in the file is crucial.
  • You can find the example configuration below.
network:
  version: 2
  ethernets:
      ens18:
          dhcp4: no
          addresses:
               – 192.168.1.100/24
          gateway4: 192.168.1.1
          nameservers:
               addresses:
                    – 8.8.8.8
                    – 8.8.4.4

Debian Configuration

  • The configuration file location should be present at “/etc/network/interfaces”.
  • You can find the example configuration below.

auto ens18
iface ens18 inet static
  address 192.168.1.100
  netmask 255.255.255.0
  gateway 192.168.1.1
  dns-nameservers 8.8.8.8 8.8.4.4

Further Assistance

For any further assistance involving TCP/IP and configuration, do not hesitate to reach out to the Hivelocity Support team via a chat, support ticket, or phone at 888-869-4678. The team can assist with recommendations, explanations, and reviewing/adjusting configuration files in your Linux OS.

The post TCP/IP Information in Linux appeared first on Hivelocity Hosting.

]]>
Mitigating CVE-2024-6387: A Comprehensive Guide https://www.hivelocity.net/kb/mitigating-cve-2024-6387-a-comprehensive-guide/ Wed, 03 Jul 2024 18:45:17 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=33177 Introduction CVE-2024-6387 is a critical vulnerability in OpenSSH that impacts systems using the glibc library. This vulnerability allows remote code execution (RCE) as root for unauthenticated users by exploiting a flaw in the default configuration of OpenSSH, particularly related to the LoginGraceTime parameter. Immediate action is required to secure your systems. This article provides a …

Mitigating CVE-2024-6387: A Comprehensive Guide Read More »

The post Mitigating CVE-2024-6387: A Comprehensive Guide appeared first on Hivelocity Hosting.

]]>
Introduction

CVE-2024-6387 is a critical vulnerability in OpenSSH that impacts systems using the glibc library. This vulnerability allows remote code execution (RCE) as root for unauthenticated users by exploiting a flaw in the default configuration of OpenSSH, particularly related to the LoginGraceTime parameter. Immediate action is required to secure your systems. This article provides a step-by-step guide to mitigate this vulnerability and enhance your overall SSH security.

Steps to Mitigate CVE-2024-6387

1. Update OpenSSH and glibc

Ensure that you are running the latest versions of OpenSSH and the glibc library, as security patches may have been released to address this vulnerability.

Debian-based Systems

Open a terminal and run the following commands:

sudo apt update
sudo apt upgrade openssh-server libc6

RPM-based Systems

Open a terminal and run the following commands:

sudo yum update openssh-server glibc

Regularly check your distribution’s advisories for specific instructions and updates.

2. Modify SSH Configuration

After updating, you need to modify your SSH configuration to reduce the risk of exploitation.

Edit sshd_config

Locate and edit the OpenSSH server configuration file, typically found at /etc/ssh/sshd_config.

  1. Reduce LoginGraceTime: Lower the LoginGraceTime parameter to minimize the window for potential exploitation. The default is usually set to 2 minutes; reducing it to 30 seconds is advisable.

    LoginGraceTime 30
  2. Disable Root Login: If root login is not necessary, disable it to enhance security.

    PermitRootLogin no
  3. Restrict User Access: Ensure that only necessary users have SSH access.

    AllowUsers specific_user

3. Implement Additional Security Measures

Further secure your SSH access by implementing these additional measures:

Key-based Authentication

Switch from password-based authentication to SSH key-based authentication:

PasswordAuthentication no
PubkeyAuthentication yes

Two-Factor Authentication

Enable two-factor authentication (2FA) for SSH access to add an extra layer of security.

Restrict IP Access

Use firewall rules to restrict SSH access to specific IP addresses or networks.

Using ufw on Ubuntu
sudo ufw allow from <trusted_ip> to any port 22
Using firewalld on CentOS/RHEL
sudo firewall-cmd --permanent --add-rich-rule='rule family="ipv4" source address="<trusted_ip>" port port=22 protocol=tcp accept'
sudo firewall-cmd --reload

4. Monitor and Audit

Regularly monitor and audit your SSH access to detect any unusual activities.

  1. Monitor SSH Logs: Regularly check SSH logs for any unauthorized login attempts:

    sudo tail -f /var/log/auth.log
  2. Implement Intrusion Detection Systems (IDS): Use IDS to detect and alert on suspicious activities.

5. Additional Hardening

Further harden your SSH server with the following measures:

Install and Configure fail2ban

fail2ban can automatically block IP addresses that show malicious signs.

sudo apt install fail2ban
sudo systemctl enable fail2ban
sudo systemctl start fail2ban

6. Stay Informed

Stay up-to-date with the latest security updates and advisories:

  • OpenSSH Security Advisory: OpenSSH Security

  • National Vulnerability Database (NVD): NVD

  • Ubuntu Security Notices: USN

  • Red Hat Security Data: Red Hat

Conclusion

By following these steps, you can mitigate the risks associated with CVE-2024-6387 and enhance the security of your SSH configuration. Regular updates, configuration changes, and additional security measures are crucial in protecting your systems from potential exploits. Stay vigilant and informed to ensure your infrastructure remains secure.

The post Mitigating CVE-2024-6387: A Comprehensive Guide appeared first on Hivelocity Hosting.

]]>
Powering Down and Rebooting Your Linux System https://www.hivelocity.net/kb/powering-down-and-rebooting-your-linux-system/ Tue, 27 Feb 2024 14:37:21 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=31550 Powering down and rebooting your Linux system involve fundamental processes that impact its operation and state. Initiating the shutdown command halts processes, ends user sessions, and unmounts file systems for a graceful shutdown. It sends signals to all running processes, instructing them to close properly to prevent data loss or corruption. Once it completes all …

Powering Down and Rebooting Your Linux System Read More »

The post Powering Down and Rebooting Your Linux System appeared first on Hivelocity Hosting.

]]>
Powering down and rebooting your Linux system involve fundamental processes that impact its operation and state. Initiating the shutdown command halts processes, ends user sessions, and unmounts file systems for a graceful shutdown. It sends signals to all running processes, instructing them to close properly to prevent data loss or corruption. Once it completes all essential operations, the system powers off.

When you issue the reboot command, the system undergoes a similar sequence of events as during shutdown. The crucial difference is that after halting processes and unmounting file systems, it initiates a hardware reset, effectively rebooting the system, which reinitializes hardware components and reloads the operating system kernel to its initial state.

Behind the scenes, these commands trigger a series of low-level operations orchestrated by the kernel and system management processes. The shutdown and reboot commands communicate with system services, notify users of impending shutdown or reboot, and handle any necessary cleanup tasks. The commands interact with system daemons responsible for managing hardware, file systems, and user sessions, ensuring a smooth transition between operational states while preserving data integrity and system stability. Overall, these commands play a crucial role in maintaining the health and functionality of Linux systems. This Powering Down and Rebooting Your Linux System guide will explain what commands you could use to perform such power actions in your Linux server.

Rebooting Your Linux Device

Rebooting your device instantly can be done via the command line interface (or in the Customer Portal) using the command reboot.

Reboot Command Which Reboots the Service Instantly
Reboot Command Which Restarts the Server Instantly

To schedule a reboot in your server, use the shutdown command in the following manner sudo shutdown -r +5 which will restart the server after a 5 minutes delay. To deactivate the scheduled reboot, you can use shutdown -c right after.

Using the shutdown Command to Reboot the Server with a 5 Minutes Delay
Using the shutdown Command to Restart the Server with a 5 Minutes Delay

Powering Down Your Linux Device 

Powering down your device instantly can be done via the command line interface (or in the Customer Portal) using the command shutdown, this command will shut the device down after 1 minutes of executing. 

Shutting Down the Server Using the shutdown Command
Shutdown Command to Power Down the Server

To schedule a shutdown in your server, use the shutdown command in the following manner sudo shutdown +5 which will power down the server after a 5 minutes delay. To deactivate the scheduled reboot, you can use shutdown -c right after.

Shutting Down the Server Using the shutdown Command with a 5 Minutes Delay
Powering Down the Server With a 5 Minutes Delay

 

The post Powering Down and Rebooting Your Linux System appeared first on Hivelocity Hosting.

]]>
Ownership and Permissions in Linux https://www.hivelocity.net/kb/ownership-and-permissions-in-linux/ Tue, 27 Feb 2024 14:37:04 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=31429 Ownership and Permissions in Linux Overview Ownership and permissions in Linux are a concept that determines who can access and modify files and directories. Every file and directory have an owner and a group, which are usually the user who created them and the user’s current group. The owner and group of a file or …

Ownership and Permissions in Linux Read More »

The post Ownership and Permissions in Linux appeared first on Hivelocity Hosting.

]]>
Ownership and Permissions in Linux Overview

Ownership and permissions in Linux are a concept that determines who can access and modify files and directories. Every file and directory have an owner and a group, which are usually the user who created them and the user’s current group. The owner and group of a file or directory can be changed using the chown command. Permissions can be read, write, or execute, and can be changed using the chmod command. Ownership and permissions are important for security and multi-user environments in Linux as Linux also uses permissions to control the access rights of the owner, group, and others. 

File and Ownership Permissions Structure

In Linux, understanding file ownership and permissions is crucial for effective system management and security.

Every file and directory in Linux have three kinds of owners:

  • User: The creator of the file becomes its owner. You can change the ownership later.
  • Group: Users are part of specific groups. Managing users in a multi-user environment involves creating separate groups (e.g., dev team, QA team, sysadmin team). Group membership simplifies permission management.
  • Other: This group includes all users on the system, even if you’re the sole user. Everyone with access to the system belongs to this group.

Each file and directory have three permissions for all three owner types:

  • Files
    • Read (r): Allows viewing or copying file contents.
    • Write (w): Permits modifying file content.
    • Execute (x): Enables running executable files (scripts or programs).
  • Directories
    • Read: Lists files and copies them from the directory.
    • Write: Adds or deletes files (requires execute permission).
    • Execute: Allows entering the directory.

File Permissions have two modes. An absolute mode and a symbolic mode. The modes detail the type of entries required for permissions to take effect.

  • Symbolic Mode 
    • Symbolic mode allows you to modify permissions based on their current state. You use symbols like +, -, and = to add, subtract, or set permissions.
      • + Adds permissions.
      • Removes permissions.
      • = Sets permissions explicitly
  • Absolute Mode
    • In absolute mode, you explicitly specify the permissions using numeric values (octal notation). These values represent the combination of read, write, and execute permissions for the owner, group, and others.
      • The numeric values are as follows:
        • 0: No permissions (—)
        • 1: Execute only (–x)
        • 2: Write only (-w-)
        • 3: Write and execute (-wx)
        • 4: Read only (r–)
        • 5: Read and execute (r-x)
        • 6: Read and write (rw-)
        • 7: Read, write, and execute (rwx)

Viewing File and Directory Permissions

Viewing file and directory ownership and permissions in Linux can be done with each via the command line interface of your Linux server.

The first one is using the ls command with the -l flag, as such ls -l. This command would allow a user to view a list of files within the directory they are in or in another (Using ls -l /path/to/directory) to view the permissions for each file. 

ls -l Command Displaying Files and Directories Within a Directory Along with Their Permissions
ls -l Command Displaying Files and Directories Within a Directory Along with Their Permissions

The second method is using the stat command to view a more in-depth scope of the file or directory involved.

stat Command Displaying an In-Depth View of File or Directory Permissions
stat Command Displaying an In-Depth View of File or Directory Permissions

Modifying File and Directory Permissions

Follow the steps below to proceed with file and directory permissions modification. For this example, we will use the absolute and symbolic modes with the file test_file.txt and the command chmod.

In this example we are modifying a file using the symbolic method by first viewing the file permissions using stat test_file.txt and modifying the permissions using chmod +x test_file.txt. Note that without specifying the user, group, other assignment, then the +x would apply all of them as seen below. 

To add permissions specifically to one of the owners, you can use chmod u+x test_file.txt which will add the +x to the user owner.

Using Symbolic Mode to Modify File Permissions
Using Symbolic Mode to Modify File Permissions

In this example we are modifying a file using the absolute method by first viewing the file permissions using stat test_file.txt and modifying the permissions using chmod 744 test_file.txt. Note that after the change has been done, the permissions changed from 644 to 744 or also known as rw-r–r– to rwxr–r–.

Using Absolute Mode to Modify File Permissions
Using Absolute Mode to Modify File Permissions

Thank you for reading and I hope that you enjoyed this Ownership and Permissions in Linux guide. For more guides, please check out our Knowledge Base which is updated weekly!

The post Ownership and Permissions in Linux appeared first on Hivelocity Hosting.

]]>
Resetting MySQL User Password https://www.hivelocity.net/kb/resetting-mysql-user-password/ Fri, 23 Feb 2024 21:25:59 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=31415 MySQL is a popular open-source database management system that can store and manipulate data. To access a MySQL database, you need to create a user account and assign it a password. The process of creating a new user and database is also being done automatically upon a creation of cPanel account and when adding domains …

Resetting MySQL User Password Read More »

The post Resetting MySQL User Password appeared first on Hivelocity Hosting.

]]>
MySQL is a popular open-source database management system that can store and manipulate data. To access a MySQL database, you need to create a user account and assign it a password. The process of creating a new user and database is also being done automatically upon a creation of cPanel account and when adding domains to said account. Resetting the MySQL user password can be very simple and can be performed using two methods as listed below in this Resetting MySQL User Password guide.

Changing MySQL User Password Using WHM/cPanel

This is the recommended method when performing a MySQL user password change when your server contains a cPanel installation.

  1. Login to your WHM/cPanel and search for “Change MySQL® User Password“.

    MySQL User Password Change Form
    MySQL User Password Change Form
  2. Select the MySQL user you wish to change the password.
  3. Ensure to type a password with a strength score of at least 80%, as shown below and press the “Change Password” once completed.
MySQL User Password Change Form Completion
MySQL User Password Change Form Completion

Changing MySQL User Password Using the Command Line Interface 

The following steps will describe the process involved in changing the MySQL user password via the command line once you’ve logged into your server via SSH or by using the Console feature in the customer portal.

  1. Login to the server as the “root” user.
  2. Type the command mysql -u root -h localhost -p to login to MySQL as the “root” user.
  3. Enter the “root” user MySQL password to login.
    1. If you are unsure of what the “root” user password is, you can use the command my_print_defaults -s client to view it in the main command prompt.
  4. Now that you are logged in to MySQL as “root” user.

    MySQL Login Prompt in Command Line
    MySQL Login Prompt in Command Line
  5. Run command SELECT user FROM mysql.user; to view a full list of available users.

    Full MySQL Users List via the Command Line
    Full MySQL Users List via the Command Line
  6. Use the following command to alter the password ALTER USER ‘pascalsuissa’@’localhost’ IDENTIFIED BY ‘MyNewPasswordis1234!’;
    1. “pascalsuissa” is the username.
    2. “MyNewPasswordis1234” is the password.
  7. Once the command has completed running, the prompt will display a “Query OK” message, indicating that the password change is now complete.

    Completion Prompt Indicating a Successful MySQL User Password Change
    Completion Prompt Indicating a Successful MySQL User Password Change

The post Resetting MySQL User Password appeared first on Hivelocity Hosting.

]]>
Skeleton Directories in Linux https://www.hivelocity.net/kb/skeleton-directories-in-linux/ Fri, 23 Feb 2024 21:25:30 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=31422 Skeleton directories in a Linux OS serves as the foundation for a new user’s home directory when created using the useradd command. It automatically copies files and directories to the user’s home directory. These files establish initial settings and environment, including the bash profile, aliases, and bookmarks. In this article, Skeleton Directories in Linux, we …

Skeleton Directories in Linux Read More »

The post Skeleton Directories in Linux appeared first on Hivelocity Hosting.

]]>
Skeleton directories in a Linux OS serves as the foundation for a new user’s home directory when created using the useradd command. It automatically copies files and directories to the user’s home directory. These files establish initial settings and environment, including the bash profile, aliases, and bookmarks.

In this article, Skeleton Directories in Linux, we will review each of the parameters and directories involved with the skeleton directory. 

Skeleton Directory Overview in A Linux System

The skeleton directory (/etc/skel) provides the backbone or skeleton of what any new account /home/<username> directory would look like. For example, if there are 3 directories in /etc/skel, then those directories would populate upon each and every new account that is being created.

Skeleton Directory and the Creation of Directories Within

  1. As shown above, we are viewing the directory with ls /etc/skel which shows no directories within.
  2. Create the required directories with the mkdir command, “Documents”, “Videos”, and “Downloads”.
  3. Use the ls command to verify that the newly created directories are present.
  4. When creating a new user, such as ‘pascal’ using the command useradd pascal, the user’s home directory will be located at /home/pascal/.
  5. View the home directory of the new user using ls /home/pascal in which the new directories will appear.
Viewing the New Directories Created in the /etc/skel Directory and How They Populate for New User Accounts
Viewing the New Directories Created in the /etc/skel Directory and How They Populate for New User Accounts

As seen in this article, skeleton directories are a useful tool for organizing the structure and layout of a project or user. Skeleton directories can help developers and collaborators to understand the purpose and function of each component, as well as to avoid duplication and confusion. Skeleton directories can also facilitate the automation and testing of the project, by making it easier to locate and execute the relevant scripts and commands.

The post Skeleton Directories in Linux appeared first on Hivelocity Hosting.

]]>
Bash Scripts in Linux https://www.hivelocity.net/kb/bash-scripts-in-linux/ Fri, 23 Feb 2024 21:25:09 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=31447 Bash, short for Bourne-Again Shell, is a powerful command-line interface (CLI) program that allows users to interact with their systems and execute bash scripts in Linux. Bash provides a way to execute commands, automate tasks, and create custom workflows using bash scripts. Here are the key points about Bash scripting. A Bash script is a …

Bash Scripts in Linux Read More »

The post Bash Scripts in Linux appeared first on Hivelocity Hosting.

]]>
Bash, short for Bourne-Again Shell, is a powerful command-line interface (CLI) program that allows users to interact with their systems and execute bash scripts in Linux. Bash provides a way to execute commands, automate tasks, and create custom workflows using bash scripts. Here are the key points about Bash scripting.

  • A Bash script is a file containing a sequence of commands written in the Bash language.
  • These commands are executed by the Bash interpreter line by line.
  • Bash scripts save time by automating repetitive tasks. Instead of typing the same commands repeatedly, you can run a script.
  • You can tailor scripts to your needs, creating personalized solutions.
  • Set up scripts to run at specific times (e.g., daily backups) by scheduling them using cron jobs. 

Creating and Executing Your First Bash Script

Let’s create a simple “Hello, World!” script in your server.

  1. Create a file named hello_world.sh using your editor of choice.
  2. Add the shebang line: #!/bin/bash.
    1. #!/bin/bash specifies that the Bash shell should interpret the script.
  3. Write the command: echo “Hivelocity!”.

    Creation of a Bash Script  in Linux Using the nano Text Editor
    Creation of a Bash Script in Linux Using the nano Text Editor
  4. Save the file.
  5. Make it executable using chmod +x /hello_world.sh.
  6. Run it by using either ./hello_world.sh or bash /hello_world.sh. (Bash at the start will run the script using the bash interpreter and should not be used if running a script in a language other than bash). 
Running a Bash Script  in Linux Using the bash Command
Running a Bash Script in Linux Using the bash Command

Bash Script Variables

Variables in Bash scripts are named symbols that represent either strings or numeric values. They allow you to store and reference data within your scripts. To create a variable, provide a name and a value for it. Variable names should be descriptive and cannot start with a number or contain spaces. They can start with an underscore and can have alphanumeric characters. It is also good practice to type variables with uppercase characters.

For example, take this bash script below.

Bash Script Variable Example
Bash Script Variable Example

Executing the script will provide the echo output of the variables that were set in the beginning of the script.

Bash Script Execution Displaying Output of Variables
Bash Script Execution Displaying Output of Variables

Other Shebang (#!) Examples

Shebang (#!) specifics the interpreter used for the script you’ve created and can be used for other languages other than bash.

  • #!/bin/bash: Specifies the Bash interpreter.
  • #!/usr/bin/env python: Uses the Python interpreter found in the user’s $PATH.
  • #!/usr/bin/perl: Executes the script using the Perl binary.

Common Operations for Bash Scripts in Linux

  1. Sleep command using “sleep 3” to pause an execution for a specified time in seconds. 
  2. Reading input from a user.
    read -p “Enter your name:” USERNAME
    echo “Hello, $USERNAME!”
  3. Loops to execute commands repeatedly 
    for i in {1..5}; do
    echo “Iteration $i”
    done

  4. Conditional Statements to make decisions based on conditions

    age=25
    if [ “$age” -ge 18 ]; then
    echo “You are an adult.”
    else
    echo “You are a minor.”
    fi

  5. Functions to define reusable code blocks
    greet() {
    echo “Hello from a function!”
    }
    greet

  6. File operations to create directories, read files, and delete files
    mkdir my_directory
    cat myfile.txt
    rm unwanted_file.txt

  7. Math operations to perform calculation
    result=$((5 + 3))
    echo “5 + 3 = $result”

  8. Checking file existence to verify if a file does exist

    if [ -f myfile.txt ]; then
    echo “File exists.”
    else
    echo “File does not exist.”
    fi

Scheduling your Script via a Cron Job

Adding a script to a cron job allows you to schedule it to run automatically at specified intervals.

  1. For demonstration purposes, let’s assume our script prints the system date and time and appends it to a log file.
    #!/bin/bash
    echo “$(date +’%Y-%m-%d %T’) – Hello, cron!” >> /home/user/log.txt

    Make sure the script is executable with chmod +x my_script.sh.

  2. Add the script to the user’s crontab by opening the crontab editor using crontab -e
  3. Append the following line to schedule the script to run every day at 3:00 AM using 

    0 3 * * * /path/to/my_script.sh

  4. Save and close the editor followed by ensuring that the script can be executed properly with chmod +x /path/to/my_script.sh.

For a useful tool on how to handle the time format of a cron job, check out the useful tool here – https://crontab-generator.org/

The post Bash Scripts in Linux appeared first on Hivelocity Hosting.

]]>
Handling Directories in Linux https://www.hivelocity.net/kb/handling-directories-in-linux/ Tue, 09 Jan 2024 22:55:22 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=29213 Directories in Linux are folders that contain files and other directories. They are organized in a hierarchical structure, starting from the root directory (/) that contains all other directories and files. In this tutorial, we will cover handling directories in Linux and explain how to create, rename, delete, and move through directories. — — Handling …

Handling Directories in Linux Read More »

The post Handling Directories in Linux appeared first on Hivelocity Hosting.

]]>
Directories in Linux are folders that contain files and other directories. They are organized in a hierarchical structure, starting from the root directory (/) that contains all other directories and files. In this tutorial, we will cover handling directories in Linux and explain how to create, rename, delete, and move through directories.

Handling directories in Linux – Absolute and Relative Paths

When traversing directories in Linux, there are two ways to type a file or directory path, an absolute path and relative path.

An absolute path is the specific location irrespective of the current working directory or combined paths and are written with reference to the root directory, starting with a forward slash /. Example of using absolute path, “cd /usr/bin

handling directories in Linux - Absolute path

A relative path is the path relative to the current working directory using period and double periods, indicating current and parent directories. Example of using a relative path when the current working directory is /usr/, “cd bin

relative path - directories in Linux

Both types will take you to the same place but take different steps and criterias to do so, when you handling directories in Linux.

How to Create a Directory 

To create a directory, we will use the mkdir command to do so. Follow the steps below to proceed. 

1. To create a directory in Linux, you can use the mkdir command followed by the name of the directory, as shown below.

The command will create a directory in the root directory (/) called “Net_Growth_21”.

mkdir /Net_Growth_21 which will create a directory in / with that name.

creating directory in linux

2. Creating a directory in a different directory, the full path can be given with the command.

mkdir /guide/Net_Growth_21 which will create the directory in a directory, /guide/, as shown below.

creating directory/guide

How to Navigate and List Directories in Linux

To navigate through directories, we will be using the following commands, pwd, ls, and cd.

1. The pwd command will print the working directory which you are currently working in.

Command to print working directory in Linux

2. The ls command will list all items in the directory you are currently working in.

List the items in directory

Another good option with ls is ls -lh which will present the items size and in a list form.

Present items in list form

3. The cd command is used to move through directories.

    1. Using cd . will navigate to the current directory as the period (.) is used to represent the current directory.
    2. Using cd .. will navigate one directory above the current directory.
    3. move through directoriesUsing cd ~ will take you to the home directory of the currently logged user. Two examples are listed below for root and psuissa users.


How to Move a Directory in Linux

If you’re trying to move a directory in Linux from one location to another, just follow these 4 steps:

1. To move a directory in Linux, you can use the mv command followed by the source and destination directories, as shown below.

mv [source directory] [destination directory]

 

2. So, if you wanted to move /directory1 into a second directory name /directory2, you would use the following command:

mv /directory1 /directory2

How to move a directories in Linux

Note: If no “/directory2” exists, /directory1 will be renamed as “/directory2”, essentially “moving” it into a newly created directory, otherwise, all content from /directory1 will move to /directory2.

 

3. This can also be done for multiple files and directories at once. Let’s say you have 3 files (File1, File2, and File3), and you’d like to move all them into /Directory1. Simply list out all your sources before your destination, and Linux will automatically move all these files at once.

mv file1.txt file2.txt file3.txt /home/directory1

How to move a directories in Linux

4. Keep in mind that in order to move files and directories, a user must have permissions allowing them to modify both the source and destination directories. Otherwise, an error will occur and permission will be denied.

 

How to Copy a Directory in Linux

If you’re trying to make a copy of an existing directory, just follow these 4 steps:

1. To copy a directory or file in linux, just use the copy command followed by the Source (the directory you’re copying), and the Destination (the place you’re copying it to):

cp -R [Source] [Destination]

 

2. to make a copy of /directory1 and place it inside of /directory2, you would use the command:

cp -R /directory1 /directory2

How to copy a directory in Linux

*Note: If no “/directory2” exists, a new directory will be created, with that name, and containing the contents of /Directory1.

 

3. Like moving files, it is possible to copy multiple files into a single directory by listing out multiple filenames for sources, followed by a single destination. For example:

cp -R file1.txt file2.txt file3.txt /directory1

Which would copy file1, file2, and file3 into /directory1.

How to copy a directory in Linux

4. Additionally, if you wanted to copy the entire contents of /Directory1 into /Directory2 (duplicating the files inside the folder but not the folder itself), you can do so by adding ” /* ” after the source directory. For example:

cp – R /directory1/* /directory2

This would create copies of all the files located in /directory1, placing duplicates of its content into /directory2, but not duplicating the actual directory itself.

How to copy a directory in Linux

How to Rename a Directory in Linux

If you need to rename an existing directory in Linux to something new, just follow these 2 steps:

 

1. Interestingly, due to the way Linux’s file structures work, moving a file and renaming a file are actually the same action. This is because when you’re “moving” a file in Linux, you’re really “renaming” its file path: giving it a new name but also a new location in your system’s structure.

mv [Source Directory] [Destination Directory]

So, to rename /directory1 to /directory_new, you would use the command:

mv /directory1 /directory_new

If “/directory_new” already exists, then this command will move the contents of /directory1 to /directory_new. However, if “/directory_new” does NOT already exist, this command will rename /directory1 to /directory_new.

Renaming a directory in linux

The post Handling Directories in Linux appeared first on Hivelocity Hosting.

]]>
MTR Report how to Generate in Linux and Windows https://www.hivelocity.net/kb/mtr-report-how-to-generate-in-linux-and-windows/ Tue, 09 Jan 2024 22:50:53 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=29200 What is an MTR? MTR (My Traceroute) is a Linux/Unix utility that combines Ping and Traceroute functions into one easy-to-use program. MTR is run on a computer to provide detailed hop test data (a series of brief measurements) which provides test results that are a combination of ping and Traceroute.  MTR continuously sends ping requests …

MTR Report how to Generate in Linux and Windows Read More »

The post MTR Report how to Generate in Linux and Windows appeared first on Hivelocity Hosting.

]]>
What is an MTR?

MTR (My Traceroute) is a Linux/Unix utility that combines Ping and Traceroute functions into one easy-to-use program. MTR is run on a computer to provide detailed hop test data (a series of brief measurements) which provides test results that are a combination of ping and Traceroute. 

MTR continuously sends ping requests to each hop until the test has stopped with each hop in the path and will display the average % of packet loss, total packets sent and received, best, average, worst, and last latency test result. 

Why Does Hivelocity Support Team Require MTRs?

MTRs are required in certain scenarios for the support team to understand and evaluate the route and potential packet loss with each hop. Normally, the team will require an MTR from the server to your workstation or other affected server, along with another from the workstation to the server.

MTR in Linux

 

What is the MTR Package in Linux?

The mtr package is a command-line network diagnostic tool that combines ping and traceroute into one program, It is also known as MyTraceRoute. The tool continuously sends packets and shows the response time and percentage of each hop from the local system to a destination host. The mtr package is an essential, real-time network diagnostic tool for your sysadmin toolbox.

Installing and Using in Linux

The procedure to install and use MTR in a Linux OS is described below.

1. The mtr package should be already installed in your OS (Skip to step 2 to confirm). If it’s missing, proceed to download it using the following command. Note that the command can change depending on your package manager.

sudo apt install mtr

Installing and using MTR package in Linux

2. Once it is installed, we will run it using the following command fup to 2 minutes and until the destination is reached. If the destination is not reached, allow it to run for up to 2 minutes. For this example, we will use Google’s DNS server IP of 8.8.8.8.

 

mtr 8.8.8.8

Installing and using MTR package in Linux

3. Once the command is used a new display will appear displaying the task being done.

Installing and using MTR package in Linux

4. The MTR report can be provided to Hivelocity’s support team via a screenshot for further evaluation and interpretation. 

 

How to Modify

The mtr package has various options to alter the output of the scan. A few examples are listed below with commands and explanations.

  • mtr -4 – will use IPv4 only.
  • mtr -6 – will use IPv6 only.
  • mtr -c <count> – will send a number <count> of pings and exit.
  • mtr -n – will not resolve hostnames to Ip addresses.

Modifying MTR in Linux
Modifying MTR in Linux

MTR in Windows 

 

What is WinMTR?

WinMTR is a Windows clone of MTR and is managed directly within their UI which allows you to run MTRs via the Windows OS. In the app, you will enter the IP or domain name of the target host in the “Host” bar, and then press Start. This will continue sending packets until you press the Stop button. The report that is made later can be exported later.

Installing and Using in Windows

The procedure to install WinMTR in Windows can be found below.

1. Proceed to the Cnet webpage to reach the download link for the portable version.

  1. Note that if the link is not working, using Google to search WinMTR should be sufficient.

2. Press on the “Download Now” to download the latest version, as shown below.

Installing and Using WinMTR in Windows

3. The next page will begin downloading the .exe file to your computer. Once the download is complete, begin installing the application.

4. Once the application has been installed, proceed to open the application.

5. In the application’s main screen, enter the IP you wish to run and press the Start button.

Installing and Using WinMTR in Windows

6. Run it for up to 2 minutes and until the destination is reached. If the destination is not reached, allow it to run for up to 2 minutes For this example we will use one of Google’s DNS server IP, 8.8.8.8 for the host IP part. An example task report can be found below.

Installing and Using WinMTR in Windows

7. The report can be provided to Hivelocity’s support team via a screenshot, by using the “Export HTML” option, or by using the “Export TEXT” option for further evaluation and interpretation.

 

How to Modify

Pressing the “Options” button will open various fields which can be modified. Most of the various options in that section should not be modified but what can often be used to provide a report with just IP addresses is to uncheck the “Resolve names” option. Once that has been performed, run the task once more.

The post MTR Report how to Generate in Linux and Windows appeared first on Hivelocity Hosting.

]]>
Understanding Linux Shells https://www.hivelocity.net/kb/understanding-linux-shells/ Tue, 14 Nov 2023 18:32:43 +0000 https://www.hivelocity.net/?post_type=hv_knowledgebase&p=29232 Introduction Linux shells are an essential part of the Linux operating system. They are command-line interpreters that allow users to interact with the operating system in many ways such as interpreting a user’s command and script files along with telling the OS what to do with them. There are many different types of shells available …

Understanding Linux Shells Read More »

The post Understanding Linux Shells appeared first on Hivelocity Hosting.

]]>
Introduction

Linux shells are an essential part of the Linux operating system. They are command-line interpreters that allow users to interact with the operating system in many ways such as interpreting a user’s command and script files along with telling the OS what to do with them. There are many different types of shells available for Linux, but some of the most popular ones include bash, zsh, and ksh.

 

Some of the characteristics of the Linux shell include:

  • Background processing: Sets up lengthy tasks to run in the background.
  • Command aliasing: Gives an alias name to a command or phrase.
  • Command history: Records the commands you enter in a history.
  • Input and output redirection: Redirects input and output to and from files.
  • Shell variable substitution: Stores data in user-defined variables.
  • Shell commands: cd, ls, echo, pwd, touch etc.
  • Functions
  • Control flow: if…then…else, case and shell loops etc.

Bourne Shell (sh)

Bourne shell is a command-line interpreter for Unix-like operating systems. It was developed by Stephen Bourne at Bell Labs in the 1970s and became the standard shell for Unix Version 7. Bourne shell supports variables, control structures, built-in commands, and basic scripting features. It is also the ancestor of many other shells, such as bash, ksh, and zsh. 

Bourne Again Shell (bash)

Bash is a command-line interpreter that allows users to interact with the operating system using text commands. Bash stands for Bourne-Again SHell, a pun on the name of the original Unix shell, the Bourne shell. Bash is compatible with the syntax and features of the Bourne shell, but also adds many enhancements. 

 

Some of the advantages of using bash are:

 

  • Bash is widely available and installed by default on most Linux and macOS systems.
  • Bash supports scripting which allows users to write programs that automate tasks and run them in bash.
  • Bash offers many built-in commands and utilities that perform common operations such as file manipulation, text processing, arithmetic, and networking.
  • Bash provides users the ability to customize their environment using variables, aliases, functions, and options.
  • Bash also supports features that make the command-line more user-friendly, such as command completion, history, editing, and redirection.

Z Shell (zsh)

Zsh is a powerful and versatile shell that offers many advantages over the traditional bash. Zsh has features such as auto-completion, spelling correction, globbing, history manipulation, and command-line editing. Zsh can also be customized with themes, plugins, and options to suit different preferences and workflows. The shell is compatible with most Unix-like operating systems and can run scripts written for bash or other shells while also being used by developers, system administrators, and power users.

 

Some of the features of Z Shell are:

 

  • Programmable command-line completion
  • Extended file globbing
  • Improved variable/array handling
  • Spelling correction and approximate completion

KornShell (ksh)

KornShell is a Unix shell that was developed by David Korn at Bell Labs in the early 1980s. It is compatible with the Bourne shell, but also provides many features from the C shell and other advanced shells. KornShell can be used as an interactive command-line interpreter or as a scripting language. 

 

Some of the features of KornShell are:

 

  • Command-line editing and history
  • Aliases and functions
  • Arrays and associative arrays
  • Arithmetic and string operations
  • Pattern matching and file name generation

How to Determine Which Shell is Being Used?

In your Linux server, within the current command-line interface, type the command below to view which Linux shell you are using.

 

echo $SHELL

The post Understanding Linux Shells appeared first on Hivelocity Hosting.

]]>