linux | LinuxHostSupport Linux Tutorials and Guides Tue, 09 Jul 2024 12:52:44 +0000 en-US hourly 1 https://wordpress.org/?v=6.6.1 How to stop Receiving Spam Emails on Linux with SpamAssassin https://linuxhostsupport.com/blog/how-to-stop-receiving-spam-emails-on-linux-with-spamassassin/ https://linuxhostsupport.com/blog/how-to-stop-receiving-spam-emails-on-linux-with-spamassassin/#respond Thu, 15 Aug 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2153 In the ongoing struggle against unwanted communication there are many technologies and strategies on how to stop receiving spam emails. One highly effective way for Linux users is the open-source Apache SpamAssassin project, offering a highly-effective and free anti-spam platform. In this article, we’ll teach you exactly how to stop receiving spam emails on Linux […]

The post How to stop Receiving Spam Emails on Linux with SpamAssassin appeared first on LinuxHostSupport.

]]>
In the ongoing struggle against unwanted communication there are many technologies and strategies on how to stop receiving spam emails. One highly effective way for Linux users is the open-source Apache SpamAssassin project, offering a highly-effective and free anti-spam platform.

In this article, we’ll teach you exactly how to stop receiving spam emails on Linux with SpamAssassin.

What is SpamAssassin and how it works

Spamassassin is a tool that scores spam emails by comparing them against various tests. It uses a header (X-Spam-Status:) marked with a number ranging from 0-5, with a setting of 3.5 being safe enough to reduce false positives and the amount of SPAM that makes it through. A SPAM score is calculated from multiple characteristics, ranging from 0 to 5, and has been effective for years. Spamassassin is a helpful tool for filtering spam emails. In this tutorial, we’ll learn how to integrate this filter into our Postfix server.

Prerequisites

  • An up-to-date Linux system
  • Postfix installed on your system
  • Root access to your server

Installing SpamAssassin

The installation of SpamAssassin service is easy to do. We accomplish it with the following command:

sudo apt-get install spamassassin # Ubuntu
sudo yum install spamassassin # AlmaLinux

After installing the service, we must integrate it with the Postfix mail server. To accomplish that, we’ll follow the next topic.

Configuring Spamassassin with Postfix

The main configuration file from Spamassassin is generally located at /etc/spamassassin/local.cf. There, you’ll find the required_score part, which sets what is spam and what is not. You can keep it as 5 and uncomment the line if it’s commented:

required_score 5.0

If you need to whitelist someone’s domain, you can add the following directive to your local.cf file:

whitelist_from *@sender_domain.com

Also, we need to configure report_safe. This directive will do the handle of the marked spam messages.

report_safe 0 # The incoming SPAM messages will have the header modified with a directive pointing it's spam
report_safe 1 # The incoming messages tagged as SPAM will create a report and attach the original message to it
report_safe 2 # The incoming SPAM will be attached as a new report and sent as plain text

To identify spam messages on the mailbox, we need to remove the rewrite_header Subject comment line so it will identify the spam:

rewrite_header Subject SPAM

And it’s done the configuration. Now, we need to integrate Spamassassin and Postfix.

Integrating Postfix and SpamAssassin

The postfix configuration file is located at /etc/postfix/master.cf. The first change required to be done is related to the SMTP line, so the line would look like:

smtp inet n - - - - smtpd

Then, after our changes, with the integration of SpamAssassin, it would look like this:

smtp inet n - - - - smtpd -o content_filter=spamassassin

At the end of our file, we need to add the following content:

spamassassin
unix – n n – – pipe
flags=R
user=spamd
argv=/usr/bin/spamc
-e /usr/sbin/sendmail
-oi -f ${sender} ${recipient}

That’s it. SpamAssassin is configured on your system and integrated with Postfix. At this point, you can test the email deliverability of your service to see if it’s working as expected. If you’re struggling with this, feel free to contact our Incident Server Support team, and we’ll help you get everything sorted out.

The post How to stop Receiving Spam Emails on Linux with SpamAssassin appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-stop-receiving-spam-emails-on-linux-with-spamassassin/feed/ 0
How to Install Node.js and NPM on Ubuntu 24.04 https://linuxhostsupport.com/blog/how-to-install-node-js-and-npm-on-ubuntu-24-04/ https://linuxhostsupport.com/blog/how-to-install-node-js-and-npm-on-ubuntu-24-04/#respond Thu, 30 May 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2086 NodeJS is an open-source JavaScript runtime environment, one of the most popular tools among web developers. Developers typically use NodeJS to improve the functionality of web applications or create local development environments. This tutorial will guide you on how to install Node.JS and NPM on Ubuntu 24.04 using the default repository and NodeSource. You will […]

The post How to Install Node.js and NPM on Ubuntu 24.04 appeared first on LinuxHostSupport.

]]>
NodeJS is an open-source JavaScript runtime environment, one of the most popular tools among web developers. Developers typically use NodeJS to improve the functionality of web applications or create local development environments. This tutorial will guide you on how to install Node.JS and NPM on Ubuntu 24.04 using the default repository and NodeSource. You will also learn how to install a specific version of NodeJS using NVM.

Prerequisites

  • An Ubuntu 24.04 VPS
  • SSH root access or user with sudo privileges

Conventions

# – given commands should be executed with root privileges either directly as a root user or by use of sudo command
$ – given commands should be executed as a regular user

Step 1. Login to the server

First, log in to your Ubuntu 24.04 server through SSH as the root user:

ssh master@IP_Address -p Port_number

You must replace ‘IP_Address‘ and ‘Port_number‘ with your server’s IP address and SSH port number. Additionally, replace ‘master’ with the username of the system user with sudo privileges.

You can check whether you have the proper Ubuntu version installed on your server with the following command:

$ lsb_release -a

You should get this output:

No LSB modules are available.
Distributor ID: Ubuntu
Description: Ubuntu Noble Numbat
Release: 24.04
Codename: noble

Step 2. Install Dependencies

To install NodeJS on our system, we need to install some dependencies. Let’s run the command below to install them.

$ sudo apt install curl apt-transport-https ca-certificates gnupg

Step 3. Install NodeJS and NPM from APT

The easiest way to install NodeJS and NPM on an Ubuntu 24.04 system is from the default APT repository. You will get NodeJS version 18 and NPM version 9 using this installation method. The installation is simple and straightforward. Let’s execute the command below to install NodeJS and NPM.

$ sudo apt install nodejs npm -y

Once installed, you can run this command to check the version.

$ nodejs -v; npm -v
master@ubuntu24:~$ nodejs -v; npm -v
v18.19.1
9.2.0

Step 4. Install NodeJS and NPM from NodeSource

We can install NodeJS from the Ubuntu default repository, but we will get an older version of NodeJS if we use this method. Alternatively, we will install NodeJS and npm through NodeJS repository to get the more recent version of it. If compared to Ubuntu’s default repository, NodeSource offer more versions to choose.

$ curl -sL https://deb.nodesource.com/setup_lts.x | sudo -E bash -

Once completed, we must download the package information from the newly added source above.

$ sudo apt update

Next, run the following command to install NodeJS and NPM.

$ sudo apt install nodejs

That’s it. NodeJS and NPM are installed. You can check the installed version by executing this one-liner:

$ node -v; npm -v

Now go to https://nodejs.org/en/download/ and see what is the LTS version. You have just installed the same version as shown there, and you will see an output like this after running the command above:

master@ubuntu24:~$ node -v; npm -v
v20.11.1
10.2.4

Again, this installation method is suitable if you want to get the LTS or a specific version. For example, if you want version 18, you can execute this command instead.

$ curl -fsSL https://deb.nodesource.com/setup_18.x | sudo -E bash -

Replace 18 with any version you want if you want another version.

Step 5. Install NodeJS and NPM using NVM

Another way to install NodeJS on Ubuntu is by using the Node Version Manager (NVM). NVM is a bash script used to manage several versions of NodeJS on your system. This installation method allows you to install and maintain different independent versions of NodeJS simultaneously.

Run this command below to download the script.

$ curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.7/install.sh | bash

Then, we need to source the script.

$ source ~/.bashrc

After executing the command, you can list the available version of NodeJS to install with this command:

$ nvm list-remote

The command will return a message containing a long list of NodeJS version to choose.

To install version 20.11.1, run this command

$ nvm install 20.11.1

As explained earlier, you can have multiple version of NodeJS, you can install another version using the same command with the different version in the command.

To switch between the installed version, you can run this command:

$ nvm use 18.19.1

Replace 18.19.1 with the version you want to switch to. Make sure the version is already installed.

Congratulation! You have successfully learned how to install Node.JS and NPM on your Ubuntu 24.04 VPS. For more information about NodeJS and NPM, please refer to the NodeJS website.

If you are still unsure, you don’t have to install NodeJS and NPM On Ubuntu 24.04 yourself. Our Linux admins will set up and configure a NodeJS and NPM VPS for you on our monthly management plans or per incident server support plans.

PS. If you liked this post on how to install NodeJS and NPM On Ubuntu 24.04, please share it with your friends on social networks using the buttons on the left or leave a reply below. Thanks.

The post How to Install Node.js and NPM on Ubuntu 24.04 appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-install-node-js-and-npm-on-ubuntu-24-04/feed/ 0
How to Verify Checksum of a File on Linux https://linuxhostsupport.com/blog/how-to-verify-checksum-of-a-file-on-linux/ https://linuxhostsupport.com/blog/how-to-verify-checksum-of-a-file-on-linux/#respond Wed, 15 May 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2093 Welcome to our tutorial on how to verify checksum of a file on Linux. Maintaining the integrity and security of data in the digital realm is crucial. Checksums validate the authenticity of files and data sets by generating unique strings of characters through mathematical algorithms. We’ll delve into the fundamentals of checksums, their significance in […]

The post How to Verify Checksum of a File on Linux appeared first on LinuxHostSupport.

]]>
Welcome to our tutorial on how to verify checksum of a file on Linux. Maintaining the integrity and security of data in the digital realm is crucial. Checksums validate the authenticity of files and data sets by generating unique strings of characters through mathematical algorithms. We’ll delve into the fundamentals of checksums, their significance in various contexts, and how to generate and verify checksums effectively. Let’s begin our exploration!

Prerequisites:

  • A Linux server
  • SSH access

What is a Checksum?

A checksum is a mathematical algorithm used to generate an alphanumeric value for a file. This process is facilitated by specialized tools that employ cryptographic hash functions to create a hash value. Checksums are crucial in verifying the integrity and security of ZIP archives or binary files and in various file types like text or document files. A matching checksum confirms that a file maintains its digital integrity and security and is an exact replica of the original file.

Consequently, if the checksum of a downloaded file does not align with the original value, two primary reasons may account for it:

  • The file might have been tampered with by unauthorized parties.
  • The file may not have been downloaded correctly, potentially resulting in the corruption of some file elements.

The two primary checksum algorithms commonly used are MD5 and SHA. When verifying checksums, it is essential to use the same algorithm that generated them. For instance, a file’s MD5 checksum will differ significantly from its SHA-256 checksum.

Method 1 – Verify checksum using md5sum

Begin by logging into your server via SSH:

ssh root@IP_Address -p Port_number

Substitute ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If necessary, replace ‘root’ with your account’s username.

You can generate the MD5 checksum to compare it with the original location of the file you downloaded or copied using the following command:

md5sum file_name

Substitute “file_name” with the name of your file.

Here’s how the output should appear:

# md5sum file_name
b74a5725c6bb94d2d0e527e1996dc9f5 file_name

Please be aware that the MD5 checksum value will differ because the file used in this tutorial is distinct from the one you are examining.

Additionally, you can utilize the following command to save the list of files alongside their MD5 checksums in a text file for future comparison:

md5sum file_name > md5sumlist.txt

To verify the MD5 checksum from the generated list, use the following command:

md5sum -c md5sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat md5sumlist.txt
b74a5725c6bb94d2d0e527e1996dc9f5 file_name
# md5sum -c md5sumlist.txt
file_name: OK

# cat md5sumchangedlist.txt
a74a5725c6bb94d2d0e527e1996dc9f5 file_name
# md5sum -c md5sumchangedlist.txt
file_name: FAILED

Method 2 – Verify checksum using sha256sum

To start, log in to your server using SSH:

ssh root@IP_Address -p Port_number

Replace ‘IP_Address’ and ‘Port_number’ with your server’s IP address and SSH port number. If needed, replace ‘root’ with your account username.

You can generate the SHA-256 checksum to compare it with the original location of the file you downloaded or copied using the following command:

sha256sum file_name

Replace file_name with your file name.

Here’s how the output should look:

# sha256sum file_name
8f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name

Please note that the SHA-256 checksum value will differ because the file used in this tutorial differs from the one you’re examining.

You can also use the following command to store the list of files along with their SHA-256 checksums in a text file for future comparison:

# sha256sum file_name > sha256sumlist.txt

To verify the SHA-256 checksum from the list you have generated, use the following command:

# sha256sum -c sha256sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat sha256sumlist.txt
8f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name
# sha256sum -c sha256sumlist.txt
file_name: OK

# cat sha256sum_changed_list.txt
3f005696fff811934bf7e80be08c7c8b70899991f607294f68abb25ab65a14f9 file_name
# sha256sum -c sha256sum_changed_list.txt
file_name: FAILED
sha256sum: WARNING: 1 computed checksum did NOT match

Method 3 – Verify checksum using sha512sum

Begin by logging into your server via SSH:

ssh root@IP_Address -p Port_number

Substitute ‘IP_Address’ and ‘Port_number’ with your server’s actual IP address and SSH port number. If necessary, replace ‘root’ with your account’s username.

You can generate the SHA-512 checksum to compare with the original location of the file you downloaded or copied using the following command:

# sha512sum file_name

Substitute “file_name” with the name of your file.

Here’s the expected output:

# sha512sum file_name
b1347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name

Please be aware that the SHA-512 checksum value will differ because the file used in this tutorial is distinct from the one you are currently examining.

Additionally, you can utilize the following command to save the list of files alongside their SHA-512 checksums in a text file for subsequent comparisons:

# sha512sum file_name > sha512sumlist.txt

To verify the SHA-512 checksum from the generated list, use the following command:

# sha512sum -c sha512sumlist.txt

For every matching checksum, the display shows “OK,” while a mismatched checksum indicates “FAILED.” Here’s how the output should look:

# cat sha512sumlist.txt
b1347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name
# sha512sum -c sha512sumlist.txt
file_name: OK

# cat sha512changedlist.txt
31347fc187453bdbd70ae1f4ca8214856ee24e994ffc65544c1c9ba84d4486177029f123070d939504f56e27e1fd6c9b3f2eec4f0174fd3a35fec570fa8192f0 file_name
# sha512sum -c sha512changedlist.txt
file_name: FAILED
sha512sum: WARNING: 1 computed checksum did NOT match

Conclusion

After trying these solutions, you shouldn’t have issues verifying checksums on Linux. If you still have trouble, however, contact our managed server support team, and we’ll make sure your files can be verified or, at the very least, tell you exactly why it’s impossible.

PS. If you found this post on verifying checksum helpful, please consider sharing it with your friends on social networks or leaving a comment in the comments section. Thank you.

The post How to Verify Checksum of a File on Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-verify-checksum-of-a-file-on-linux/feed/ 0
How to Fix MySQL Can’t Connect to Server Issues https://linuxhostsupport.com/blog/fix-mysql-cant-connect-to-server-issues/ https://linuxhostsupport.com/blog/fix-mysql-cant-connect-to-server-issues/#respond Mon, 15 Apr 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2070 Last month, we showed you how to resolve the “can’t connect to local server” error, though this won’t help if you’re using a remote MySQL server. As such, we’ve created this guide on “how to fix MySQL can’t connect to server issues”. MySQL is a popular open-source RDBMS, short for Relational Database Management System, widely […]

The post How to Fix MySQL Can’t Connect to Server Issues appeared first on LinuxHostSupport.

]]>
Last month, we showed you how to resolve the “can’t connect to local server” error, though this won’t help if you’re using a remote MySQL server. As such, we’ve created this guide on “how to fix MySQL can’t connect to server issues”.

MySQL is a popular open-source RDBMS, short for Relational Database Management System, widely used for web applications and other data-driven projects. It’s part of the LAMP/LEMP stack, and many popular websites and applications use it as a database system for storing data. However, users occasionally encounter issues where they can’t connect to the MySQL server, which can disrupt normally functioning applications. In this guide on how to fix MySQL can’t connect to server issues, we will explore common reasons for this problem and provide step-by-step solutions to help you resolve MySQL connection issues.

Check MySQL Server Status

Before diving into more complex troubleshooting, start by checking the status of your MySQL server. Ensure that the MySQL service is running and that there are no critical errors or warnings in the server logs. You can use the following command to check the MySQL service status:

# systemctl status mysql

You will receive similar output If the service is not running:

# systemctl status mysql
○ mariadb.service - MariaDB 10.6.12 database server
     Loaded: loaded (/lib/systemd/system/mariadb.service; enabled; vendor prese>
     Active: inactive (dead) since Fri 2024-01-12 23:41:21 UTC; 1s ago

Start the MySQL service using:

# systemctl start mysql

Verify MySQL Port and Network Configuration

The Default MySQL port for connections is 3306. Ensure that the MySQL server is configured to listen on the correct port and that there are no firewall or network issues preventing connections. Check the MySQL configuration file (usually located at /etc/mysql/my.cnf or /etc/my.cnf) for the following lines:

bind-address = 127.0.0.1
port = 3306

Ensure that the bind-address allows connections from the necessary IP addresses or is set to 0.0.0.0 to allow connections from any IP address. To check connectivity to the MySQL server on port 3306 you can also use the netcat command. You can do that by running the command:

nc -zv 192.168.2.20 3306

Instead of 192.168.2.20, you should use the IP address of the MySQL server. If the connection is successful, you should get similar output:

Connection to 192.168.2.20 3306 port [tcp/mysql] succeeded!

If the connection fails, you will see an output like this:

nc: connect to 192.168.2.20 port 3306 (tcp) failed: Connection refused

Then, you should log in to the MySQL server and check which port is MySQL listening on.

MySQL User Privileges

Incorrect user privileges may prevent successful connections to the MySQL server. Verify that the user attempting to connect has the necessary privileges. You can use the following MySQL command to grant privileges:

GRANT ALL PRIVILEGES ON database_name.* TO 'username'@'localhost' IDENTIFIED BY 'password';

Replace database_name, username, and password with your actual database name, username, and password. Then you can run the command:

FLUSH PRIVILEGES;

Then simply exit the MySQL shell and if the problem was with the MySQL user privileges you should be able to connect now.

Check for Network Issues

Network issues can often be a cause of connection problems. Ensure there are no network interruptions, and the server is accessible from the client machine. Ping the server to check for connectivity:

ping your_mysql_server_ip

If there are issues, check the network configuration, firewall settings, and any security groups or access control lists (ACLs) that may be blocking connections.

Examine MySQL Error Logs

MySQL logs provide valuable information about errors and warnings. Examine the MySQL error logs to identify any issues causing the connection problem. The error logs are typically located in the /var/log/mysql directory (check your MySQL configuration for the exact location) and are named error.log. You can find more information here that might help you identify the issue.

Resolving MySQL connection issues involves systematically identifying and addressing potential problems. By checking your server status, verifying port and network configurations, confirming user privileges, investigating network issues, and examining error logs, you can troubleshoot and fix MySQL can’t connect to server problems effectively. If you cannot solve this issue, you can always contact our Support Team, which will help you solve the problem without worrying too much about making the right changes.

The post How to Fix MySQL Can’t Connect to Server Issues appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/fix-mysql-cant-connect-to-server-issues/feed/ 0
How to Fix MySQL “Can’t connect to local server” https://linuxhostsupport.com/blog/how-to-fix-mysql-cant-connect-to-local-server/ https://linuxhostsupport.com/blog/how-to-fix-mysql-cant-connect-to-local-server/#respond Sat, 30 Mar 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2061 MySQL is an open-source relational database management system used for storing data. It is written in C and C++, offering various features that are very useful for developers and other users familiar with it. Often, it’s very useful to block off access to your MySQL server to prevent unauthorized access. Sometimes, you may lock yourself […]

The post How to Fix MySQL “Can’t connect to local server” appeared first on LinuxHostSupport.

]]>
MySQL is an open-source relational database management system used for storing data. It is written in C and C++, offering various features that are very useful for developers and other users familiar with it. Often, it’s very useful to block off access to your MySQL server to prevent unauthorized access. Sometimes, you may lock yourself out. In this blog post we will show you how to fix the MySQL connectivity issues when accessing MySQL as a local server. This blog post will teach you how to fix the dreaded “can’t connect to local server” issue. Let’s get started!

Prerequisites

  • A server with a Linux-based distribution (we used Ubuntu 22.04)
  • User privileges: root or non-root user with sudo privileges

MySQL Can’t connect to local server

The error message “can’t connect to local MySQL server through socket” can appear due to various reasons. One possibility is that the server cannot establish a connection to the MySQL server using its default socket due to an incorrect path to the socket file. Other reasons include incorrect permissions, misconfiguration in the MySQL setup, or the MySQL service is crashing unexpectedly due to a broken database, not enough RAM on the server, etc.

The socket is an endpoint where two processes communicate with each other. When we say the MySQL socket, we are talking about the mysqld.sock file located at /var/run/mysqld/mysqld.sock. Let’s go over the possible solutions for this connecting issue with the local MySQL server.

Let’s go over each possibility – we’re confident your MySQL server will be accessible locally once you try all of these solutions.

Check Your MySQL Service

Sometimes the MySQL service can stop unexpectedly due to various reasons. It may be due to insufficient disk space, not enough RAM, or the server has been rebooted and the MySQL service was not enabled to start on boot previously.

So, when we try to log in to the MySQL console with the following command:

mysql -u root -p

The connection cannot be established, and we will receive the following output:

root@host:~# mysql -u root -p
Enter password: 
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

First, we need to check if the MySQL service is up and running with the following command:

systemctl status mysql

If the service is not running, you should receive the following output:

root@host:~# systemctl status mysql
○ mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: inactive (dead)  since Mon 2024-01-08 18:19:37 CST; 13min ago
    Process: 30718 ExecStartPre=/usr/share/mysql/mysql-systemd-start pre (code=exited, status=0/SUCCESS)
    Process: 30749 ExecStart=/usr/sbin/mysqld (code=exited, status=0/SUCCESS)
   Main PID: 30749 (code=exited, status=0/SUCCESS)
     Status: "Server shutdown complete"
        CPU: 1.981s

We just need to start and enable the service with the command below:

sudo systemctl start mysql && sudo systemctl enable mysql

After checking the status again, you should receive the following output:

root@host:~# systemctl status mysql
● mysql.service - MySQL Community Server
     Loaded: loaded (/lib/systemd/system/mysql.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2024-01-08 18:32:21 CST; 8min ago
   Main PID: 30950 (mysqld)
     Status: "Server is operational"
      Tasks: 37 (limit: 4558)
     Memory: 365.3M
        CPU: 5.241s
     CGroup: /system.slice/mysql.service
             └─30950 /usr/sbin/mysqld

Try to log into your server now – it should be working again. If you are still seeing the same error, move onto the next potential solution.

MySQL Socket Permissions

Let’s say that we started and enabled the MySQL service, but we are still experiencing the error message:

ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/var/run/mysqld/mysqld.sock' (2)

Now we need to check if the socket file exists and is in the right directory with the correct permissions. Execute the command below:

ls -al /var/run/mysqld/

If you get this output:

root@host:~# ls -al /var/run/mysqld/
drwxr-xr-x  2 root root 120 Jan 8 19:12 .
drwxr-xr-x 32 root root 960 Jan 8 19:12 ..
srwxrwxrwx  1 root root   0 Jan 8 19:12 mysqld.sock
-rw-------  1 root root   6 Jan 8 19:12 mysqld.sock.lock

This output shows us that the permissions are incorrect – the root user owns the files. In this case, we need to set the right permissions:

chown -R mysql:mysql /var/run/mysqld/
chmod 755 /var/run/mysqld/

Once the permissions are set, restart the MySQL service and try to connect again to the MySQL console.

MySQL Configuration File

If you are still not able to connect to the MySQL console, or in other words your MySQL client can’t connect to a local server, then you should check the MySQL configuration file usually located at /etc/mysql/mysql.conf.d/mysqld.cnf – other locations for this include /etc/mysql/my.cnf, or even /etc/my.cnf. Find where your configuration file is and open it using your preferred text editor.

Look for the socket variable and make sure to put the full path of the socket file. If there is no socket variable, add it to your file like so:

socket = /var/run/mysqld/mysqld.sock

Make sure the permissions for that folder are set correctly as well. Save the file, close it and restart the MySQL service. Your MySQL client should be able to connect to your local server.

If none of this is solving the issue and if you have a managed Linux support plan with us, you can ask our support team to help you with your MySQL service. We are available 24/7 and are experts in system configuration, including with MySQL. We will be able to help you with the configuration of MySQL as well as any other issues you’re having with your server.

The post How to Fix MySQL “Can’t connect to local server” appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-fix-mysql-cant-connect-to-local-server/feed/ 0
How to Fix Themes Not Installing on WordPress https://linuxhostsupport.com/blog/how-to-fix-themes-not-installing-on-wordpress/ https://linuxhostsupport.com/blog/how-to-fix-themes-not-installing-on-wordpress/#respond Fri, 15 Mar 2024 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=2055 Finding the right theme for your WordPress website can take some time. Once you found the right WordPress theme, installing the WordPress theme is often easy and straightforward. However, sometimes you may face some problems or errors and the WordPress theme can’t be installed. You don’t want to look for another theme again and this […]

The post How to Fix Themes Not Installing on WordPress appeared first on LinuxHostSupport.

]]>
Finding the right theme for your WordPress website can take some time. Once you found the right WordPress theme, installing the WordPress theme is often easy and straightforward.

However, sometimes you may face some problems or errors and the WordPress theme can’t be installed. You don’t want to look for another theme again and this theme was perfect for your website. You are in luck – join us in this guide to help you fix the WordPress theme not installing problem on your website.

There are a few different ways that this problem can be solved, so please try and check each one. Odds are something here will fix your problem.

Your uploaded theme file exceeds the maximum file size

Let’s say you downloaded the theme that you want to install, and you navigate to Appearance -> Theme -> Add New Theme and you upload your theme.

Then you receive the following error message:

The uploaded file exceeds the upload_max_filesize directive in php.ini

Based on the error message, your PHP configuration resticts file uploads to a size that is smaller than the theme you tried to upload. Just like the error suggests, to fix the problem you’ll need to increase the upload_max_filesize value. Once that’s done, you can upload the theme, and it’ll likely work.

How to increase max file upload size for PHP in cPanel

If you have WHM & cPanel, you can log in to your cPanel account and click on “MultiPHP INI Editor” and select the WordPress domain in the Select Location drop-down menu. Then you can increase the “upload_max_filesize” value to be higher than the size of the WordPress theme that you are uploading. For example, if your theme is 50 megabytes in size, we recommend setting it to something like 75 megabytes.

How to increase max file upload size for PHP using php.ini

In case you don’t have WHM & cPanel, you should change the upload_max_filesize value in the php.ini file. You can find the php.ini file by creating a new file phpinfo.php in the DocumentRoot of your WordPress website with the following content inside.

<?php

phpinfo( );

?>

Then go ahead and save this file and navigate to https://your-domain.com/phpinfo.php in your favorite browser and you can find the location of the php.ini file in the section “Loaded Configuration File“.

Then open the php.ini file in the location where it is found and change upload_max_filesize from 25M for example to a larger number – one that is larger than the theme you want to upload. Save the file and exit. Restart your web server.

Also, make sure to delete the phpinfo.php file from your web server as revealing information about your environment invites attackers to find ways into your server through vulnerabilities.

Your PHP memory limit is too low

Another error that you may face is exhausting the memory with the following error message in your PHP log:

Fatal error: Allowed memory size of X bytes exhausted.

Same as in the previous example, you should increase the PHP memory limit from cPanel or by finding the php.ini file on your server and increasing the value for the “memory_limit” variable.

You can change the memory limit from cPanel by logging in to your cPanel account and navigating to the “MultiPHP INI Editor” and selecting the WordPress domain in the Select Location drop-down menu, then you can change the “memory_limit” value.

If you are not using cPanel you can find the php.ini file by creating a phpinfo.php file that will show you the php.ini location on your server. Then adjust your memory_limit variable from the default 128M to a larger number, such as 256M or 512M. Make sure to restart your web server.

“Installation Failed: Could Not Create Directory” Error

Two scenarios may cause this error. Your server has run out of disk space, or your cPanel or DirectAdmin account has reached the disk quota. In some extreme cases, if your server has too many files, you may reach the inodes limit on your server. Inodes are used to identify unique files and folders – it’s possible to run out of numbers even without running out of disk space.

To fix this error you should delete some old or unused files to free up some space/inodes, or upgrade your hosting plan.

Lack of permissions or ownership by the web server

Another problem that you can face is your directory or files might have incorrect permissions or ownership.

You can change the file and directory permissions of the WordPress directory using FTP or SFTP through your FTP client, such as FileZilla. This is a free application for Windows, macOS and Linux that lets you remotely connect to your server.

You can select the WordPress DocumentRoot, righ-click on it and select File permissions…

Then you can set 755 in the numeric value field > select recurse into subdirectories > apply to directories only and click ok.

Again you can repeat the same procedure right-click on the DocumentRoot, select File permissions… and set 644 in the numeric value field > select recurse into subdirectories > apply to files only and click ok.

To change the file permissions from your terminal you can navigate inside the WordPress website directory and run the following commands.

find . -type f -exec chmod 644 {} +
find . -type d -exec chmod 755 {} +

This will set the correct permissions for your WordPress files and directories.

You may also need to change the ownership of the files and directories to your web server’s user. Depending on what Linux distribution and web server you’re using, this user is named differently. It could be www-data, nginx, or apache to name a few.

To set the ownership of your WordPress installation, let’s say your WordPress is installed at the directory /var/www/html/wordpress/. To change the ownership of the entire WordPress installation to your web server user (in our example it is www-data), you can do that like so:

chown -R www-data:www-data /var/www/html/wordpress

With that, your web server should now be able to access all WordPress files and folders properly.

Incompatible plugins

Sometimes plugin compatibility may be the issue when you are installing a new theme. It may cause a conflict and you won’t be able to install the new theme. This is especially possible if your theme depends on some plugins to function properly. You can test this by installing some WordPress plugin compatibility checker or disabling all the plugins one by one to check which plugin is causing the issue.

Some of the themes may have requirements that you can check before installing. This may include incompatibility with certain plugins, which PHP versions and WordPress versions can be used.

Parse or Syntax Error with your theme

Another problem that you might encounter when installing a new WordPress theme is when you try to install some custom theme in WordPress, and you receive a syntax error. It’ll usually say something about “parse error” and “syntax error”. In this case, there’s a code issue within the theme itself. You should contact the theme developer or check the theme code for any syntax errors in the code.

What about child themes?

Installing child themes works in the same way as installing parent themes. You just need to ensure you keep the parent theme of your child theme installed. If you see any errors with the child theme but not with the parent theme, it’s possible that it is a permissions issue, in which case you can scroll up and try to fix your permissions again.

Conclusion

By trying each of these solutions, you shouldn’t have any issues with themes not installing on WordPress. If you still have trouble, however, get in touch with our managed server support team and we’ll make sure your themes can be installed, or we’ll at the very least tell you exactly why it’s not possible to install your theme.

The post How to Fix Themes Not Installing on WordPress appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-fix-themes-not-installing-on-wordpress/feed/ 0
How to Check and Change the Time Zone on Linux https://linuxhostsupport.com/blog/how-to-check-and-change-the-time-zone-on-linux/ https://linuxhostsupport.com/blog/how-to-check-and-change-the-time-zone-on-linux/#respond Thu, 15 Feb 2024 18:30:00 +0000 https://linuxhostsupport.com/blog/?p=2038 Time zones are very important for the Linux system because they can affect how the system operates, as well as affecting data displayed on your website for example. In this blog post, we will explain how to check and change the time zone on your Linux server. Setting the time and date is also important […]

The post How to Check and Change the Time Zone on Linux appeared first on LinuxHostSupport.

]]>
Time zones are very important for the Linux system because they can affect how the system operates, as well as affecting data displayed on your website for example. In this blog post, we will explain how to check and change the time zone on your Linux server. Setting the time and date is also important as it involves setting the correct time zone. These settings can be easily checked and changed according to your needs.

Changing the timezone on a Linux server is a very straightforward process. Let’s get things done!

Prerequisites

  • A server running a recent version of Linux
  • User privileges: root or non-root user with sudo privileges

Update the System

Before we make any changes to our Linux system, we should always update the packages to the latest version available. To do that, execute the following command:

sudo apt-get update -y && sudo apt-get upgrade -y

If there’s a new kernel update, you’ll need to restart to load the new kernel.

Check the Time Zone

All Linux servers have some kind of time zone that is already set. To check the time zone, we need to use the timedatecl command. The timedatectl command in Linux is used for displaying the current time on your server. It displays the system time, the hardware clock, and the time zone configured on your system. There is additional info as output from this command about the status of the systemd-timesyncd.service and clock synchronization.

Let’s execute the timedatectl command and see the exact output:

root@host:~# timedatectl
               Local time: Sun 2024-01-14 15:57:57 CST
           Universal time: Sun 2024-01-14 21:57:57 UTC
                 RTC time: Sun 2024-01-14 21:57:57
                Time zone: America/Chicago (CST, -0600)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

The first line displays the local time, the second line is the Universal time, and the third line is the hardware clock (RTC, or Real Time Clock). Then the timezone is displayed, and as you can see on our system it’s set to America/Chicago CST (Central Standard Time). After that is the info about the synchronization, the network time protocol service, and the hardware clock in the local time zone, which in this case is disabled.

We can check the time zone if we execute the date command:

root@host:~# date
Sun Jan 14 16:12:14 CST 2024

There is also another way to check the time zone, and that way is by listing the following file:

ls -l /etc/localtime

You should get the following outptut:

root@host:~# ls -al /etc/localtime
lrwxrwxrwx 1 root root 35 Jan  14 16:14 /etc/localtime -> /usr/share/zoneinfo/America/Chicago

As you can see, the timedatectl command is easier to use and the output of that command includes more details compared to the other methods.

Change the Time Zone on Linux

In the previous step, we explained different ways for checking the time zone. Now let’s cover how to change the current time zone on Linux.

Before changing the time zone, we need to list the available time zones with the following command:

timedatectl list-timezones

You will get a long list of time zones, as listed below:

Africa/Abidjan
Africa/Accra
Africa/Addis_Ababa
Africa/Algiers
Africa/Asmara
Africa/Asmera
Africa/Bamako
	.
	.
America/Anchorage
America/Anguilla
America/Antigua
America/Araguaina
America/Argentina/Buenos_Aires
America/Argentina/Catamarca
America/Argentina/ComodRivadavia
America/Argentina/Cordoba
America/Argentina/Ushuaia
	.
	.
Europe/Monaco
Europe/Moscow
Europe/Nicosia
Europe/Oslo
Europe/Paris
Europe/Podgorica
Europe/Prague
Europe/Riga
Europe/Rome
Europe/Samara
Europe/San_Marino

To change the current time zone to Europe/Monaco for example, you need to execute the following command:

timedatectl set-timezone Europe/Monaco

After executing this command, you can check the time zone to see the changes:

root@host:~# timedatectl
               Local time: Sun 2024-01-15 22:28:29 CET
           Universal time: Sun 2024-01-15 21:28:29 UTC
                 RTC time: Sun 2024-01-15 21:28:29
                Time zone: Europe/Monaco (CET, +0100)
System clock synchronized: yes
              NTP service: active
          RTC in local TZ: no

As you can see the time zone was successfully changed.

Another way to change the time zone is using the tzselect command:

root@host:~# tzselect
Please identify a location so that time zone rules can be set correctly.
Please select a continent, ocean, "coord", or "TZ".
1) Africa
2) Americas
3) Antarctica
4) Asia
5) Atlantic Ocean
6) Australia
7) Europe
8) Indian Ocean
9) Pacific Ocean
10) coord - I want to use geographical coordinates.
11) TZ - I want to specify the timezone using the Posix TZ format.
#? 

Now, you can select the continent, ocean, and coordinates, or specify the time zone using the Posix TZ format. Let’s choose number 1 for the Africa continent. You will get a list of all countries in Africa.

Please select a country whose clocks agree with yours.
 1) Algeria		  13) Côte d'Ivoire	    25) Iceland		      37) Namibia		49) Sudan
 2) Angola		  14) Djibouti		    26) Kenya		      38) Niger			50) Tanzania
 3) Benin		  15) Egypt		    27) Lesotho		      39) Nigeria		51) Togo
 4) Botswana		  16) Equatorial Guinea	    28) Liberia		      40) Rwanda		52) Tunisia
 5) Burkina Faso	  17) Eritrea		    29) Libya		      41) Sao Tome & Principe	53) Uganda
 6) Burundi		  18) Eswatini (Swaziland)  30) Madagascar	      42) Senegal		54) Western Sahara
 7) Cameroon		  19) Ethiopia		    31) Malawi		      43) Sierra Leone		55) Zambia
 8) Central African Rep.  20) Gabon		    32) Mali		      44) Somalia		56) Zimbabwe
 9) Chad		  21) Gambia		    33) Mauritania	      45) South Africa
10) Comoros		  22) Ghana		    34) Mayotte		      46) South Sudan
11) Congo (Dem. Rep.)	  23) Guinea		    35) Morocco		      47) Spain
12) Congo (Rep.)	  24) Guinea-Bissau	    36) Mozambique	      48) St Helena
#? 

We will choose number 45 for example to change the time zone to South Africa.

The following information has been given:

	South Africa

Therefore TZ='Africa/Johannesburg' will be used.
Selected time is now:	Mon Jan 15 13:00:40 SAST 2024.
Universal Time is now:	Mon Jan 15 11:00:40 UTC 2024.
Is the above information OK?
1) Yes
2) No
#? 

After that, we can confirm by typing 1 and hitting the Enter button. You will get the following screen:

You can make this change permanent for yourself by appending the line
	TZ='Africa/Johannesburg'; export TZ
to the file '.profile' in your home directory; then log out and log in again.

Here is that TZ value again, this time on standard output so that you
can use the /usr/bin/tzselect command in shell scripts:
Africa/Johannesburg 

You should definitely add that line to your .profile file so that your time zone is remembered when you next login:

echo "TZ='Africa/Johannesburg'; export TZ" >> ~/.profile

Congratulations! You successfully changed your time zone using two different ways.

Of course, you don’t have to spend your time on this and if you have a managed Linux support plan with us. We will help you with any aspect of your server time zones, including any app-specific time zone settings. You can simply ask our support team – they are available 24/7 and will be able to help you with your time zone as well as any additional requirements that you may have.

The post How to Check and Change the Time Zone on Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-check-and-change-the-time-zone-on-linux/feed/ 0
5 most Used dig Commands in Linux With Examples  https://linuxhostsupport.com/blog/5-most-used-dig-commands-in-linux-with-examples/ https://linuxhostsupport.com/blog/5-most-used-dig-commands-in-linux-with-examples/#respond Wed, 15 Feb 2023 18:30:00 +0000 https://linuxhostsupport.com/blog/?p=1761 The DIG command offers a vast amount of functionalities and different options. In this guide, we’ll learn more about some of the most important functionalities for DNS troubleshooting. What is the DIG command? DIG command (Domain Information Groper command) is a tool with a basic command-line interface that serves for making different DNS (domain name […]

The post 5 most Used dig Commands in Linux With Examples  appeared first on LinuxHostSupport.

]]>
The DIG command offers a vast amount of functionalities and different options. In this guide, we’ll learn more about some of the most important functionalities for DNS troubleshooting.

What is the DIG command?

DIG command (Domain Information Groper command) is a tool with a basic command-line interface that serves for making different DNS (domain name system) queries. You can use the DIG command to:

– Check all of the available DNS records or individual DNS records
– Diagnose the name servers of your domain.
– Trace IP addresses.
– See the hostnames that correspond to an IP address.

And many other aspects that you can read directly on their manual. You can find the DIG command pre-installed on most Linux distros. Also, you can easily install it on macOS, too with brew, and get the DIG command on Windows 10 with bind9.

Top 5 most used DIG commands:

Here you have five examples of DIG command. We will use rosehostingtest.com as a hostname and 1.1.1.1. as an IP address. Feel free to try these commands with the domain and IP address you want by simply changing the text before you try.

Once you are on your terminal, we can proceed with the following commands:

1. Finding the website IP address

To do that function, everything you need to do is simply use the dig command with the domain name after it, for example:

dig rosehostingtest.com

This will return you the A record of your hostname but with a lot of details together, here is an example:

➜  ~ dig rosehostingtest.com

; <<>> DiG 9.10.6 <<>> rosehostingtest.com
;; global options: +cmd
;; Got answer:
;; ->>HEADER<<- opcode: QUERY, status: NOERROR, id: 40154
;; flags: qr rd ra; QUERY: 1, ANSWER: 2, AUTHORITY: 0, ADDITIONAL: 1

;; OPT PSEUDOSECTION:
; EDNS: version: 0, flags:; udp: 512
;; QUESTION SECTION:
;rosehostingtest.com. IN A

;; ANSWER SECTION:
rosehostingtest.com. 300 IN A 104.21.51.178
rosehostingtest.com. 300 IN A 172.67.183.57

;; Query time: 53 msec
;; SERVER: 8.8.8.8#53(8.8.8.8)
;; WHEN: Tue Dec 20 12:23:50 -03 2022
;; MSG SIZE  rcvd: 80

If you want an answer with fewer details, you can add +short to your command, no matter if it’s before or after the hostname, you can use it together with your domain and it will return only the IP address:

➜  ~ dig rosehostingtest.com +short
104.21.51.178

From now on, in this guide, we’ll use the +short option so it’s less information making it more friendly to be readen.

2. Getting the NameServers from the domain.

For that usage, instead of only using the dig command, we had to add the option NS to our command. So, to get the nameservers of your domain name, you can use the following command:

➜  ~ dig rosehostingtest.com NS +short
aragorn.ns.cloudflare.com.
coco.ns.cloudflare.com.

Here you can see to which DNS the domain you are checking is pointing to.

3. Check the path of your DNS.

This option will show you the path from the root servers to the DNS zone of the hostname that you are querying. To use the trace option, you should run:

➜  ~ dig rosehostingtest.com +trace +short
NS h.root-servers.net. from server 8.8.8.8 in 44 ms.
NS b.root-servers.net. from server 8.8.8.8 in 44 ms.
NS k.root-servers.net. from server 8.8.8.8 in 44 ms.
NS m.root-servers.net. from server 8.8.8.8 in 44 ms.
NS c.root-servers.net. from server 8.8.8.8 in 44 ms.
NS a.root-servers.net. from server 8.8.8.8 in 44 ms.
NS f.root-servers.net. from server 8.8.8.8 in 44 ms.
NS j.root-servers.net. from server 8.8.8.8 in 44 ms.
NS d.root-servers.net. from server 8.8.8.8 in 44 ms.
NS i.root-servers.net. from server 8.8.8.8 in 44 ms.
NS g.root-servers.net. from server 8.8.8.8 in 44 ms.
NS e.root-servers.net. from server 8.8.8.8 in 44 ms.
NS l.root-servers.net. from server 8.8.8.8 in 44 ms.
RRSIG NS 8 0 518400 20230102050000 20221220040000 18733 . Ban8EH/5IIhAO5yzTrFjKFL/ZblByKCk1ln3kXGqwwusnoBTY6fpXY/4 bQztpIpYGEE0O0Nh6afh6O2Uk/BtFvZf1YT6t1xRFZOJJ2fQGntqnvYt VX0HLYwrGmWZiaTcRWVWezLDJ/xQrxab1FGH/09qn9UQjfkswN372vb3 feGu2vbti9I63rzKTl2wJFn95jwkTRwkgrXUfP10znzJpCj3B8ZCPtN+ cvwWWrUFu1Yj5DuOS3c0SRDrcF4YFkRQTc3Fy/kMlqAvbuDuKKmGuo+f E0+oBXFWroFPLf7wB6dbHOGxoppNokqjDN1VyAHQx0uMWnfRksMpq3RC 8u3GIw== from server 8.8.8.8 in 44 ms.
A 104.21.51.178 from server 2a06:98c1:50::ac40:2143 in 37 ms.
A 172.67.183.57 from server 2a06:98c1:50::ac40:2143 in 37 ms.
RRSIG A 13 2 300 20221221162911 20221219142911 34505 rosehostingtest.com. Nn6Pr3DT0JjfqH2yV1HlMPMIbfsFYr4Voyvb5kR6aV70cTGdrItRmi6E cIKc6eDoPWJUdoIpIuDUuDwj3wcpyA== from server 2a06:98c1:50::ac40:2143 in 37 ms.

The output will show you the route of your DNS query goes. You can check if the connection is hoping somewhere to troubleshoot your DNS problems, so you can get exactly when it’s lost.

4. Checking the entries responsible for mails.

All emails to be received by the recipient, requires the domain to have their MX records properly setup, you can check yours by using the following command:

➜  ~ dig rosehostingtest.com MX +short
31 route2.mx.cloudflare.net.
42 route1.mx.cloudflare.net.
66 route3.mx.cloudflare.net.

So in our example case, the email from the test domain is handled by Cloudflare, and any email issues or problems need to be checked directly with them.

5. Check the RDNS of an IP address.

You can easily get a reverse DNS from one ip address (this means the hostname that is associated with the ip address basically) using this dig command:

➜  ~ dig -x 1.1.1.1 +short
one.one.one.one

The hostname of the queried IP address will be available on the output.

Those are the most useful commands from the dig, but you can use more options that are available in their own manual. You can run:

man dig

dig -h

This will show ALL The options available so you can do different queries. Of course, if you have an active server and need assistance in troubleshooting your DNS servers, do not hesitate to contact us. We are available 24/7/365 to help you.

The post 5 most Used dig Commands in Linux With Examples  appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/5-most-used-dig-commands-in-linux-with-examples/feed/ 0
5 Ways to Empty or Delete a Large File in Linux https://linuxhostsupport.com/blog/5-ways-to-empty-or-delete-a-large-file-in-linux/ https://linuxhostsupport.com/blog/5-ways-to-empty-or-delete-a-large-file-in-linux/#respond Mon, 30 Jan 2023 18:30:00 +0000 https://linuxhostsupport.com/blog/?p=1755 In this article, we will go over five different ways to empty/delete a large file in Linux. You might have a file that’s gigabytes in size that you want to get rid of quickly, or you want to automate emptying a file for each iteration. Whatever the case may be, you’ll be able to easily […]

The post 5 Ways to Empty or Delete a Large File in Linux appeared first on LinuxHostSupport.

]]>
In this article, we will go over five different ways to empty/delete a large file in Linux.

You might have a file that’s gigabytes in size that you want to get rid of quickly, or you want to automate emptying a file for each iteration. Whatever the case may be, you’ll be able to easily delete or empty a file with help from this article.

We’ll be running these commands on an Ubuntu 22.04 VPS, but pretty much all of these commands should work on any modern distribution.

Prerequisites

  • A Linux VPS or a dedicated server of your choosing
  • Write access to the file or root/sudo privileges

1. Using /dev/null to empty the contents of a file

What is /dev/null?

The software device file (found in the /dev/ directory) called “null” is a file with two very simple purposes. It discards or deletes any data written to it or returns EOF (short for “end-of-file”) if you try to read its contents. In this case, we are going to read from /dev/null.

You can use the cat command (which is short for concatenate) to read the contents of /dev/null, followed by a redirection operator to redirect the output into the file we want to empty.

cat /dev/null > yourFile.ext

What this does is output the contents of /dev/null and then redirect that content into your file. The contents of your file are essentially starting with “End of file,” making it empty.

What does > do?

This redirection operator takes whatever data would’ve been printed to the console and allows you to place it into any file. Using only one > replaces the contents of the file with the data you are redirecting, and using two of them >> appends the data to the end of the file. Since we want to empty our file, we only use one > to replace the contents.

Here is a screenshot as an example.

You can see the text that says “10G” (short for ten gigabytes) changes to, say 0 (zero bytes) after our command is executed.

Unfortunately, you cannot delete a file using /dev/null as it can only do the two functions mentioned earlier.

2. Using echo to empty the contents of a file

You can use the echo command, normally designed to send data to stdout (standard output or your console) and use a redirection operator again to place the contents of your echo command into the file you want to empty.

echo > yourFile.txt

The echo command outputs a new line when no input is provided. When combining this with a redirection of the output into your file, your file gets replaced with only the new line.

This is how it looks in practice:

As you can see, the file’s contents are emptied. You might notice, however, that unlike the previous method shown, this file now has a size of 1 byte instead of 0 bytes. This is because we store a newline instead of a truly empty file. If your use case requires that the file have a size of zero bytes, then this method won’t work for you.

Additionally, you cannot delete files using the echo command. Echo can only create data, not destroy it.

3. Using a redirection operator to empty the contents of a file

You may have noticed our use of redirection operators in both methods listed above to empty the contents of a file. Instead of using commands to redirect output, we can actually take advantage of this redirection to empty our file.

> yourFile.txt

You can see in this command we are redirecting nothing! By doing this, we are taking the output of nothing and replacing the contents of our file with it.

This is what it looks like when you run the command using only redirection:

You should note that the file is emptied completely, with a file size of zero bytes. This is the easiest and fastest way to empty a file.

Once again, this method won’t work for deleting files, as it only redirects content instead of destroying it.

4. Using truncate to empty the contents of a file

This great command lets you truncate (or cut short) the content of any file easily and quickly. Interestingly, the name does not suggest it, but you can also use this command to increase the apparent size of any file too.

truncate -s 0 yourFile.txt

What this command does is execute the truncate command, the option -s 0 sets the size to zero bytes.

You can see the example below:

This command does exactly as advertised, setting the file size to 0 bytes by truncating anything past that size.

Once again, this useful tool only sets the size of files; it does not delete them.

5. Using rm or unlink to delete a file

Now that we have seen multiple ways to empty the contents of a file, it’s about time we see ways to delete the file altogether. Luckily, there are two different ways of doing so.

Delete a file with the rm command

The rm command (short for remove) does one task extremely well: removing files and directories.

rm yourFile.txt

By running this, your file will be deleted instantly.

Another option is the unlike command, which simply calls the unlink function, which removes the link to the file.

unlink yourFile.txt

If no process is using the file, then the file is deleted, and the filesystem reclaims the space.

Here are some examples detailing how they work:

The next image shows the use of unlink:

With these commands, however, the opposite issue is the case – you cannot empty the contents of the file. You can only delete the file or destroy the link to the file.

However, if you are a user of our Managed VPS hosting services, make sure to use our team of Linux experts. Not only will they give you a list of all of the large files on your system, but they can also clear their contents, delete the files, or even set up a rotation of these files to ensure their size stays small automatically.

Did this post help you empty or delete a large file on your filesystem? If so, please consider spreading the word so others can benefit from this tip. Have any other methods of emptying or deleting a file? Let us know in our comment section below!

The post 5 Ways to Empty or Delete a Large File in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/5-ways-to-empty-or-delete-a-large-file-in-linux/feed/ 0
10 Useful cron Commands in Linux With Examples https://linuxhostsupport.com/blog/10-useful-cron-commands-in-linux-with-examples/ https://linuxhostsupport.com/blog/10-useful-cron-commands-in-linux-with-examples/#respond Tue, 15 Nov 2022 18:30:00 +0000 https://linuxhostsupport.com/blog/?p=1730 In this tutorial, we will explain ten useful cron commands in Linux with examples. The cron command is used for scheduling tasks to be executed in a specific period, like a month, day, hour, minute, or even seconds. The cron uses a table of tabs called crontabs which have a list of commands that need […]

The post 10 Useful cron Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
In this tutorial, we will explain ten useful cron commands in Linux with examples.

The cron command is used for scheduling tasks to be executed in a specific period, like a month, day, hour, minute, or even seconds. The cron uses a table of tabs called crontabs which have a list of commands that need to be executed with their times respectively. These cron commands are used by system administrators mostly, to make their work easier and be sure not to forget to execute something during a specific period of their work.

In this tutorial, we are going to use Ubuntu 20.04, but you can choose any Linux distro you want. Let’s get started!

Prerequisites

  • Fresh install of Ubuntu 20.04 OS
  • User privileges: root or non-root user with sudo privileges

Update the System

Before we start with the ten useful cron commands, we need to update the system packages to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Once the system is updated, we are ready to show you the basic cron commands in Linux.

1. Manage crond service

To check the status of the crond service, execute the following command:

systemctl status cron.service

You should receive the following output:

root@host:~# systemctl status cron.service
● cron.service - Regular background program processing daemon
     Loaded: loaded (/lib/systemd/system/cron.service; enabled; vendor preset: enabled)
     Active: active (running) since Mon 2022-08-08 23:57:40 CEST; 1 weeks 3 days ago
       Docs: man:cron(8)
   Main PID: 583 (cron)
      Tasks: 1 (limit: 4611)
     Memory: 11.7M
     CGroup: /system.slice/cron.service
             └─583 /usr/sbin/cron -f

For starting, stopping, and restarting the cron service, you can use the following commands respectively:

systemctl start cron.service

systemctl stop cron.service

systemctl restart cron.service

2. List the jobs

To list the jobs for the current user, execute the following command:

crontab -l

The output should look similar to this because we do not have cron jobs set yet:

root@host:/var/www/html# crontab -l
no crontab for root

3. Create your first cron job

To create your first cron job execute the following command:

crontab -e

After executing this command, the file will be opened, and you can paste the following lines of code:

1 0 * * *   root cd /var/www/html && /usr/bin/sh script.sh

Save the file and close it. If you execute the command crontab -l, you will get this:

root@host:/var/www/html# crontab -l
# Edit this file to introduce tasks to be run by cron.
#
# Each task to run has to be defined through a single line
# indicating with different fields when the task will be run
# and what command to run for the task
#
# To define the time you can provide concrete values for
# minute (m), hour (h), day of month (dom), month (mon),
# and day of week (dow) or use '*' in these fields (for 'any').
#
# Notice that tasks will be started based on the cron's system
# daemon's notion of time and timezones.
#
# Output of the crontab jobs (including errors) is sent through
# email to the user the crontab file belongs to (unless redirected).
#
# For example, you can run a backup of all your user accounts
# at 5 a.m every week with:
# 0 5 * * 1 tar -zcf /var/backups/home.tgz /home/
#
# For more information see the manual pages of crontab(5) and cron(8)
#
# m h  dom mon dow   command
1 0 * * *   cd /var/www/html && /usr/bin/sh script.sh

4. Schedule a job every 10 minutes

To schedule a job to run every 10 minutes, add the following lines with the crontab -e command:

*/10 * * * * root cd /var/www/html && /usr/bin/sh script.sh

This cron will call the script every 10 minutes.

5. Schedule a job every hour

To schedule a cron job to run every hour, add the following lines with the crontab -e command:

0 * * * * root cd /var/www/html && /usr/bin/sh script.sh

6. Schedule a job every day at 10:00 AM

Now, we will show you a different way to schedule a cron job. Open the file /etc/crontab. You should see the following lines of code:

# /etc/crontab: system-wide crontab
# Unlike any other crontab you don't have to run the `crontab'
# command to install the new version when you edit this file
# and files in /etc/cron.d. These files also have username fields,
# that none of the other crontabs do.

SHELL=/bin/sh
PATH=/usr/local/sbin:/usr/local/bin:/sbin:/bin:/usr/sbin:/usr/bin

# Example of job definition:
# .---------------- minute (0 - 59)
# |  .------------- hour (0 - 23)
# |  |  .---------- day of month (1 - 31)
# |  |  |  .------- month (1 - 12) OR jan,feb,mar,apr ...
# |  |  |  |  .---- day of week (0 - 6) (Sunday=0 or 7) OR sun,mon,tue,wed,thu,fri,sat
# |  |  |  |  |
# *  *  *  *  * user-name command to be executed
17 *    * * *   root    cd / && run-parts --report /etc/cron.hourly
25 6    * * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.daily )
47 6    * * 7   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.weekly )
52 6    1 * *   root    test -x /usr/sbin/anacron || ( cd / && run-parts --report /etc/cron.monthly )
#

Now to add the cron job to execute every day at 10:00 AM, just add the following line at the bottom of the file, save it and close it.

0 0 * * * root cd /var/www/html && /usr/bin/sh script.sh

7. Schedule a job At 12:00 AM, only on Friday

To schedule this job, open the /etc/crontab file and paste the following command:

0 0 * * FRI root cd /var/www/html && /usr/bin/sh script.sh

8. Schedule a job for a daily backup

To schedule a daily backup, for example, with some script that will execute commands to generate a daily backup, you do not have to specify intervals. You just need to place the script to the /etc/cron.daily directory on your server:

9. Understanding the cron directories

In the previous example, we explained how to enable daily backup by putting some script into it. What if we want our script to be executed hourly, weekly, or monthly? Do not worry about that. Just execute ls -al /etc/cron and hit tab in your terminal server:

root@host:/var/www/html# ll /etc/cron
cron.d/       cron.daily/   cron.hourly/  cron.monthly/ crontab       cron.weekly/

As you can see, there are directories for different periods where you can place your scripts, which will be executed automatically.

10. Man command for cron

If you want to learn more about the cron, you must execute man cron in your terminal. You should receive complete documentation about the cron command:

CRON(8)                                                               System Manager's Manual                                                               CRON(8)

NAME
       cron - daemon to execute scheduled commands (Vixie Cron)

SYNOPSIS
       cron [-f] [-l] [-L loglevel]

DESCRIPTION
       cron is started automatically from /etc/init.d on entering multi-user runlevels.

OPTIONS
       -f      Stay in foreground mode, don't daemonize.

       -l      Enable  LSB  compliant  names  for  /etc/cron.d  files.   This  setting,  however,  does  not  affect  the  parsing of files under /etc/cron.hourly,
               /etc/cron.daily, /etc/cron.weekly or /etc/cron.monthly.

       -n      Include the FQDN in the subject when sending mails.  By default, cron will abbreviate the hostname.

       -L loglevel
               Tell cron what to log about jobs (errors are logged regardless of this value) as the sum of the following values:

That’s it. You just learned how to set up cron jobs on your own in different ways. If you find this difficult and you want some specific cron at a specific time, just contact our technical support, and they will do the rest. We are available 24/7.

If you liked this post about ten useful cron commands in Linux with examples, please share it with your friends on social networks or simply leave a reply below.

The post 10 Useful cron Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/10-useful-cron-commands-in-linux-with-examples/feed/ 0
5 Most Used Echo Commands in Linux With Examples https://linuxhostsupport.com/blog/5-most-used-echo-commands-in-linux-with-examples/ https://linuxhostsupport.com/blog/5-most-used-echo-commands-in-linux-with-examples/#comments Sun, 30 Oct 2022 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=1723 This blog post will show you the five most used echo commands in Linux with examples. The echo command in Linux is a command that outputs the strings passed to its arguments. The echo command is supported on various Linux distributions such as Ubuntu, CentOS, Debian, and other OS like Windows. This command is most […]

The post 5 Most Used Echo Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
This blog post will show you the five most used echo commands in Linux with examples.

The echo command in Linux is a command that outputs the strings passed to its arguments. The echo command is supported on various Linux distributions such as Ubuntu, CentOS, Debian, and other OS like Windows. This command is most used in shell scripts and batch files to output status text to the screen.

In this tutorial, we will use the latest Ubuntu 22.04 OS, but you can choose any Linux distro per your choice. Let’s get started!

Prerequisites

  • A server with Ubuntu 22.04 OS
  • User privileges: root or non-root user with sudo privileges

Update the System

It is recommended to update the system packages to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Once the system is updated, we are ready to show you the five most used echo commands in Linux.

Syntax of the echo command

The syntax of the echo command is the following:

echo [option(s)] [string(s)]

The echo command is simple and is being executed with the main word echo using some options and strings next to it.

1. Display simple line to standard output

To display a single line as text on standard output, execute the following echo command with the string:

echo This blog post will teach you about the echo command.

This is how looks the output of this command:

root@host:~# echo This blog post will teach you about the echo command.
This blog post will teach you about the echo command.

2. Print Files and Folders

The echo command can be used to print all files and folders in some directory as an alternative to the ls -al command for listing.

echo *
This is the output of the command above:
root@host:/# echo *
bin boot core dev etc home lib lib32 lib64 libx32 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var

3. Redirect operator to output text in a file

The following command will redirect the output in the file instead of the standard output on the command line.

echo * > outputfile.txt

To check the content of the file, execute the cat outputfile.txt command, and you should receive the same as in the previous paragraph:

root@host:/# cat outputfile.txt
bin boot core dev etc home lib lib32 lib64 libx32 lost+found media mnt opt proc root run sbin snap srv sys tmp usr var

4. Removing Text Spacing

To remove the text spacing in some lines, execute the following command with option -b:

echo -e "This \bblog \bpost \bwill \bhelp \byou \bwith \understanding \bthe \becho \bcommand"

You should get the following output:

root@host:/# echo -e "This \bblog \bpost \bwill \bhelp \byou \bwith \bunderstanding \bthe \becho \bcommand"
Thisblogpostwillhelpyouwithunderstaingtheechocommand

5. Displaying the Text in Multiple Lines

To display the text in multiple lines, execute the following command with option \n.

echo -e "This \nblog \npost \nwill \nhelp \nyou \nwith \nunderstanding \nthe \necho \ncommand"

You should get the following output:

root@host:/# echo -e "This \nblog \npost \nwill \nhelp \nyou \nwith \nunderstaing \nthe \necho \ncommand"
This
blog
post
will
help
you
with
understanding
the
echo
command

These were the most used echo commands on a daily basis by system administrators and other Linux users. If you want to know more about the echo command, just execute the command man echo, and you will get a complete definition of echo and its usage:

root@host:/# man echo
ECHO(1)                                                                    User Commands                                                                    ECHO(1)

NAME
       echo - display a line of text

SYNOPSIS
       echo [SHORT-OPTION]... [STRING]...
       echo LONG-OPTION

DESCRIPTION
       Echo the STRING(s) to standard output.

       -n     do not output the trailing newline

       -e     enable interpretation of backslash escapes

       -E     disable interpretation of backslash escapes (default)

       --help display this help and exit

       --version
              output version information and exit

       If -e is in effect, the following sequences are recognized:

       .
       .
       .
       .
       .

That’s it. You just learned to use the echo command on Linux with examples. Of course, if you need some help with this, you just need to sign up for one of our NVMe plans and submit a support ticket. Our admins will start work on your request immediately. We are available 24/7.

If you liked this post about the five most used echo commands in Linux with examples, please share it with your friends on social networks or simply leave a reply below.

The post 5 Most Used Echo Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/5-most-used-echo-commands-in-linux-with-examples/feed/ 1
5 Most Used Touch Commands in Linux With Examples https://linuxhostsupport.com/blog/5-most-used-touch-commands-in-linux-with-examples/ https://linuxhostsupport.com/blog/5-most-used-touch-commands-in-linux-with-examples/#comments Sat, 15 Oct 2022 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=1720 In this tutorial, we are going to show you the most used touch commands in Linux with examples. The touch command is a standard command in Linux operating system used on daily basis by the system administrators, developers, and other users familiar with the Linux command line. With the touch command, we can easily create […]

The post 5 Most Used Touch Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
In this tutorial, we are going to show you the most used touch commands in Linux with examples.

The touch command is a standard command in Linux operating system used on daily basis by the system administrators, developers, and other users familiar with the Linux command line. With the touch command, we can easily create files, empty files, modify files, timestamps and etc.

In this tutorial, we will execute the touch commands on Ubuntu 20.04 OS, but you can choose any Linux distro. Le’ts get started!

Prerequisites

  • A server with Ubuntu 20.04 OS
  • User privileges: root or non-root user with sudo privileges

Update the System

If you have a fresh installation of Ubuntu 20.04, it is recommended to update the system packages to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Once the system is updated, we are ready to show you the basic touch commands in Linux.

1. Create a File

To create an empty zero byte file, execute the following command:

touch file.txt

You can check the size of the file:

-rw-r--r--  1 root root 0 Aug 14 22:58 file.txt

2. Change only the access time

To change only the access time to the file, you need to execute the following command:

touch -a file.txt

This command will update the last access modification time and will create the file if it does not exists.

3. Use the timestamp of another file

Sometimes we need to set the same timestamp to a file from another file. To do that, execute the following command:

touch -r file1.txt file2.txt

This command will update the timestamp of file2.txt with the timestamp of file file1.txt.

4. Create a file with a specific timestamp

To create a file and specify the time, you need to execute the following command:

touch -t 202208181118.34 file-time

The command above will create the file-time with a timestamp on August 18, 2022, at 11:18:34 AM.

5. Creating Multiple files

In the above examples, we were creating only a single file. Sometimes we need multiple files to be created. To do that, we can simply use the touch command with multiple file names:

touch file1.txt file2.txt file3.txt

This command will create three files at once:

-rw-r--r--  1 root root    0 Aug 15 11:51 file1.txt
-rw-r--r--  1 root root    0 Aug 15 11:51 file2.txt
-rw-r--r--  1 root root    0 Aug 15 11:51 file3.txt

Learn more about the touch command

In the previous paragraphs, we covered the most used touch commands. There is a brief explanation of the touch command along with options in Linux. To learn more about the touch command, execute the man touch command in your terminal.

man touch

You should get the following output:

TOUCH(1)                                                                   User Commands                                                                   TOUCH(1)

NAME
       touch - change file timestamps

SYNOPSIS
       touch [OPTION]... FILE...

DESCRIPTION
       Update the access and modification times of each FILE to the current time.

       A FILE argument that does not exist is created empty, unless -c or -h is supplied.

       A FILE argument string of - is handled specially and causes touch to change the times of the file associated with standard output.

       Mandatory arguments to long options are mandatory for short options too.

       -a     change only the access time

       -c, --no-create
              do not create any files

       -d, --date=STRING
              parse STRING and use it instead of current time

       -f     (ignored)

       -h, --no-dereference
              affect each symbolic link instead of any referenced file (useful only on systems that can change the timestamps of a symlink)

       -m     change only the modification time

       -r, --reference=FILE
              use this file's times instead of current time

       -t STAMP
              use [[CC]YY]MMDDhhmm[.ss] instead of current time

       --time=WORD
              change the specified time: WORD is access, atime, or use: equivalent to -a WORD is modify or mtime: equivalent to -m

       --help display this help and exit

Congratulations! You learned the basic touch commands with examples applicable to every Linux distribution.

You learned how to create one file or multiple files with specific timestamps. If you find it challenging to understand the touch command and you are not able to manage the files on your server, you can simply contact our epic technical support, and they will do the rest. You only need to sign up for one of our NVMe VPS plans and submit a support ticket. We are available 24/7.

If you liked this post about the five most used touch commands in Linux, please share it with your friends on social networks or simply leave a reply below. Thanks.

The post 5 Most Used Touch Commands in Linux With Examples appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/5-most-used-touch-commands-in-linux-with-examples/feed/ 1
10 Useful iptables Commands in Linux https://linuxhostsupport.com/blog/10-useful-iptables-commands-in-linux/ https://linuxhostsupport.com/blog/10-useful-iptables-commands-in-linux/#respond Tue, 30 Aug 2022 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=1714 In this tutorial we are going to explain to you 10 useful iptables commands applicable in any Linux distro. Iptables on Linux servers are used for controlling the incoming and outgoing web traffic. The traffic is controlled by the iptables rules in the firewall written by system administrators or users familiar with Linux servers. The […]

The post 10 Useful iptables Commands in Linux appeared first on LinuxHostSupport.

]]>
In this tutorial we are going to explain to you 10 useful iptables commands applicable in any Linux distro.

Iptables on Linux servers are used for controlling the incoming and outgoing web traffic. The traffic is controlled by the iptables rules in the firewall written by system administrators or users familiar with Linux servers. The rules in iptables are stored in tables that have chains for every defined rule. In this blog post, we are going to use Ubuntu 22.04 as OS, but you can choose any distro if you want to try these iptables commands by yourself. Let’s get started!

Prerequisites

  • Fresh install of Ubuntu 22.04 OS
  • User privileges: root or non-root user with sudo privileges

Update the System

Before we start with the basic iptables rules we are going to update the system packages to the latest versions available.

sudo apt update -y && sudo apt upgrade -y

Once, the system is updated we are ready to show you the basic iptables commands in Linux.

Install iptables service

To install the iptables service execute the following command:

sudo apt-get install iptables -y

Once, the iptables service is installed we can proceed with the basic iptables rules in the next paragraphs.

1. Check iptables rules

Since, we installed the iptables service and we did not add any rule, checking the iptables rules should give you empty output.

iptables -nvL

You should receive the following output:

root@host:~# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

2. Whitelist IP Address

Sometimes the users are not able to access the website, or the server thus we need to whitelist their IP address manually with the following command:

iptables -A INPUT -s 192.168.1.1 -j ACCEPT

3. Block IP Address

If there are continuous attacks on the server, or the owner do not want some IP addresses to have access on his server, we can easily block them with the following command:

iptables -A INPUT -s 192.168.0.1 -j DROP

4. Block Host in iptables

Sometimes we need to block the whole host in the iptables rules. For example to block google.com in the iptables rules first you need to find the IP address and the CIDR with the following commands:

host google.com

You should receive the following output:

root@host:~# host google.com
google.com has address 172.217.4.46
google.com has IPv6 address 2607:f8b0:4004:c07::64
google.com has IPv6 address 2607:f8b0:4004:c07::8b
google.com has IPv6 address 2607:f8b0:4004:c07::65
google.com has IPv6 address 2607:f8b0:4004:c07::71
google.com mail is handled by 10 smtp.google.com.

Now, to find the CIDR execute the following command:

whois 172.217.4.46 | grep CIDR

You should receive the following output:

root@host:~# whois 172.217.4.46 | grep CIDR
CIDR:           172.217.0.0/16

We have everything that we need to block the google network. Just execute the following command:

iptables -A OUTPUT -p tcp -d 172.217.0.0/16 -j DROP

5. Block Specific Port

For example if we do not want some specific port to be accessible from outside, we can easily block it. To block outgoing connections on the MySQL 3306 port via iptables rules execute the following command:

iptables -A OUTPUT -p tcp --dport 3306 -j DROP

6. Grant Access to multiple ports

To allow multuple ports for incoming connections execute the following command:

iptables -A INPUT  -p tcp -m multiport --dports 80,443 -j ACCEPT

To allow multuple ports for outgoing connections execute the following command:

iptables -A OUTPUT -p tcp -m multiport --sports 80,443 -j ACCEPT

7. Port Forwarding

To set up port forwarding and forward for example port 80 to port 443 execute the following command:

iptables -t nat -A PREROUTING -i eth0 -p tcp --dport 80 -j REDIRECT --to-port 443

8. Save iptables rules

For example to save all these iptables commands you need to execute the following command:

iptables-save

You should receive the following output:

root@host:~# iptables-save
# Generated by iptables-save v1.8.7 on Fri Jul 22 23:52:08 2022
*filter
:INPUT ACCEPT [0:0]
:FORWARD ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
-A INPUT -s 192.168.0.1/32 -j ACCEPT
-A INPUT -s 192.168.0.1/32 -j DROP
-A INPUT -p tcp -m multiport --dports 80,443 -j ACCEPT
-A OUTPUT -d 172.217.0.0/16 -p tcp -j DROP
-A OUTPUT -p tcp -m tcp --dport 3306 -j DROP
-A OUTPUT -p tcp -m multiport --sports 80,443 -j ACCEPT
COMMIT
# Completed on Fri Jul 22 23:52:08 2022
# Generated by iptables-save v1.8.7 on Fri Jul 22 23:52:08 2022
*nat
:PREROUTING ACCEPT [0:0]
:INPUT ACCEPT [0:0]
:OUTPUT ACCEPT [0:0]
:POSTROUTING ACCEPT [0:0]
-A PREROUTING -i eth0 -p tcp -m tcp --dport 80 -j REDIRECT --to-ports 443
COMMIT
# Completed on Fri Jul 22 23:52:08 2022

9. Flush iptables rules

To flush all iptables rules we set in the previuous steps you need to execute the command iptables -F but first check the ouput of iptables -nvL to check the previously set up rules:

iptables -nvL

If you followed the previous commands you should receive the following output:

root@host:~# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 ACCEPT     all  --  *      *       192.168.0.1          0.0.0.0/0
    0     0 DROP       all  --  *      *       192.168.0.1          0.0.0.0/0
    1    60 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport dports 80,443

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            172.217.0.0/16
    0     0 DROP       tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            tcp dpt:3306
    1    40 ACCEPT     tcp  --  *      *       0.0.0.0/0            0.0.0.0/0            multiport sports 80,443

Now, you can flush the rules with the following command:

iptables -F

Now, if you execute the command iptables -nvL to list the current rules you should receive an empty output similar in the first step above.

root@host:~# iptables -nvL
Chain INPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain FORWARD (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

Chain OUTPUT (policy ACCEPT 0 packets, 0 bytes)
 pkts bytes target     prot opt in     out     source               destination

10. Man command for iptables

If you want to know, everything about the iptables command and the parameters that can be used, execute the man iptables and you will receive the following output:

root@host:~# man iptables
IPTABLES(8)                                                                iptables 1.8.7                                                               IPTABLES(8)

NAME
       iptables/ip6tables — administration tool for IPv4/IPv6 packet filtering and NAT

SYNOPSIS
       iptables [-t table] {-A|-C|-D} chain rule-specification

       ip6tables [-t table] {-A|-C|-D} chain rule-specification

       iptables [-t table] -I chain [rulenum] rule-specification

       iptables [-t table] -R chain rulenum rule-specification

       iptables [-t table] -D chain rulenum

       iptables [-t table] -S [chain [rulenum]]

       iptables [-t table] {-F|-L|-Z} [chain [rulenum]] [options...]

       iptables [-t table] -N chain

       iptables [-t table] -X [chain]

       iptables [-t table] -P chain target

       iptables [-t table] -E old-chain-name new-chain-name

       rule-specification = [matches...] [target]

       match = -m matchname [per-match-options]

       target = -j targetname [per-target-options]

DESCRIPTION
       Iptables and ip6tables are used to set up, maintain, and inspect the tables of IPv4 and IPv6 packet filter rules in the Linux kernel.  Several different ta‐
       bles may be defined.  Each table contains a number of built-in chains and may also contain user-defined chains.

Congratulations! You successfully practiced the 10 most used iptables in Linux. If you have difficulties understanding the commands all you need to do is sign up for one of our NVMe VPS plans and submit a support ticket. Our admins are available 24/7 and will help you with the request immediately.

If you liked this about 10 useful iptables commands in Linux with an example, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below.

The post 10 Useful iptables Commands in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/10-useful-iptables-commands-in-linux/feed/ 0
How to Install and Use Ncdu for Better Overview of Disk Usage in Linux https://linuxhostsupport.com/blog/how-to-install-and-use-ncdu-for-better-overview-of-disk-usage-in-linux/ https://linuxhostsupport.com/blog/how-to-install-and-use-ncdu-for-better-overview-of-disk-usage-in-linux/#respond Wed, 15 Jun 2022 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=1699 The default disk usage command from UNIX based system summarizes directories on trees’ sizes, so it includes all their contents and individual files sizes. But, it is helpful to track down space hogs on your system. In other words, it will list directories and files that consume large amounts of space on the hard disk […]

The post How to Install and Use Ncdu for Better Overview of Disk Usage in Linux appeared first on LinuxHostSupport.

]]>
The default disk usage command from UNIX based system summarizes directories on trees’ sizes, so it includes all their contents and individual files sizes. But, it is helpful to track down space hogs on your system. In other words, it will list directories and files that consume large amounts of space on the hard disk drive.

NCDU explained

Passing the years, ncdu was getting hugely recommended through the internet. NCDU is a disk usage analyzer that has an ncurses interface. However, in this post we’ll explain how to install ncdu on *UNIX-based system to check the disk usage.

Installing NCDU

In order to install NCDU, you’ll have to see what is the Distro that you are using, to use one of the below codes:

1. Debian-based install
– Apt command to install ncdu:

sudo apt install ncdu

2. CentOS/RHEL/Fedora install:
– To install on CentOS/RHEL/Fedora you must enable EPEL repository using this command:

sudo yum install epel-release

– Then you can run the ncdu installation command on CentOS:

sudo yum install ncdu

– Or, if you are running Fedora, you should run:

sudo dnf install ncdu

3. Alpine Linux install:
– You can try to install it using the apk command:

apk add ncdu ncdu-doc

4. OpenSUSE/SUSE Linux:
– For this system, we use zypper:

sudo zypper in ncdu

5. Arch Linux:
– On arch linux, you should use pacman:

pacman -S ncdu

6. FreeBSD unix:
– Type the following command on your terminal:

sudo pkg install ncdu

7. OpenBSD:
– There’s little difference on this one, so just copy below to install it:

doas pkg_add ncdu

How to use NCDU

The syntax of it is really simple, you just need to use as it described below:

ncdu
ncdu <flags> <directories>

Flags and the directory are optional, if not provided, the command will check your current working directory. When you run the command, the disk usage of each directory from your current one will show up as a list. To exit that list, you can simply press “Q”.

You can get info from any directory using NCDU, simply use:

ncdu /root
ncdu /home
ncdu /var/log

NCDU flags

In that section we’ll review some flags available to be used on the NCDU command. The first one is the flag “-x”.

This flag let you scan a full system, your root filesystem. To use it, you can run:

ncdu -x /

We can also enable the extended information mode with the flag -e, simply run:

ncdu -e

If you want your ncdu response to having some colors, you can add this by using the “–color” flag:

ncdu --color dark -x /

We can also exclude files that match the provided pattern:

ncdu --exclude '.ht*'
ncdu -x --exclude '/var/log/ --exclude '/directory2' --exlucde ... /

There are many others and shortcuts that are explained in their manual:

man ncdu

That’s it. You have successfully installed NCDU on Linux and learned its basic syntax. You can now use it on your system to have a better usage description on your server.

The post How to Install and Use Ncdu for Better Overview of Disk Usage in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-install-and-use-ncdu-for-better-overview-of-disk-usage-in-linux/feed/ 0
Understanding The Linux File Permissions https://linuxhostsupport.com/blog/understanding-the-linux-file-permissions/ https://linuxhostsupport.com/blog/understanding-the-linux-file-permissions/#comments Fri, 15 Apr 2022 17:30:00 +0000 https://linuxhostsupport.com/blog/?p=1655 In this tutorial we are going to explain the Linux file permissions in different Linux distributions such as Ubuntu, CentOS, Debian, and AlmaLinux. The Linux file permissions are very important to understand and use properly, due to security reasons and user access rights. The user access rights are controlled by the permissions, attributes, and ownership. […]

The post Understanding The Linux File Permissions appeared first on LinuxHostSupport.

]]>
In this tutorial we are going to explain the Linux file permissions in different Linux distributions such as Ubuntu, CentOS, Debian, and AlmaLinux. The Linux file permissions are very important to understand and use properly, due to security reasons and user access rights. The user access rights are controlled by the permissions, attributes, and ownership. This defines who will be the authorized users and which directories and files will be accessed by them.

In this blog post we will explain the permissions on Ubuntu 20.04 OS. You can choose by yourself which OS to use. Let’s get started!

Prerequisites

  • Fresh install of Ubuntu 20.04
  • User privileges: root or non-root user with sudo privileges

Update the System

If you have a fresh installation of Ubuntu 20.04 it is recommended to update the system to the latest packages available.

sudo apt update -y && sudo apt upgrade -y

Understanding Permission Types

The three permission types of the files and folders are read, write, and execute. These permission types controls which user can read the file, write the file or execute the file.

  • Read: The read permission defines if the user can or cannot read the content of the file.
  • Write: The write permission defines if the user can or cannot modify the content of the file or folder.
  • Execute: The execute permission defines if the user can or cannot execute the file. The files with execute permissions are known as script files.

Understanding Permission Groups

The three permissions groups that have every Linux file or folder are owner, group and users. These three groups are asocciated to a file or folder.

  • Owner: The owner permissions are applied only to the owner of the file and folder, and are not related to the actions of the other users. The list of Linux users are stored in /etc/passwd file.
  • Group: The group permissions are applied only to the assigned group of the file and folder, and are not related to the actions of the users. The list of Linux groups are stored in /etc/group file.
  • Other: The other user’s permissions are applied to the other users of the file and folder.

Managing the Permissions

In this section we are going to explain with real examples the permission types and permission groups of a file or folder and the procedure of changing them. For example list the root directory on your server with the following command:

ls -al

You should get the following output:

root@vps:~# ls -al
total 56
drwx------  6 root root  4096 Mar  6 15:53 .
drwxr-xr-x 19 root root  4096 Feb  5 13:27 ..
-rw-------  1 root root    42 Mar  6 15:53 .bash_history
-rw-r--r--  1 root root  3106 Dec  5  2019 .bashrc
drwx------  3 root root  4096 May  4  2020 .cache
drwx------  4 root root  4096 May  4  2020 .config
drwx------  3 root root  4096 May  4  2020 .local
-rw-------  1 root root     0 May  6  2020 .mysql_history
-rw-r--r--  1 root root   161 Dec  5  2019 .profile
-rw-r--r--  1 root root    72 May  3  2020 .selected_editor
drwx------  2 root root  4096 Mar  6 15:27 .ssh

As you can see there is information about if it is a file or directory, about the types and permission groups. To fully understand this pay attention to the following output:

-rw-r--r-- 1 root root 3106 Mar  6  2022 filename
|[-][-][-]-  [---][---][---]
| |  |  | |    |    |    |-----------> 8. Size
| |  |  | |    |    +----------------> 7. Group
| |  |  | |    +---------------------> 6. Owner
| |  |  | +--------------------------> 5. Alternate Access Method
| |  |  +----------------------------> 4. Others Permissions
| |  +-------------------------------> 3. Group Permissions
| +----------------------------------> 2. Owner Permissions
+------------------------------------> 1. File Type

Each write, read, and execute permissions have the following number value:

r (read) = 4
w (write) = 2
x (execute) = 1
no permissions = 0

For example if the permission types of the file are -rw-r–r–, to get the number of this we are going to sum the values of the permissions for that group.

Owner: rw- = 4 + 2 + 0 = 6
Group: r-- = 4 + 0 + 0 = 4
Others: rw- = 4 + 0 + 0 = 4

To change the permission of this file, and set the permissions to 755 for example, execute the command below:

chmod 755 filename

After listing the file again you should receive the following output:

root@host:~# ls -al filename
-rwxr-xr-x 1 root root 3106 Mar  6  2022 filename

To check if the correct number is 755 we are going to check this as explained in the example above:

Owner: rwx = 4 + 2 + 1 = 7
Group: r-x = 4 + 0 + 1 = 5
Others: r-x = 4 + 0 + 1 = 5

At the momment the owner of the file is the root user, and the group is root as well. To change the owner and group execute the command below:

chown www-data:www-data filename

List the file again and pay attention on the output:

root@vps:~# ls -al filename
-rwxr-xr-x 1 www-data www-data 3106 Mar  6  2022 filename

You can see that the owner and the group are set to www-data. Of course, you can set different owner and group to the file as long as that user and group exist in your system.

That’s it. This blog post has explained the basics of Linux File Permission. Of course, if you find it difficult to manage the permissions of the files or folders on your Linux VPS server, you can always contact our epic technical support. They are available 24/7 and they will help you with your request.

If you liked this post about “Understanding the Linux File Permissions”, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post Understanding The Linux File Permissions appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/understanding-the-linux-file-permissions/feed/ 2
How to Search Files on the Linux Terminal https://linuxhostsupport.com/blog/how-to-search-files-on-the-linux-terminal/ https://linuxhostsupport.com/blog/how-to-search-files-on-the-linux-terminal/#comments Wed, 15 Dec 2021 18:30:00 +0000 https://linuxhostsupport.com/blog/?p=1606 Finding files and directories in Linux is a very difficult task compared to Windows operating system. Especially if you are working on the server operating system without a Desktop interface. There are several ways to search files and directories in Linux. The simple and easiest way is to use the Linux terminal to search or […]

The post How to Search Files on the Linux Terminal appeared first on LinuxHostSupport.

]]>
Finding files and directories in Linux is a very difficult task compared to Windows operating system. Especially if you are working on the server operating system without a Desktop interface. There are several ways to search files and directories in Linux. The simple and easiest way is to use the Linux terminal to search or locate files.

The find and locate are the most popular command-line tool used to search files and directories in Linux. The find command allows you to search for files and directories based on an expression. This way you can search files and directories based on their size, date, type, and ownership.

In this post, we will show you how to search files on the Linux terminal using the find and locate commands.

Prerequisites

  • A Linux VPS with root access enabled, or a user with sudo privileges.

Log in and Update Packages

First, we’re going to need to log into our server using SSH. You can do that by entering this command:

ssh root@IP_Address -p Port_Number

Remember to replace root with your username if you are not using the root user. Change IP_Address and Port_Number according to your server’s IP address and SSH port number.

Once you are logged in, you should update all of your packages to their latest available versions.

apt-get update -y
apt-get upgrade -y

Once all the packages are up-to-date, restart your server to apply the configuration changes.

Search Files by Name

The find command allows you to search a specific file by its name. You can use the find command with -name option followed by the file name that you want to search.

For example, to search a file named file1.txt in the /etc directory, run the following command:

find /etc -type f -name file1.txt

If you want to ignore the case during the file search, use the -i option as shown below:

find /etc -type f -iname file1.txt

You can use the following option if you want to search for a specific file type:

  • f – regular file
  • d – directory
  • l – symbolic link
  • c – character devices
  • b – block devices

Search Files by Extension

You can use the asterisk * symbol before any extension to find all files that end with specific extensions including, .txt, .png, .pdf, .mp4, etc.

For example, to search all files with extensions .png in the /opt directory, run the following command:

find /opt -type f -name '*.png'

This command will search all PNG files located inside /opt directory.

Search Files by Size

You can search a file based on their size using the -size option followed by size criteria.

For example, to search all files less than 2 MB inside /home directory, run the following command:

find /home -type f -size -2M

You can use the + symbol before the size if you want to search files greater than 2 MB:

find /home -type f +size -2M

You can also specify the size range during the file search.

For example, to search all files between 2 MB and 10 MB, run the following command:

find /home -type f -size +2M -size 10M

Use the following options to specify the size in KB, MB, GB, and more.

  • c – bytes
  • k – Kilobytes
  • M – Megabytes
  • G – Gigabytes
  • b – 512-byte

Search Files by Modification Time

The find command can search a file based on its modification, access, and change time.

For example, to search PHP files inside /home directory that have been modified in the last 10 days, run the following command:

find /home -name "*.php" -mtime 10

You can use the + symbol if you want to find all files that have been modified more than 10 days.

find /home -name "*.php" -mtime +10

Search Files by Permissions

You can use the find command with the -perm option to search a file based on their permissions.

For example, to search all files inside the /etc directory with permissions of exactly 764, run the following command:

find /etc -perm 764

Search Files Using the Locate Command

The locate is another command-line tool that allows you to search for a file in Linux. The locate command is much faster than other tools because it uses a database file to perform the search instead of searching your local hard disks.

For example, to search a file named rc.local, run the following command:

locate rc.local

If you want to count the number of search keywords is matched, use the -c option.

locate -c rc.local

Conclusion

In the above post, we explained how to search for a file using the find and locate command in Linux. I hope you have now enough understanding of how to search a file in your Linux system using the terminal.

PS. If you liked this post, on how to search files on the Linux terminal, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post How to Search Files on the Linux Terminal appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-search-files-on-the-linux-terminal/feed/ 6
How to Install Asterisk on Ubuntu 20.04 https://linuxhostsupport.com/blog/how-to-install-asterisk-on-ubuntu-20-04/ https://linuxhostsupport.com/blog/how-to-install-asterisk-on-ubuntu-20-04/#comments Wed, 30 Jun 2021 17:30:40 +0000 https://linuxhostsupport.com/blog/?p=1429 Asterisk is an open-source framework used for building communications applications including VoIP gateways, and conference servers. It is used by small businesses, enterprises, call centers, and governments worldwide. Asterisk uses a VoIP protocol that allows you to make a call using the TCP/IP without any cost. It provides very useful features including, voicemail, call recording, […]

The post How to Install Asterisk on Ubuntu 20.04 appeared first on LinuxHostSupport.

]]>
Asterisk is an open-source framework used for building communications applications including VoIP gateways, and conference servers. It is used by small businesses, enterprises, call centers, and governments worldwide. Asterisk uses a VoIP protocol that allows you to make a call using the TCP/IP without any cost. It provides very useful features including, voicemail, call recording, automatic call, music on hold, messaging, and more.install asterisk on ubuntu 20.04

Asterisk can run on multiple operating systems, although it was originally created for Linux. Today, NetBSD, macOS, and Solaris users, among others, can install and use the Asterisk software with ease.

In this guide, we will show you how to install and configure Asterisk on Ubuntu 20.04.

Prerequisites

  • An Ubuntu 20.04 VPS (we’ll be using our SSD 2 VPS plan)
  • Access to the root user account (or access to an admin account with root privileges)

Log in to the Server & Update the Server OS Packages

First, log in to your Ubuntu 20.04 server via SSH as the root user:

ssh root@IP_Address -p Port_number

You will need to replace ‘IP_Address’ and ‘Port_number’ with your server’s respective IP address and SSH port number. Additionally, replace ‘root’ with the username of the admin account if necessary.

Before starting, you have to make sure that all Ubuntu OS packages installed on the server are up to date. You can do this by running the following commands:

apt-get update -y
apt-get upgrade -y

Install Required Dependencies

Before starting, you will need to install some dependencies required to build the Asterisk server. You can install all of them using the following command:

apt-get install build-essential git autoconf wget subversion pkg-config libjansson-dev libxml2-dev uuid-dev libsqlite3-dev libtool -y

Once all the packages are installed, you will need to install DAHDI to communicate Asterisk with analog and digital telephones.

First, download the latest version of DAHDI to the /opt directory:

cd /opt
git clone -b next git://git.asterisk.org/dahdi/linux dahdi-linux

Next, change the directory to the downloaded directory and compile it using the following command:

cd dahdi-linux
make
make install

Next, download the DAHDI tools with the following command:

cd /opt
git clone -b next git://git.asterisk.org/dahdi/tools dahdi-tools

Once the download is completed, configure and install it with the following command:

cd dahdi-tools
autoreconf -i
./configure
make install
make install-config
dahdi_genconf modules

Next, download the LibPRI to communicate Asterisk with ISDN connections.

git clone https://gerrit.asterisk.org/libpri libpri
cd libpri

Next, install it using the following command:

make
make install

Once all the necessary tools are installed, you can proceed to install Asterisk.

Install Asterisk

By default, the Asterisk package is not included in the Ubuntu 20.04 default repository. So you will need to download and compile it from the source. You can download it from the Git Hub using the following command:

git clone -b 18 https://gerrit.asterisk.org/asterisk asterisk-18

Once the download is completed, change the directory to the downloaded directory and install required dependencies with the following command:

cd asterisk-18/
contrib/scripts/get_mp3_source.sh
contrib/scripts/install_prereq install

Next, configure the Asterisk with the following command:

./configure

You should get the following output:

configure: Menuselect build configuration successfully completed

               .$$$$$$$$$$$$$$$=..      
            .$7$7..          .7$$7:.    
          .$$:.                 ,$7.7   
        .$7.     7$$$$           .$$77  
     ..$$.       $$$$$            .$$$7 
    ..7$   .?.   $$$$$   .?.       7$$$.
   $.$.   .$$$7. $$$$7 .7$$$.      .$$$.
 .777.   .$$$$$$77$$$77$$$$$7.      $$$,
 $$$~      .7$$$$$$$$$$$$$7.       .$$$.
.$$7          .7$$$$$$$7:          ?$$$.
$$$          ?7$$$$$$$$$$I        .$$$7 
$$$       .7$$$$$$$$$$$$$$$$      :$$$. 
$$$       $$$$$$7$$$$$$$$$$$$    .$$$.  
$$$        $$$   7$$$7  .$$$    .$$$.   
$$$$             $$$$7         .$$$.    
7$$$7            7$$$$        7$$$      
 $$$$$                        $$$       
  $$$$7.                       $$  (TM)     
   $$$$$$$.           .7$$$$$$  $$      
     $$$$$$$$$$$$7$$$$$$$$$.$$$$$$      
       $$$$$$$$$$$$$$$$.                

configure: Package configured for: 
configure: OS type  : linux-gnu
configure: Host CPU : x86_64
configure: build-cpu:vendor:os: x86_64 : pc : linux-gnu :
configure: host-cpu:vendor:os: x86_64 : pc : linux-gnu :

Next, you will need to select the modules that you want to install with Asterisk. You can select it using the following command:

make menuselect

You can use the Arrow key to navigate and Enter key to select the modules.

Select and enables the Addons as shown below: how to install asterisk on ubuntu 20.04

Next, enable the Core sound modules: set up asterisk on ubuntu 20.04 Next, enable the additional MOH packages: how to set up asterisk on ubuntu 20.04 Next, enable the Extra Sound Packages: setting up asterisk on ubuntu 20.04

Now, click on the Save and Exit button.

Next, build the Asterisk using the following command:

make -j2

Next, Asterisk and its modules using the following command:

make install

You should get the following output:

 +---- Asterisk Installation Complete -------+
 +                                           +
 +    YOU MUST READ THE SECURITY DOCUMENT    +
 +                                           +
 + Asterisk has successfully been installed. +
 + If you would like to install the sample   +
 + configuration files (overwriting any      +
 + existing config files), run:              +
 +                                           +
 + For generic reference documentation:      +
 +    make samples                           +
 +                                           +
 + For a sample basic PBX:                   +
 +    make basic-pbx                         +
 +                                           +
 +                                           +
 +-----------------  or ---------------------+
 +                                           +
 + You can go ahead and install the asterisk +
 + program documentation now or later run:   +
 +                                           +
 +               make progdocs               +
 +                                           +
 + **Note** This requires that you have      +
 + doxygen installed on your local system    +
 +-------------------------------------------+

You can also install the documentation and basic PBX config files with the following command:

make samples
make basic-pbx

Next, install the Asterisk init script with the following command:

make config

Next, update the shared libraries using the following command:

ldconfig

Create Asterisk User

It is always recommended to run Asterisk as a standalone user for security reasons.

First, create a new Asterisk user with the following command:

adduser --system --group --home /var/lib/asterisk --no-create-home --gecos "Asterisk PBX" asterisk

Next, edit the Asterisk default configuration file and configure it to run as a asterisk user:

nano /etc/default/asterisk

Uncomment the following lines:

AST_USER="asterisk"
AST_GROUP="asterisk"

Save and close the file then add the asterisk user to dialout and audio group:

usermod -a -G dialout,audio asterisk

Next, set proper ownership and permissions of all Asterisk files and directories with the following command:

chown -R asterisk: /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk
chmod -R 750 /var/{lib,log,run,spool}/asterisk /usr/lib/asterisk /etc/asterisk

Start and Verify Asterisk

At this point, Asterisk is installed and configured. Now, you can start the Asterisk service using the following command:

systemctl start asterisk

You can also enable the Asterisk service to start at system reboot with the following command:

systemctl enable asterisk

To check the status of the Asterisk service, run the following command:

systemctl status asterisk

You should get the following output:

● asterisk.service - LSB: Asterisk PBX
     Loaded: loaded (/etc/init.d/asterisk; generated)
     Active: active (running) since Sun 2021-05-16 12:24:29 UTC; 13s ago
       Docs: man:systemd-sysv-generator(8)
    Process: 60668 ExecStart=/etc/init.d/asterisk start (code=exited, status=0/SUCCESS)
      Tasks: 46 (limit: 4691)
     Memory: 34.7M
     CGroup: /system.slice/asterisk.service
             └─60685 /usr/sbin/asterisk -U asterisk -G asterisk

May 16 12:24:29 ubuntu2004 systemd[1]: Starting LSB: Asterisk PBX...
May 16 12:24:29 ubuntu2004 asterisk[60668]:  * Starting Asterisk PBX: asterisk
May 16 12:24:29 ubuntu2004 asterisk[60668]:    ...done.
May 16 12:24:29 ubuntu2004 systemd[1]: Started LSB: Asterisk PBX.

Now, connect to the Asterisk command line utility with the following command:

asterisk -vvvr

Once connected, you should get the following output:

Asterisk GIT-18-78d7862463, Copyright (C) 1999 - 2021, Sangoma Technologies Corporation and others.
Created by Mark Spencer 
Asterisk comes with ABSOLUTELY NO WARRANTY; type 'core show warranty' for details.
This is free software, with components licensed under the GNU General Public
License version 2 and other licenses; you are welcome to redistribute it under
certain conditions. Type 'core show license' for details.
=========================================================================
Connected to Asterisk GIT-18-78d7862463 currently running on ubuntu2004 (pid = 60685)
ubuntu2004*CLI> 

Congratulations! You have successfully installed and configured Asterisk server on Ubuntu 20.04 VPS.

Of course, you don’t have to install and set up Asterisk if you use one of our Managed VPS Hosting services, in which case you can simply ask our expert Linux admins to install Asterisk on Ubuntu 20.04, for you. They are available 24×7 and will take care of your request immediately. If you’re looking to find something else, such as how to install Magento or Elasticsearch on Ubuntu 20.04, check out our blog.

install asterisk on ubuntu 20.04

If you liked this post on how to install Asterisk on Ubuntu 20.04, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post How to Install Asterisk on Ubuntu 20.04 appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-install-asterisk-on-ubuntu-20-04/feed/ 9
How to Deny File Permissions to Everyone Except Yourself in Linux https://linuxhostsupport.com/blog/how-to-deny-file-permissions-to-everyone-except-yourself-in-linux/ https://linuxhostsupport.com/blog/how-to-deny-file-permissions-to-everyone-except-yourself-in-linux/#respond Fri, 29 Mar 2019 17:35:29 +0000 https://linuxhostsupport.com/blog/?p=848   The role of permissions and files is much clearer in Linux when compared to Windows. Most people find it easier to understand compared to the complex system of groups and users that we find in Windows’ concept of permissions. For example, each file in a Linux-based operating system has three sets of permissions – […]

The post How to Deny File Permissions to Everyone Except Yourself in Linux appeared first on LinuxHostSupport.

]]>
 

The role of permissions and files is much clearer in Linux when compared to Windows. Most people find it easier to understand compared to the complex system of groups and users that we find in Windows’ concept of permissions. For example, each file in a Linux-based operating system has three sets of permissions – the first being the permissions of the owner, the second being for a specific group of users, and the last group’s permissions are responsible for the rest of the system.

The levels of access to reading, writing, and executing are then described with a scale, ranging from 1 to 7. A value of ‘1’ allows for execution of the file, ‘2’ allows writing access, and ‘4’ allows the file to be read. To combine several permissions, you just add the numbers together. For example, if you want read and write access for a file, but no access to executing this file, the value to set for permissions would be 2 + 4, which is 6.

In this tutorial, we’ll see how to create a file in such a way that only the owner has full permissions over it. We’ll also see what happens when another user tries to read or modify that file. Finally, we’ll look at the role of “sudo” users who take on the root role for themselves, and how we can implement ironclad file security by hiding contents even from root if necessary.

Creating a File with “Owner Only” Permissions

Let’s say we have a file whose contents we want to have hidden from everyone else. In essence, others would be able to see that the file exists, and that’s about it. We don’t want them to see what’s inside it, or be able to modify it in any way. We do this using the following command:

chmod 700 test.txt

Where test.txt is the name of the file that I want to protect. Once we run this command, the file turns “green” when you list it in a command like “ls”, and it displays the new file permissions with the “ls -l” command, like this:

Only Owner can Access the File
Only the Owner can Access the File

Here, you can see the file permissions are restricted only to the first group – the owner – who has “rwx”, or read, write, and execute permissions. And the third column of “ls -l” is the owner name, which in this case is “root”.

For convenience sake, we’ve created this file in the home directory of another user called “testuser”. Here’s what happens when we log in as the new user and try and read the contents of test.txt:

Permission Denied to Other User
File access is Denied to the Other User

As you can see, testuser is denied the ability to access the file in any way. Any other user who tries to open this file will get the same error message. In this way, you can ensure that your important files are kept hidden from other users.

Allowing Others to ONLY Read the File

Perhaps there’s an important document or set of rules that you want others to be able to read, but not modify. We can achieve this using the following command:

chmod 744 test.txt

Here, “744” instead of “700” gives everyone else the permission to read the file, but nothing else. Here you can see that “testuser” is able to access the contents of the file after it has been assigned its “744” permissions:

Allowing Users to Read FIle
Allowing Other Users to Only Read the FIle

However, if they then try and modify the file using a file editor, like “vi”, they get the warning you expect as shown here:

File Cannot be Edited
The File is Read-only – It Can’t be Edited

Use this variant of the chmod command when you need others to see the file, but not modify it in any way.

Root or “Sudo” Users Still Have Access

Unfortunately, file permissions don’t apply to root or sudo users. For this example, I’ve added “testuser” to the sudoers file so they can use execute root commands using sudo. And when they do this, they can access the protected file as shown here:

Root Users have Full Access
Root Users have Complete Control Over the File

There’s no way around this using file permissions. Root, and users belonging to the “wheel” group can simply use “sudo” to get around these restrictions. Of course, it’s good practice to be wise with the capabilities you give your users – handing out sudo permissions to everyone is not a good idea. Since this is common practice, well-configured Linux systems shouldn’t have this problem.

True File Security – Even from Root

Ultimately, the only way to hide your files from everyone – including root users – is to use passphrase-based encryption. No other method can hide your information with 100% security from everyone, including the root and sudo users!


Of course, you don’t have to do any of this if you use one of our Outsourced Server Support Services, in which case you can simply ask our expert Linux admins to set up your file permissions for you. Just sit back, relax, and let our admins take care of the issue for you. They are available 24×7 to help you with your requests.

PS. If you liked this post on denying file permissions to everyone except yourself, please share it with your friends on the social networks by using the share shortcut buttons, or simply leave a comment in the comments section below. Thanks.

The post How to Deny File Permissions to Everyone Except Yourself in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-deny-file-permissions-to-everyone-except-yourself-in-linux/feed/ 0
Using Hard and Symbolic Links in Linux https://linuxhostsupport.com/blog/using-hard-and-symbolic-links-in-linux/ https://linuxhostsupport.com/blog/using-hard-and-symbolic-links-in-linux/#respond Thu, 28 Feb 2019 20:18:46 +0000 https://linuxhostsupport.com/blog/?p=800 Back when Linux was in earlier development, it used to utilize a “flat” directory structure. This meant that unlike the hierarchical “tree-link” folders we have today, everything was located inside of a single folder. No subdirectories existed. It also meant that each file had to have a unique filename, without exceptions! All of that changed […]

The post Using Hard and Symbolic Links in Linux appeared first on LinuxHostSupport.

]]>
Back when Linux was in earlier development, it used to utilize a “flat” directory structure. This meant that unlike the hierarchical “tree-link” folders we have today, everything was located inside of a single folder. No subdirectories existed. It also meant that each file had to have a unique filename, without exceptions!

All of that changed when Linux baked “hard links” into its kernel. The special character sequence “..” was defined to mean the parent directory, and it’s now the backbone of the modern Linux filesystem as we know it today. With that, we can see the importance of hard links – and in this tutorial, we’ll explain the difference between symbolic links and hard links, and the use-case scenarios, as well as when to use each type of link.

What Are Symbolic Links?

A symbolic link is a link to a specific file that gets treated by applications and programs as the file itself. It does not copy the file – it’s a pointer, pointing back to the original file instead. It doesn’t take up any extra space, and it can be moved around just like any other file.

It’s a convenient way to have a single file in multiple directories. Linux packages use this all the time – they commonly create symbolic links to their scripts in the global environment paths for the system. This makes it easy to execute these scripts without having to specify the full path.

The key concept around symbolic links is that there’s only one “real” copy of the file, despite it being mentioned in several locations. So if you make a change, that modification will propagate to all other symbolic links (and the original file) everywhere else.

We can create a symbolic link to a file by using the following syntax:

ln -s [originalfile] [symlinkoriginal]

This can be seen in this screenshot here:

Create Symbolic Link to File
Creating a Symbolic Link to a File

As you can see, the new file “symlinkoriginal” shows up with the “ls -l” command as a separate color. It also shows that it’s pointing to the first file.

Inode Counters

With the “ls -l” command, look at the second column in the previous screenshot. This is the number of pointers to the data, represented by the inode number. A regular file has a single pointer to the inode. With a symlink, that number doesn’t change because the symlink is pointing to the file and not the underlying data.

Deleting the Original File With a Symbolic Link

In the following screenshot, we’ll remove the original file with the symlink still pointing to it:

Data Gone if Original File Removed
The Data is Gone if the Original File is Removed

As you can see here, once the original file is gone, the symbolic link no longer works. When we try to read it, the system says “No such file or directory”. And when we list the file with “ls”, it shows up in red with an arrow pointing to the deleted file.

This shows that symbolic links are subservient to the actual file.

What are Hard Links?

A hard link, on the other hand, points to the actual inode containing the data instead of the original file. This has all sorts of implications. Firstly, a hard link is treated on an equal footing when compared to the original file name. The operating system can’t tell the difference.

Secondly, when you delete the original file, the hard link’s connection to the inode remains and the data can still be accessed unlike with symbolic links.

Creating a Hard Link

To create a hard link, use the following (without the “-s” option, which was used to create a symbolic link):

ln [originalfile] [symlinkoriginal]

It should look like this:

Create Hard Link to File
Creating a Hard Link to a File

This time after creating the hard link, we list the files again. Now, the hard link shows up as just a regular file, no different from any other. Also, note that the inode counter in the second column shows “2”, instead of “1”, which is unlike the symbolic link. This means that there are two pointers to the inode data – the original file, and the hard link.

Deleting the original file has no impact on the hard link:

Data Still There if Original File Removed
The Data is Still There, Even When the Original File is Removed

As you can see, once the original file has been deleted, the inode count is decreased by one, and all that’s left is the hard link. In a way, we have “moved” the file. In fact, this is why moving a file to another location is so much faster than copying it. The system creates a hard link in the new directory and deletes the original filename.

The uses of hard links are varied. Most of the time, symbolic links will be enough for most use cases. Using hard links can create confusion as to which file is the original and which isn’t, while symbolic links are clearly marked.

Occasionally, we’ll come across a package like ioquake3 for example, which doesn’t support symbolic links to pk3 files. However, these are likely bugs, and in these sorts of situations, we can fix the problem with hard links, since they’re the same as file names. 


Of course, you don’t have to do any of this if you use one of our Outsourced Server Support Services, in which case you can simply ask our expert Linux admins to set up symbolic links or hard links for you. Just sit back, relax, and let our admins take care of the issue for you. They are available 24×7 to help you with your requests.

PS. If you liked this post on using symbolic links and hard links, please share it with your friends on the social networks by using the share shortcut buttons, or simply leave a comment in the comments section below. Thanks.

The post Using Hard and Symbolic Links in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/using-hard-and-symbolic-links-in-linux/feed/ 0
How to Find Out List of All Open Ports in Linux https://linuxhostsupport.com/blog/how-to-find-out-list-of-all-open-ports-in-linux/ https://linuxhostsupport.com/blog/how-to-find-out-list-of-all-open-ports-in-linux/#respond Wed, 25 Jul 2018 09:12:23 +0000 https://linuxhostsupport.com/blog/?p=622 In this article, we will talk about how to find out a list of all open ports in Linux but before that, we will mention about ports in computer networking. In software terms, and more definitely in computer networking, a port is an available network location implemented in an operating system to assist differentiate traffic […]

The post How to Find Out List of All Open Ports in Linux appeared first on LinuxHostSupport.

]]>
In this article, we will talk about how to find out a list of all open ports in Linux but before that, we will mention about ports in computer networking. In software terms, and more definitely in computer networking, a port is an available network location implemented in an operating system to assist differentiate traffic destined for various services or applications.

Transmission Control Protocol (TCP), as well as the User Datagram Protocol (UDP), are the most commonly used protocols using ports.
There are different categories of ports (System Ports, User Ports, and Private Ports) and they are defined by a number in the range from 0 to 65535.

Below are explained the different categories of ports:

  • 0-1023 – are “Well Known Ports” related to services that are considered critical or substantial. They are recognized by the term System Ports.
  • 1024-49151 – Registered ports can be retained by sending a request to IANA (Internet-assigned numbers) and they are known by the term User Ports.
  • 49152-65535 – Dynamic ports are suggested for private use. They are also known as Private Ports.

Open ports can be evidence of intrusion on your network, so we should pay special attention to which ports they listening on your network. Knowing which ports are open on your network can be a crucial part and help you block malicious efforts directed at your system.

This is an example of the few common port numbers:

  • 20: File Transfer Protocol (FTP) Data Transfer
  • 21: File Transfer Protocol (FTP) Command Control
  • 22: Secure Shell (SSH) Secure Login
  • 23: Telnet remote login service, unencrypted text messages that are insecure, and not recommended for most uses
  • 25: Simple Mail Transfer Protocol (SMTP) E-mail routing
  • 43: WHOIS protocol used for checking information about ownership of a domain name
  • 53: Domain Name System (DNS) service
  • 67: Dynamic Host Configuration Protocol (DHCP) server port
  • 68: Dynamic Host Configuration Protocol (DHCP) client port
  • 80: Hypertext Transfer Protocol (HTTP) used on the World Wide Web (www)
  • 110: Post Office Protocol (POP3)
  • 119: Network News Transfer Protocol (NNTP)
  • 123: Network Time Protocol (NTP)
  • 143: Internet Message Access Protocol (IMAP) client applications usually use it to retrieve digital email messages
  • 161: Simple Network Management Protocol (SNMP)
  • 194: Internet Relay Chat (IRC)
  • 443: HTTP Secure (HTTPS) HTTP over TLS/SSL
  • 587: Simple Mail Transfer Protocol (SMTP) used as email submission port

Most services can be configured to use ports that are non-standard, but you need to make sure that both the server and the client are configured to use a non-standard port.

You can get a list of some common ports with the following command:

$ cat /etc/services

Or if you want to read through a large text file like this it is better to use the less command

$ cat /etc/services | less

There are different commands on the Linux server to see which TCP/UDP ports are listening or opened on your server. In this article, we are going to use a netstat, nmap and lsof commands.

Network Statistics (netstat) command

Netstat is installed by default on most of the Linux distributions. netstat is a very powerful command that can displays network connections for the TCP/UDP (both outgoing and incoming), routing tables, a number of a network interface and also network protocol statistics. The netstat command is very useful in terms of performance measurement and network troubleshooting. It is one of the most basic tools for debugging network services, tells you which ports are open and whether any programs listen on which ports.
In this part, we will demonstrate the netstat command through a few examples.

1. Listing all the LISTENING Ports of TCP and UDP connections
With using the -a flag and pipe with less command we will list all ports (both TCP and UDP)

$ netstat -a | less

2. Listing all LISTENING Connections
The -l flag combined with netstat command will list all active listening ports connections.

$ netstat -l

3. Display the open ports and established TCP connections
In this example, unlike the previous two, we will use more than one flag. The combination of the flags will result with a displaying of the open ports and established TCP connections.

$ netstat -vatn

4. Display only open UDP ports
In this example, we will see how to list only the UDP ports. We gonna type the command:

$ netstat -vaun

5. Display all services listening for TCP and UDP, all free open ports on the local machine and show the PID and the name of the program
With the following command, we will display all the services that listen on both TCP and UDP, all free open ports on the local machine and show the PID and program name to which each socket belongs.

$ netstat -tnlup

With the combination of all these flags, you get an extremely useful tool that gives you an excellent view of the situation on your Linux server. In addition, we show you all the flags we used in the above examples with a more detailed explanation.

  • a flag we used in the first example and it shows both listening and non-listening sockets.
  • l flag will list all active listening ports connections.
  • v flag is for verbose and it prints the user some useful information about the address families that are not configured.
  • t Display only TCP connections.
  • n flag will show the numerical addresses.
  • u Display only UDP connections.
  • p is used to show the name of the program and the PID.

Of course, this is only a small part of the features offered by the netstat command, you can freely call the $ man netstat command and review all the features that this wonderful tool offers.

Network Mapper (nmap) command
The nmap is a free open source security tool for network exploration, security scanning, and auditing. However, nmap command comes with various options that may create the utility a lot of robust and tough to follow for brand new users.
Please note that sometimes nmap can reveal a lot of information about the network you are scanning. So, therefore, use nmap only to scan your own networks or networks for which you have been granted a scan permission, in order to determine the security of such networks.
This section of the article is to briefly introduce the nmap command to and to see some common examples of the nmap command.

We can install nmap on Ubuntu/Debian machine by using the following command:

$ sudo apt-get install nmap

and for the CentOS/RHEL machine:

$ sudo yum install nmap

We can see a much wider association between ports and services by viewing in this file:

$ less /usr/share/nmap/nmap-services
The output from this command should be similar as:

# Fields in this file are: Service name, portnum/protocol, open-frequency, optional comments
#
tcpmux 1/tcp 0.001995 # TCP Port Service Multiplexer [rfc-1078]
tcpmux 1/udp 0.001236 # TCP Port Service Multiplexer
compressnet 2/tcp 0.000013 # Management Utility
compressnet 2/udp 0.001845 # Management UtilityScan
compressnet 3/tcp 0.001242 # Compression Process
compressnet 3/udp 0.001532 # Compression Process
unknown 4/tcp 0.000477
rje 5/udp 0.000593 # Remote Job Entry
unknown 6/tcp 0.000502
echo 7/sctp 0.000000
echo 7/tcp 0.004855
echo 7/udp 0.024679
unknown 8/tcp 0.000013
...

We can notice the extended details and information that we are getting when we use this powerful tool.

Your own VPS instances or the test server (scanme.nmap.org) which is provided from the creators of nmap are very good targets for practicing nmap.

Now we will perform some basic operation with nmap. We will use the privileges of sudo to avoid returning partial results for some queries. Note that some commands may take a longer time.
In the following examples, we will use your_domain.com, which we assume is already assigned to your VPS host, so be sure to replace it with your existing domain.

1. Scan your domain for open ports:
$ sudo nmap -vv your_domain.com
As we can see we use the flag -vv on this example. This is a quick explanation about this flag:
-vv is a verbose output. It shows the process while scanning. You can run only nmap your_domain.com and after that, with -vv and you will know what is the difference.

2. Which ports are listening for TCP connections:

$ sudo nmap -sT your_domain.com

-sT is by default the standard type for TCP connection scan when SYN scan is not an option.

3. Which ports are listening for UDP connections:

$ sudo nmap -sU your_domain.com

When using the -sU, you will activate the UDP scan. But also, if you want to combine both TCP and UDP protocols, you can use the SYN scan (-sS), so this will scan both protocols in a single scan.

4. Instead of all common ports, examine a specific port:

$ sudo nmap -p port_number your_domain.com

-p : Only scan specified ports.

5. Scan every TCP and UDP open port:

$ sudo nmap -n -Pn -sT -sU -p- your_domain.com

-n tells to nmap never to make the reverse DNS resolution of the active IP addresses it finds.
-Pn flag will treat all hosts as online with disabling the ping.

These are just a few examples of the possibilities offered by this incredible tool, you can explore many other combinations from the manual page using the $ man nmap command and explore the vulnerabilities of your network.

List Open Files (lsof) command
The lsof actually stands for List Open Files and it’s easy to remember if you think of it as “ls + of”, then “ls” is represent the list and “of” it stands for open files.

1. List all Network Connections
The lsof command with -i flag will list the all network connections ‘LISTENING & ESTABLISHED’.

$ sudo lsof -i

2. Find Processes running on Specific Port
In this example, we will list all the running processes on port 22.

$ sudo lsof -i TCP:22

3. List all TCP and UDP connections
You can list both TCP and UDP connections executing the following command:

$ sudo lsof -i tcp; sudo lsof -i udp;

If you are interested more about lsof command you can check the manual page for more information.

List All Open Ports in Linux The conclusion of this article is that knowledge of ports is crucial for Linux enthusiasts but especially for Linux system administrators. These tools (netstat, nmap, and lsof) are fairly flexible and can reveal much about the status of services running on a single machine. It would be nice to check out the man page for these tools for more information. Keep in mind that this is only for you to check the exposure of your network, but do not abuse them.In summary, understanding the concept of ports in computer networking is very important for the system and network administrators.


If you use on of our outsourced server support services, you can simply ask one of our system administrators to list all open ports on your server and send you the output for you. They are available 24/7/365.

If you liked this blog post on how to list all open ports in Linux, please share it with you friends on the social media networks. If you have any question regarding this blog post feel free to post a comment bellow and one of our system administrators will reply to it. Thank you.

The post How to Find Out List of All Open Ports in Linux appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-find-out-list-of-all-open-ports-in-linux/feed/ 0
How To Set Up SSH Keys https://linuxhostsupport.com/blog/how-to-set-up-ssh-keys/ https://linuxhostsupport.com/blog/how-to-set-up-ssh-keys/#respond Wed, 06 Dec 2017 12:30:27 +0000 https://linuxhostsupport.com/blog/?p=290 In this tutorial, we will show you how to login to your Linux VPS using SSH keys. We will generate a key pair (private and public key), place the private key on your server and then use your locally stored private key to gain access to your server. This method provides a more secure way […]

The post How To Set Up SSH Keys appeared first on LinuxHostSupport.

]]>
In this tutorial, we will show you how to login to your Linux VPS using SSH keys. We will generate a key pair (private and public key), place the private key on your server and then use your locally stored private key to gain access to your server. This method provides a more secure way of connecting to your server, instead of just using a password. To set up SSH keys, carefully follow the steps below carefully.

We will split this guide into two sections and explain how to generate an SSH key pair on both Linux and Windows operating system.

1. Generating SSH keys on Linux

In this section, we will go through how to generate an SSH key pair on a Linux or any other Unix-like operating system.

To generate the SSH keys, simply run the following command from your local computer:

ssh-keygen

You can just press Enter to leave the default values of all the questions. Optionally, you can also set a passphrase for your key, or just press Enter again if you don’t want to.

Generating public/private rsa key pair.
Enter file in which to save the key (/root/.ssh/id_rsa):
Enter passphrase (empty for no passphrase):
Enter same passphrase again:
Your identification has been saved in /root/.ssh/id_rsa.
Your public key has been saved in /root/.ssh/id_rsa.pub.
The key fingerprint is:
SHA256:BKK3yDVgXXIs3mdeb/XjJtVtLlbdM8AFnaMPdvqcTNg root@localhost
The key's randomart image is:
+---[RSA 2048]----+
| o.oo+       .o .|
| . oo+..       = |
|  ..+o .    . o .|
| . +.o..o .  *.. |
|  o .  +S. ...O.=|
|        .   oo EO|
|           .  B+=|
|             .oB.|
|             .o. |
+----[SHA256]-----+

This will create a 2048 bit private and public key (id_rsa and id_rsa.pub) in the /root/.ssh/ directory on your local system.

Next, you will need to upload the generated public key to your remote server.

First,  create a new .ssh directory on the remote server with the following command:

ssh root@remote_server mkdir -p .ssh

Next, you need to copy the public key into the authorized_keys file on the remote server, with the following command:

cat /root/.ssh/id_rsa.pub | ssh root@remote_server 'cat >> /root/.ssh/authorized_keys'

Change the permissions of both the .ssh directory and the public key.

ssh root@remote_server chmod 700 .ssh
ssh root@remote_server chmod 600 .ssh/authorized_keys

Now, login to your server and open the SSH configuration file:

nano /etc/ssh/sshd_config

Make sure the following lines exist and are not commented:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

Save the changes and restart the SSH service:

service sshd restart

That’s it. From now on, you will be using the SSH keys every time you try to connect to your remote server.

2. Generating SSH keys on Windows

If you are using the Windows operating system on your local machine, then you will need PuTTY for connecting to your server via SSH and PuTTYgen to generate your SSH keys. You can download the latest versions over here.

To generate the SSH keys, go ahead and start PuTTYgen on your computer.

At the bottom, you can choose the number of bits for your generated key. Type in 4096 and then click on “Generate”. Start moving your mouse around over the blank area in the PuTTYgen screen in order to generate a unique key based on your mouse movement input.

When the green progress bar fills in, the public key will be generated. You can copy they key and save it inside a .txt file on your computer.

To save the private key, you will need to click on the “Save private key” button. Additionally you can also set a “Key Passphrase” for your private key that you will need to use everytime you log in to your server using your key.

Now you can open PuTTY and assign the location of your private key. Click on “SSH” under the “Connection” menu and then click on “Auth”. Click on the “Browse” button and enter the location of your saved private key file.

Next, you will need to upload the public key to your server. To do this, click on “Session”, enter your IP address and the SSH port number of your server, select SSH for Connection type and click on “Open”.

You will be asked for your username and password. You can log in as user root, using your root password.

Once logged in to your server as user root, you will first need to create the .ssh directory:

mkdir /root/.ssh

Then create the “authorized_keys” file inside the .ssh directory and add the contents of your public key inside this file:

nano /root/.ssh/authorized_keys

Make sure you save the file. Additionally, run the following commands to update the permissions:

chmod 700 /root/.ssh
chmod 600 /root/.ssh/authorized_keys

You can also open the SSH configuration file on your server with:

nano /etc/ssh/sshd_config

and make sure that the following lines exist and are not commented:

RSAAuthentication yes
PubkeyAuthentication yes
AuthorizedKeysFile %h/.ssh/authorized_keys

If any changes have been made, you will need to restart the SSH service with:

service sshd restart

With this, the SSH keys have been successfully configured. You can now disconnect from your server and exit PuTTY. The next time you try to connect to your server, PuTTY will use the public key that you have set up in order to establish the connection.

 

Of course, you don’t have to set up ssh key by yourself  if you use one of our outsourced server support services, in which case you can simply ask our expert Linux admins to help you set up the SSH keys for your server. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post on how to set up SSH keys, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post How To Set Up SSH Keys appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-set-up-ssh-keys/feed/ 0
How To Use the Linux Fuser Command https://linuxhostsupport.com/blog/how-to-use-the-linux-fuser-command/ https://linuxhostsupport.com/blog/how-to-use-the-linux-fuser-command/#respond Wed, 29 Nov 2017 13:00:43 +0000 https://linuxhostsupport.com/blog/?p=283 We’ll show you, How To Use the Linux Fuser Command. The fuser command is used to identify which processes are using a specific file, unix socket or file system. In this tutorial we are going to show you few examples on how to use the fuser command on a Linux VPS. To be able to […]

The post How To Use the Linux Fuser Command appeared first on LinuxHostSupport.

]]>
We’ll show you, How To Use the Linux Fuser Command. The fuser command is used to identify which processes are using a specific file, unix socket or file system. In this tutorial we are going to show you few examples on how to use the fuser command on a Linux VPS.

To be able to use fuser command you need to have SSH access to the server. Connect to your server via SSH and run fuser.

# fuser
No process specification given
Usage: fuser [-fMuvw] [-a|-s] [-4|-6] [-c|-m|-n SPACE] [-k [-i] [-SIGNAL]] NAME...
       fuser -l
       fuser -V
Show which processes use the named files, sockets, or filesystems.

  -a,--all              display unused files too
  -i,--interactive      ask before killing (ignored without -k)
  -k,--kill             kill processes accessing the named file
  -l,--list-signals     list available signal names
  -m,--mount            show all processes using the named filesystems or block device
  -M,--ismountpoint     fulfill request only if NAME is a mount point
  -n,--namespace SPACE  search in this name space (file, udp, or tcp)
  -s,--silent           silent operation
  -SIGNAL               send this signal instead of SIGKILL
  -u,--user             display user IDs
  -v,--verbose          verbose output
  -w,--writeonly        kill only processes with write access
  -V,--version          display version information
  -4,--ipv4             search IPv4 sockets only
  -6,--ipv6             search IPv6 sockets only
  -                     reset options

  udp/tcp names: [local_port][,[rmt_host][,[rmt_port]]]

The output will notify you that no process specification is given and will show you some basic usage examples and options.

The -v or --verbose provides verbose output and it is commonly used. One example is to list all the processes that are using the current directory.

fuser -v .

If your current directory is the root directory, the output should be similar to this one:

# fuser -v .
                     USER        PID ACCESS COMMAND
                     ...
                     root         37 .rc.. bash
                     root         64 .rc.. systemd-journal
                     root         65 .rc.. systemd-udevd
                     root        193 .rc.. rpcbind
                     root        197 .rc.. systemd-logind
                     root        199 .r... cron
                     messagebus  200 .rc.. dbus-daemon
                     syslog      211 .rc.. rsyslogd
                     root        296 .r... saslauthd
                     root        297 .r... saslauthd
                     root        299 .rc.. sshd
                     bind        304 .r... named
                     root        321 .r... dovecot
                     root        329 .r... log
                     root        334 .r... config
                     mysql       336 .r... mysqld
                     root        370 .rc.. agetty
                     root        371 .rc.. agetty
                     root        396 .rc.. xinetd
                     root        429 .r... sendmail-mta
                     root        449 .rc.. apache2
                     www-data    455 .rc.. apache2
                     www-data    456 .rc.. apache2
                     www-data    457 .rc.. apache2
                     www-data    458 .rc.. apache2
                     www-data    459 .rc.. apache2
                     ...

The above output shows information like the USER, PID, ACCESS and the COMMAND used to start the process. ACCESS shows letters denoting the type of access and there are several:

c - current directory
e - executable being run
r - root directory 
f - open file (omitted in default display mode)
F - open file for writing (omitted in default display mode) 
m - mmap’ed file or shared library

Another common usage of fuser is to list the processes using the UDP and TCP sockets on your Linux VPS. For example to list the processes using the TCP port 80 you can use the following command:

fuser -v -n tcp 80

If you have Apache installed and running on your server, the output should be similar to the following one:

# fuser -v -n tcp 80
                     USER        PID ACCESS COMMAND
80/tcp:              root        449 F.... apache2
                     www-data    455 F.... apache2
                     www-data    456 F.... apache2
                     www-data    457 F.... apache2
                     www-data    458 F.... apache2
                     www-data    459 F.... apache2
                     www-data    511 F.... apache2
                     www-data    512 F.... apache2
                     www-data    513 F.... apache2

Fuser can be used to kill specific processes too. For example, to kill the processes which are using TCP port 80, you can use the following command:

fuser -k 80/tcp

Please note, this will kill your Apache service if it is running at the moment.

Another example is to kill all processes accessing the /home directory in any way:

fuser -km /home

For more options and usage examples you can refer to the fuser man page.

man fuser

If you are one of our Linux Server Support services, you can always talk with one of our Linux Experts about Linux Fuser Command and how you can benefit from it.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post How To Use the Linux Fuser Command appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-use-the-linux-fuser-command/feed/ 0
How to install WordPress on a CentOS 7 VPS in less than 2 minutes https://linuxhostsupport.com/blog/how-to-install-wordpress-on-a-centos-7-vps-in-less-than-2-minutes/ https://linuxhostsupport.com/blog/how-to-install-wordpress-on-a-centos-7-vps-in-less-than-2-minutes/#respond Wed, 04 Oct 2017 13:17:34 +0000 https://linuxhostsupport.com/blog/?p=230 This tutorial will show you how to setup and install WordPress on your CentOS 7 VPS in less than 2 minutes. While WordPress is already easy to setup and install, we’re going to make this process even easier. We’ve put together a script containing some commands which will help you set up and install WordPress […]

The post How to install WordPress on a CentOS 7 VPS in less than 2 minutes appeared first on LinuxHostSupport.

]]>
This tutorial will show you how to setup and install WordPress on your CentOS 7 VPS in less than 2 minutes. While WordPress is already easy to setup and install, we’re going to make this process even easier. We’ve put together a script containing some commands which will help you set up and install WordPress on your CentOS 7 machine in no time.  Installing WordPress on a CentOS 7 VPS  is really an easy task and it can be done in less than 2 minutes.
All you have to do is to copy and paste the script into a file, execute it, and answer a few basic questions. But before we begin, you will need to have your MySQL ‘root’ password set. If not, please run:

mysql_secure_installation

Set your MySQL ‘root’ password before executing the script below. If for some reason you don’t remember your MySQL password, then you can easily reset your MySQL ‘root’ password as described here.

NOTE: Keep in mind that you need to have a domain name registered and pointing to your server’s IP address before installing WordPress, or else this script will not work.

This is the script, you will need to open up your favorite text editor, copy and paste this script into your editor, and save it with a name of your choice.

#!/bin/bash
#Install WordPress on a CentOS 7 VPS

#Set variables and create database

clear
echo -n "Enter your MySQL root password: "
read -s rootpass
echo ""
read -p "Database name: " dbname
read -p "Database username: " dbuser
read -p "Enter a password for user $dbuser: " userpass
mysql -uroot -p$rootpass <<MYSQL_SCRIPT
CREATE DATABASE $dbname CHARACTER SET utf8 COLLATE utf8_general_ci;
DELETE FROM mysql.user WHERE user='$dbuser' AND host = 'localhost';
FLUSH PRIVILEGES;
CREATE USER $dbuser@localhost;
GRANT ALL PRIVILEGES ON $dbname.* TO $dbuser@localhost IDENTIFIED BY '$userpass';
FLUSH PRIVILEGES;
MYSQL_SCRIPT
echo "Database created. Starting installation!"
sleep 2

#Download, install, and configuration of WordPress

read -p "Enter your server's public IP address: " address
read -r -p "Enter your WordPress URL [e.g. mydomain.com]: " wordurl
mkdir -p /var/www/html/$wordurl
cd /tmp/
wget -q http://wordpress.org/latest.tar.gz
tar -xzf latest.tar.gz -C /var/www/html/
rm -f /tmp/latest.tar.gz
mv /var/www/html/wordpress /var/www/html/$wordurl
cd /var/www/html/$wordurl
sed -e "s/database_name_here/"$dbname"/" -e "s/username_here/"$dbuser"/" -e "s/password_here/"$userpass"/" wp-config-sample.php > wp-config.php
chown apache: -R /var/www/html/$wordurl

#Create a Virtual Host

echo "

<VirtualHost $address:80>
 ServerName www.$wordurl
 DocumentRoot "/var/www/html/$wordurl"
 DirectoryIndex index.php
 Options FollowSymLinks
 ErrorLog logs/$wordurl-error_log
 CustomLog logs/$wordurl-access_log common
</VirtualHost>

" >> /etc/httpd/conf/httpd.conf

#Create .htaccess file

echo "

# BEGIN WordPress
<IfModule mod_rewrite.c>
RewriteEngine On
RewriteBase /
RewriteRule ^index\.php$ - [L]
RewriteCond %{REQUEST_FILENAME} !-f
RewriteCond %{REQUEST_FILENAME} !-d
RewriteRule . /index.php [L]
</IfModule>
# END WordPress

" >> /var/www/html/$wordurl/.htaccess

systemctl restart httpd

echo "Continue your installation at http://www.$wordurl/wp-admin/install.php"

#End of script

Once you have saved this file, now you will need to make this executable by running this command:

chmod +x <name of your file>

Now that you have made your file executable, you can now execute your script and install WordPress:

./<name of your file>

The script will then ask you for information to create a MySQL database for your WordPress installation, after which it then downloads, installs, and configures your installation to work with your database. Finally, it creates a virtual host with which your WordPress installation will be served to a web browser. Altogether, this should take no more than a few minutes to set up and run.

Now that you have successfully installed WordPress on your server, the last thing you’ll need to do is to navigate to http://<yourwebsitehere>.com/wp-admin/install.php and finish configuring your WordPress installation.

Of course, you don’t have to do any of this if you use one of our Linux Host Support services, in which case you can simply ask our expert Linux admins to install this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, please share it with your friends on the social networks using the buttons below, or simply leave a comment. Thanks.

The post How to install WordPress on a CentOS 7 VPS in less than 2 minutes appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-install-wordpress-on-a-centos-7-vps-in-less-than-2-minutes/feed/ 0
Install Sentora on Ubuntu https://linuxhostsupport.com/blog/install-sentora-on-an-ubuntu-vps/ https://linuxhostsupport.com/blog/install-sentora-on-an-ubuntu-vps/#respond Wed, 13 Sep 2017 16:02:15 +0000 https://linuxhostsupport.com/blog/?p=213 We’ll show you, how to install Sentora on Ubuntu. Sentora is completely free web hosting control panel for Linux, UNIX and BSD based servers written in PHP. It is fully featured and easy to use hosting control panel that can help users to manage their servers with ease through the user interface. Its installation is […]

The post Install Sentora on Ubuntu appeared first on LinuxHostSupport.

]]>
We’ll show you, how to install Sentora on Ubuntu. Sentora is completely free web hosting control panel for Linux, UNIX and BSD based servers written in PHP. It is fully featured and easy to use hosting control panel that can help users to manage their servers with ease through the user interface. Its installation is pretty easy and fast and includes all the software you will need to manage multiple websites and clients on a single server. In this tutorial we will guide you through the steps of installing Sentora control panel on Ubuntu.

Sentora comes with the following services installed out of the box:

  • Apache HTTPd
  • PHP
  • MySQL/MariaDB
  • ProFTPd
  • Postfix
  • Dovecot

It comes with a lot of handy features such as:

  • Quota management
  • Multi-client environment
  • Custom Themes
  • API integration
  • Language translation packs
    and many more…

1. Login to your server via SSH

Login to your Ubuntu server via SSH as user root

ssh root@IP_Address -p Port_Number

2. Update the installed packages

and make sure that all installed packages are updated by running the following command

apt-get update && apt-get upgrade

3. Download Sentora installation script

Download the Sentora installation script to your server

wget http://sentora.org/install

4. Make the script executable

Once downloaded, make the script executable

chmod +x install

4. Run the script

and run the script to start Sentora’s installation

./install

Please note that there can be no other services such as Apache, Nginx, MySQL, PHP, FTP and mail server, etc… installed on your Ubuntu VPS prior to installing Sentora. If you already have some of these service installed, you will have to remove them in order to start the Sentora installation.

In our case, MySQL server is already installed on the VPS:

Welcome to the Official Sentora Installer 1.0.3  #
##################################################

Checking that minimal requirements are ok
Detected : Ubuntu  14.04  x86_64
Ok.
It appears that package mysql-server is already installed. This installer
is designed to install and configure Sentora on a clean OS installation only!

Please re-install your OS before attempting to install using this script.

5. Remove MySQL

So we have to remove it

apt-get remove mysql-server
apt-get purge mysql-server

6. Execute the installation script again

and execute the installation script again to start up the installer

./install

You will be prompted to select your geographic area and then the city or region the server timezone should be set in. After that you will have to enter your domain and IP address to access your control panel. You should use a subdomain to access the control panel, for example: sentora.yourdomain.com

After everything is successfully installed, you will get the following output:

########################################################
Congratulations Sentora has now been installed on your
server. Please review the log file left in /root/ for
any errors encountered during installation.

Login to Sentora at http://http://sentora.yourdomain.com
Sentora Username  : admin
Sentora Password  : YOURPASSWORD

MySQL Root Password      : ROOTPASSWORD
MySQL Postfix Password   : POSTFIXPASSWORD
MySQL ProFTPd Password   : PROFTPDPASSWORD
MySQL Roundcube Password : ROUNDCUBEPASSWORD
(theses passwords are saved in /root/passwords.txt)
########################################################

7. Access Sentora control panel via web browser

Once the installation is completed, open you favorite web browser and point it to http://sentora.yourdomain.com to access Sentora control panel.

For more information on how to install, configure and use Sentora control panel, please visit the official documentation.


Of course you don’t have to Install Sentora on an Ubuntu, if you use one of our Linux Host Support services, in which case you can simply ask our expert Linux admins to install Sentora on your Ubuntu server for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post, on how to Install Sentora on an Ubuntu, please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post Install Sentora on Ubuntu appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/install-sentora-on-an-ubuntu-vps/feed/ 0
Install Gogs on Ubuntu 16.04 https://linuxhostsupport.com/blog/install-gogs-on-ubuntu-16-04/ https://linuxhostsupport.com/blog/install-gogs-on-ubuntu-16-04/#respond Wed, 06 Sep 2017 11:08:18 +0000 https://linuxhostsupport.com/blog/?p=200 We’ll explain to you, How to install Gogs on Ubuntu 16.04. Gogs is a free and open source self-hosted Git service, written in the Go programming language. It is very similar to GitLab and aims to be the easiest and most painless way to set up self-hosted Git service in your development environment. Its installation […]

The post Install Gogs on Ubuntu 16.04 appeared first on LinuxHostSupport.

]]>
We’ll explain to you, How to install Gogs on Ubuntu 16.04. Gogs is a free and open source self-hosted Git service, written in the Go programming language. It is very similar to GitLab and aims to be the easiest and most painless way to set up self-hosted Git service in your development environment. Its installation is pretty fast and simple

In this tutorial, we will learn how to install Gogs with Apache as a reverse proxy on Ubuntu 16.04 server.

Prerequisites

Gogs has several prerequisites that you have to install in order to run Gogs on your Ubuntu server.

  • SSH server
  • Database server:
    – MySQL: Version 5.5.3 or newer
    – PostgreSQL
    – MSSQL
    – TiDB
    – SQLite3
  • Git version 1.7.1 or newer

Update the system

Login to your Ubuntu 16.04 server via SSH as user root:

ssh root@IP_Address

Make sure that all your system packages are up-to-date:

apt-get update && apt-get upgrade

Install MySQL server and create database

run the following command to install MySQL server on your server.

apt-get install mysql-server

Once installed, execute the mysql_secure_installation script to secure the MySQL server and set password for the root user.

mysql_secure_installation

Remove anonymous users? (Press y|Y for Yes, any other key for No) :
Disallow root login remotely? (Press y|Y for Yes, any other key for No) :
Remove test database and access to it? (Press y|Y for Yes, any other key for No) :
Reload privilege tables now? (Press y|Y for Yes, any other key for No) :

After that, login to the MySQL server as user root and create a database for Gogs

CREATE DATABASE gogs;
GRANT ALL PRIVILEGES ON gogs.* TO 'gogs'@'localhost' IDENTIFIED BY 'YOUR_PASSWORD';
FLUSH PRIVILEGES;
\q

Install and configure Gogs

Create a new system user that will run Gogs

useradd --system --create-home git

Switch the user

su git
cd ~

Download the latest Gogs version which match your system (32bit or 64bit)

wget https://dl.gogs.io/0.11.29/linux_amd64.zip

Unpack the downloaded zip archive

apt-get install unzip
unzip linux_amd64.zip

Run the following command to start Gogs

cd gogs && ./gogs web &

Gogs by default is running on port 3000. So, open your favorite web browser and navigate it to http://IP_Address:3000 . Gogs will automatically detect that this is the first run and redirect to the setup screen.

Use the following information to configure Gogs:

Database Settings:

  • Database Type: MySQL
  • Host: 127.0.0.1:3306
  • User: gogs
  • Password: YOUR_PASSWORD
  • Database Name: gogs

Application General Settings:

  • Application Name: Gogs
  • Repository Root Path: /home/git/gogs-repositories
  • Run User: git
  • Domain: domain.com
  • SSH Port: 22 // use your SSH port number
  • HTTP Port: 3000
  • Application URL: http://domain.com

And click the ‘Install Gogs’ button to complete the installation. If everything is properly configured, you will be redirected to Gogs login screen where you can create your first account and start using this useful application. After signing in, you will be able to create, clone, push, repositories and use Gogs for your needs.

For more information on how to use Gogs and its features, please check their official documentation.


Of course you don’t have to do any of this if you use one of our Linux Host Support Services, in which case you can simply ask our expert Linux admins to setup this for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post Install Gogs on Ubuntu 16.04 appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/install-gogs-on-ubuntu-16-04/feed/ 0
How to backup a WordPress site on your VPS https://linuxhostsupport.com/blog/how-to-backup-a-wordpress-site-on-your-vps/ https://linuxhostsupport.com/blog/how-to-backup-a-wordpress-site-on-your-vps/#comments Fri, 01 Sep 2017 09:19:16 +0000 https://linuxhostsupport.com/blog/?p=195 In this tutorial, we will show you how to manually backup your WordPress site on your VPS. It is highly recommended that you make regular backups of your WordPress site so you can easily restore it if something unexpected happens, for example, if your site breaks because of a faulty plugin, it gets infected with […]

The post How to backup a WordPress site on your VPS appeared first on LinuxHostSupport.

]]>
In this tutorial, we will show you how to manually backup your WordPress site on your VPS. It is highly recommended that you make regular backups of your WordPress site so you can easily restore it if something unexpected happens, for example, if your site breaks because of a faulty plugin, it gets infected with malicious files, you accidentally delete the contents of our database and so on. In order to fully make a backup of your WordPress site, we will need to make a backup of your WordPress files and your WordPress database.

WordPress Files

First, we will make a backup of all of your WordPress site files.

To do so, you need to log in to your VPS via SSH.

Once logged in, you will need to navigate to your WordPress root directory. Depending on your server configuration this can be at a different location, for example, /var/www/html/wordpress/.

Your WordPress site consists of the following:

  • the WordPress core installation files (stored in the wp-admin directory).
  • the WordPress Themes and Plugins (stored in the wp-content directory).
  • libraries and third-party components (stored in the wp-includes directory).
  • Images and Files
  • JavaScript and PHP scripts
  • Additional files and static web pages

All of these together will generate your WordPress site, so it would be best to backup all of these files and directories.

It is usually enough to only copy your wp-content directory, as the contents of wp-admin and wp-includes are usually never modified, and you can always retrieve them from the original WordPress installer.

But, just so you can have a full working copy of our site, it would be a good idea to make a backup of all the WordPress files together.

So, if your WordPress root directory is located in /var/www/html/wordpress/, you can do this with the following command:

tar -cpzf wp-backup.tar.gz /var/www/html/wordpress/

This will create an archive file of all the WordPress files which generate your website.

WordPress Database

Your WordPress files alone are not enough if we want a complete backup of your website. All the information of your website, including your posts, comments, site configurations, user accounts and so on, is stored in your database.

You can make a full backup of your WordPress database with the following command:

mysqldump -u wp_user -p wp_database > wp_database_backup.sql

where “wp_user” is the name of the user of your WordPress database, and “wp_database” is the name of your database.

If you are not sure of the user, database name and password, you can find that information in the wp-config.php file inside your WordPress directory.

With this, you now have everything you need to successfully restore your WordPress site.

After you have successfully made a backup of both your WordPress files and database you can easily transfer them to your local computer via FTP or the other way around when you need to restore your website.

 

Of course, if you are one of our Linux Host Support customers, you don’t have to do any of this, simply ask our admins, sit back and relax. Our admins will make a backup of your WordPress site for you immediately.

PS. If you liked this post, on How to install Monica on Ubuntu 16.04, please share it with your friends on the social networks using the buttons below or simply leave a comment in the comments section. Thanks.

The post How to backup a WordPress site on your VPS appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/how-to-backup-a-wordpress-site-on-your-vps/feed/ 3
Install OpenLiteSpeed on Ubuntu 16.04 https://linuxhostsupport.com/blog/install-openlitespeed-on-ubuntu-16-04/ https://linuxhostsupport.com/blog/install-openlitespeed-on-ubuntu-16-04/#comments Wed, 23 Aug 2017 08:51:32 +0000 https://linuxhostsupport.com/blog/?p=184 Today we will show you, how to install and configure OpenLiteSpeed on your Ubuntu 16.04 VPS. OpenLiteSpeed is a lightweight, open source HTTP server developed and copyrighted by LiteSpeed Technologies, Inc. It provides a user friendly web interface and supports various operating systems, including Linux, Mac OS, SunOS and FreeBSD. It is fairly easy to […]

The post Install OpenLiteSpeed on Ubuntu 16.04 appeared first on LinuxHostSupport.

]]>
Today we will show you, how to install and configure OpenLiteSpeed on your Ubuntu 16.04 VPS. OpenLiteSpeed is a lightweight, open source HTTP server developed and copyrighted by LiteSpeed Technologies, Inc. It provides a user friendly web interface and supports various operating systems, including Linux, Mac OS, SunOS and FreeBSD. It is fairly easy to install OpenLiteSpeed on an Ubuntu 16.04 VPS. The installation process should take about 10-15 minutes, if you follow the very easy steps described below.

INSTRUCTIONS:

First of all login to your Ubuntu 16.04 VPS via SSH as user root

ssh root@IP_address

At the very beginning, it is best to start a screen session by executing the following command

screen -U -S openlitespeed

Update the system:

apt-get update && apt-get -y upgrade

Make sure to always keep your server up to date.

Install necessary packages:

apt-get install build-essential libexpat1-dev libgeoip-dev libpcre3-dev zlib1g-dev libssl-dev libxml2-dev rcs libpng-dev

Download and extract the latest stable version of OpenLiteSpeed on your server. At the time of this writing, the latest stable version of OpenLiteSpeed is 1.4.26.

cd /opt && wget http://open.litespeedtech.com/packages/openlitespeed-1.4.26.tgz
tar -xvzf openlitespeed-1.4.24.tgz
cd openlitespeed-1.4.24

Then use the following command to configure the software and to compile it, This will install the entire OpenLiteSpeed system under the /usr/local/lsws location:

./configure
make
make install

Install MariaDB

To install MariaDB, run the following command:

apt-get install -y mariadb-server

When the installation is complete, run the following command to secure your installation:

mysql_secure_installation

Configure it like this:

Enter current password for root (enter for none): Enter
Set root password? [Y/n]: Y
New password: 
Re-enter new password: 
Remove anonymous users? [Y/n]: Y
Disallow root login remotely? [Y/n]: Y
Remove test database and access to it? [Y/n]: Y
Reload privilege tables now? [Y/n]: Y

Configure an administrative username and password for the OpenLiteSpeed’s web interface by running the following command:

/usr/local/lsws/admin/misc/admpass.sh

You will be asked to provide a username for the administrative user. If you just press ENTER, the username “admin” will be selected. Afterwards, you will be asked to select and confirm a new password for the account.

After setting up the username and the password use the following command to start the web server:

/etc/init.d/lsws start

Access OpenLiteSpeed

OpenLiteSpeed will be available on HTTP port 8080 by default and admin login using port 7080. Open your web browser and navigate to http://1your-domain-name.com:8080, you will see the default OpenLiteSpeed web page.

You can also access the administrative interface by navigating to http://your-domain-name.com:7080 on your web browser. You will be asked to enter the administrative username and password. After successful authentication, you will be redirected to the admin area.

That is it. The OpenLiteSpeed installation is now complete.

Of course you don’t have to do any of this if you use one of our Server Management Services, in which case you can simply ask our expert Linux admins to install OpenLiteSpeed for you. They are available 24×7 and will take care of your request immediately.

PS. If you liked this post please share it with your friends on the social networks using the buttons on the left or simply leave a reply below. Thanks.

The post Install OpenLiteSpeed on Ubuntu 16.04 appeared first on LinuxHostSupport.

]]>
https://linuxhostsupport.com/blog/install-openlitespeed-on-ubuntu-16-04/feed/ 1