LinuxTips Archives - The Linux GURUS https://thelinuxgurus.com/category/linuxtips/ Learn Linux & DevOPS from THE LINUX GURUS Tue, 16 Mar 2021 15:13:07 +0000 en-US hourly 1 https://i0.wp.com/thelinuxgurus.com/wp-content/uploads/2020/01/cropped-thelinuxgurus_transparent_name.png?fit=32%2C32&ssl=1 LinuxTips Archives - The Linux GURUS https://thelinuxgurus.com/category/linuxtips/ 32 32 148921671 How to use FIND command in Linux https://thelinuxgurus.com/how-to-use-find-command-in-linux/ https://thelinuxgurus.com/how-to-use-find-command-in-linux/#respond Tue, 16 Mar 2021 15:13:07 +0000 https://thelinuxgurus.com/?p=1333 In this tutorial on how to use the ‘Find command’ in Linux, we will discuss in brief what is find command & will also discuss...

The post How to use FIND command in Linux appeared first on The Linux GURUS.

]]>
In this tutorial on how to use the ‘Find command’ in Linux, we will discuss in brief what is find command & will also discuss some examples for the same. 

Find command is a pretty useful command for easily locating files & folders in Linux. What makes it a powerful command is that we can use a number of search criteria/options to refine the search.  

It can be found & used on almost all Linux distros by default.

Recommended Read: How to use NMAP command to test Server/Network Security

Also Read: How to create a free SSL certificate using Let’s Encrypt in Linux


Syntax for using Find command

To use the find command, the basic syntax is:-

# find  location search-criteria  search-term

Now that we have some understanding of what the find command is & how to use the find command in Linux. Let’s discuss some examples as well,


Examples of the FIND command in Linux

 

Finding files on the system

To find all the files in the ‘/’ folder i.e. root directory, use,

# find / -type f

To search for the file in a particular directory, use,

# find /etc/ -type f

 

Finding directories on the system

To find all the folders/directories in the ‘/’ folder i.e. root directory, use,

# find / -type d

To look for all the directories in a particular directory, use,

# find /etc/ -type d

 

Finding files based on the name

If you know the name of the file or folder you are looking for, then you can also use that to make search easy & fast with the following command,

# find /etc -iname “*.txt”

This shows all the files in the /etc folder with extension .txt. One thing to consider here is that it will ignore a case-sensitive file. It will show all the files ending with .txt but will ignore files ending with .TXT or .Txt. 

To include all such files as well, we can use ‘-name’ instead of ‘-iname’, for example,

# find /etc -name “*.txt”

 

Invertive name search

Find command can also be used to exclude some files & only show the remaining files, use,

# find /etc -not -name “*.txt”

above command will list all the files & directories that do not have extension “.txt” at the end.

 

Finding files/directories with size

With the find command, we can also find files based on the file sizes. Use the following example as reference,

# find /etc -type f -size 2M

This will show all the files in the /etc folder with the size of 2 Megabytes.

 

Combining search criteria

We can also combine more than one search option to produce a more refined search,

# find /etc -name ‘test*’ ! -name ‘*.php’

here, it will find all the files with the name ‘test’ at the start in ‘/etc’ folder which does not have extension .php. “!” here is the equivalent of AND operator.

Also, we can combine two search criteria & produce results when any of the two search criteria are satisfied.

# find /etc -name ‘test*’ -o -name ‘*.txt’

Here “-o” is equivalent to OR operator.

Search based on file permissions

To find files based on their permissions, use, 

# find /etc -type f -perm 0400

This will show all the files in the /etc folder with the permission of 0644.

# find /etc -type f -perm /u=r

The result for the above command will show all files for a user with only read permissions.

 

Finding files with user & group ownership

Similar to how we can locate files with particular permissions, we can also use find command to locate files with a particular owner, 

# find / -user dan

Here, we are locating all the files that are created by user ‘dan’. Similarly, we can also search for files or folders that are owned by a group by replacing -user with -group.

# find / -group dan

 

Finding files based on their modification time, Access time & Change time

# find / -mtime 10

It will find all the files that were modified in the last 10 days. Replace mtime with -atime to find all the files that were accessed in the last 10 days.

# find / -cmin -60 

It will find all the files that were changed in the last 60 minutes.

# find / -mmin -60 

It will find all the files modified in the last 60 minutes.

# find / -amin -60 

It will find all the files accessed in the last 60 minutes.

 

Listing all the found files

To get all files and present them in order as ‘ls command’ would, use,

# find . -exec ls -ld {} \;

This will show all the files in output as would be shown by ls command.

 

Finding & deleting the found files

We can also combine some options to locate files & then can also perform an operation to delete them, all in a single command,

# find /etc -type f -name *.txt -size -1M -exec rm -f {} \;

This command will find all the files with .txt as an extension with a size of less than 1 Megabyte & will execute the rm/delete command on found files.

 

Getting Help

Like with any other Linux command, we can also take help from the OS documentation to get more detailed information about the command. Use,

# find –help

how to use find command in linux

With this, we complete our tutorial on how to use the FIND command in Linux.  These are only some examples, certainly, there are plenty of ways that you can use the find command to get what you need. If you run into any issues or have any questions, please do send us using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to use FIND command in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-use-find-command-in-linux/feed/ 0 1333
How to use NMAP command to test Server/Network Security https://thelinuxgurus.com/how-to-use-nmap-command-to-test-server-network-security/ https://thelinuxgurus.com/how-to-use-nmap-command-to-test-server-network-security/#respond Mon, 01 Mar 2021 15:26:18 +0000 https://thelinuxgurus.com/?p=1324 NMAP command (short for Network Mapper) is an open-source network security tool & is the best port scanner for your server/network. Nmap command is widely...

The post How to use NMAP command to test Server/Network Security appeared first on The Linux GURUS.

]]>
NMAP command (short for Network Mapper) is an open-source network security tool & is the best port scanner for your server/network. Nmap command is widely used for auditing the network security & also for the penetration testing of your networks. 

It displays the open or exposed ports or services on your or another target machine/network & along with that, it will also provide other information of the system like Operating system, etc.

Another way that we can use Nmap is for “Network Discovery”. 

In this tutorial, we will learn how we can use the Nmap command to test out our system or network security & check all the open or exposed services on the target system with the help of some examples.

Recommended Read: Install & learn to use TCPDUMP with examples

Also Read: How to Schedule a Shutdown in Linux using Crontab?

 


NMAP command Installation


Nmap is pre-installed on almost all Linux distributions, none the less you can use the following commands if that’s not the case to install it on some of the popular Linux distributions.

 

RHEL/CentOS/Oracle Linux/Scientific Linux

# yum install nmap

Ubuntu/Mint/Debian

$ sudo apt-get install nmap

Fedora/CentOS 8/RHEL 8

$ dnf install nmap

 


Nmap Command Examples


Now let’s move on to discuss some of the examples for the Nmap utility.

1- Scanning a single IP

To scan a single system on our network, open terminal & execute the following command,

$ nmap 10.10.1.10

Similarly, we can also scan a system with its hostname,

$ nmap mail.thelinuxgurus.com

 

2- Scan multiple IPs

For scanning multiple IPs, we can mention all the IPs followed by a space. Like this,

$ nmap 10.10.1.10 10.10.1.200

Or to scan an IP address range,  we can also mention a range,

$ nmap 10.10.1.10-110

Similarly for scanning a full subnet,

$ nmap 10.10.1.0/24

 

3- Scanning IP list from a file

If you have saved IP addresses in a file, then we can also mention a file to scan all IPs mentioned in that file,

$ nmap –iL ips.txt

where ‘ips.txt’ is the file containing all the IP addresses. 

 

4- Port scanning

For scanning a single port of a machine, we can mention the port number along with option ‘p’,

$ nmap –p 22 10.10.1.10

For scanning a range of ports, use

$ nmap –p 100-1000 10.10.1.10

For scanning all the ports i.e. 65535 ports, run the following command,

$ nmap –p 10.10.1.10

For scanning 100 most common ports, used option ‘F’ with nmap command,

$ nmap –F 10.10.1.10

This scan is also known as a Fast scan.

 

5- Ping a device aka Host discovery

This is normally used to make sure that the device is up or not. We can also call it Host Discovery,

$ nmap –sP 10.10.1.0/24

 

6- TCP port scan

To perform a scan on all TCP ports in a host, use the options ‘sT’ with nmap command,

$ nmap –sT 10.10.1.10

 

7- UDP port scan

To run the port scanning on all UDP ports in a host, use the options ‘sU’ with nmap command,

$ nmap –sU 10.10.1.10

 

8- OS & Service scan

To check only the Operating System of the target machine, use ‘O’ option,

$ nmap –O 10.10.1.10

In addition to the Operating system & we can also check all the services running on the system with the use of option ‘A’ with nmap command,

$ nmap –A 10.10.1.10

 

9- Show all host interfaces & routes

To get all the interfaces that are available on the target system & also show all the routes of the system, use the option ‘iflist’,

$ nmap –iflist

 

10- Scan a firewall-protected system

To scan a target system that has been protected by a firewall, we can use the options ‘PN’ with nmap command,

$ nmap –PN 10.10.1.10

 

11- Redirecting output to a file

To redirect the output of a command to a text file, use the option ‘oN’ followed by the filename,

$ nmap –oN output.txt 10.10.1.10

Similarly, we can also export output to an XML file, using the option ‘X’,

$ nmap –oX output.xml 10.10.1.10

Or alternatively, just use the redirect symbols to redirect output to a file,

$ nmap 10.10.1.10 > output.txt

 

12- Getting Help

If you have not found the nmap functionality that you require or need more information about the various options that can be used with Nmap, you can refer to help as well,

$ nmap –help

nmap command

Nmap command is fairly extensible & a big topic to cover in a single tutorial, whatever we have mentioned here are some of the basic commands to get you started with Nmap. We will try to publish some more advanced examples on how you can use the Nmap command in Linux.

This completes our tutorial, please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to use NMAP command to test Server/Network Security appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-use-nmap-command-to-test-server-network-security/feed/ 0 1324
How to Execute a Command or a Script on system Startup or Reboot https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/ https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/#respond Tue, 16 Feb 2021 16:42:49 +0000 https://thelinuxgurus.com/?p=1166 Being a Linux system admin or even a general Linux user, you might be required to run some commands or scripts at a regular interval...

The post How to Execute a Command or a Script on system Startup or Reboot appeared first on The Linux GURUS.

]]>
Being a Linux system admin or even a general Linux user, you might be required to run some commands or scripts at a regular interval or at a needed time. We use crontab to accomplish these tasks & we have already discussed Crontab in our tutorial. But how can we execute a command or script on system startup or after a reboot?

Well, there are two ways we can execute a command or script on system startup or after a reboot,

1- using ‘/etc/rc.local’ file

2- using Crontab

Recommended Read:  Beginner’s guide to Backup Postgres Database

Also Read: Scheduling CRON Jobs with Crontab for Beginners

Let’s discuss both these methods one by one.


1- Using ‘/etc/rc.local’ file

This is my go-to method when I need to execute a command or script on system startup. To execute a command on startup, open the file ‘/etc/rc.local’,

NOTE:- In the latest CentOS version, we might find this file in ‘/etc/rc.d/rc.local’.

$ sudo vi /etc/rc.local

& add it into the file with full command path, like,

/bin/date

Save file & exit. To get the full path of the command, you can run the ‘which’ command,

$ which date

Now the command will execute on each startup or after a reboot as well. To add a script to the file, first make sure that the script is executable,

$ chmod +x /home/linuxtechlab/test.sh

& then edit the rc.local file,

$ sudo vi /etc/rc.local

/bin/sh /home/linuxtechlab/test.sh

Save the file & exit, we are done. Now let’s see the second method as well.


2- Using Crontab

For this method, we only need to create a new crontab job in our system. So to create a new crontab job, run the following command,

$ crontab -e

Then add the following job to crontab,

@reboot (sleep 120; /bin/sh /home/linuxtechlab/test.sh)

So we added the job to run on every reboot with a sleep period of 120 seconds because we want our system to be fully up before our script is executed, otherwise, our script might fail to run. We now end this tutorial on how to execute command or script on system startup or after a reboot. Please do share any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post How to Execute a Command or a Script on system Startup or Reboot appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/how-to-execute-a-command-or-a-script-on-system-startup-or-reboot/feed/ 0 1166
Install EPEL repository on CentOS/RHEL 6, 7 & 8 https://thelinuxgurus.com/install-epel-repository-on-centos-rhel-6-7-8/ https://thelinuxgurus.com/install-epel-repository-on-centos-rhel-6-7-8/#comments Wed, 20 Jan 2021 13:03:30 +0000 https://thelinuxgurus.com/?p=885 EPEL repository is part of special groups within the fedora group, it creates & maintains additional packages for Enterprise Linux, mainly CentOS, RHEL, Scientific Linux,...

The post Install EPEL repository on CentOS/RHEL 6, 7 & 8 appeared first on The Linux GURUS.

]]>
EPEL repository is part of special groups within the fedora group, it creates & maintains additional packages for Enterprise Linux, mainly CentOS, RHEL, Scientific Linux, Oracle Linux. EPEL stands for Extra Packages for Enterprise Linux & provides packages that are not available with the default repositories.

Recommended Read: Examples on how to use YUM command in Linux

Also Read: Scheduling CRON Jobs with Crontab for Beginners

There are two methods using which we can install the EPEL repository on the Linux system,

1- Using the packages from default repositories

2- Using rpm package


1- Using the packages from the default repositories

To install the package from default repositories, use the following command,

CentOS/RHEL 6/7

# yum install epel-release

CentOS/RHEL 8

# dnf install epel-release

This command will work most of the times but I have faced an issue with some versions where this might not work. So if this does not work for you, then you can use the second method.


2- Using RPM packages

For this method, we will directly install the RPM package for epel repository. Based on the version, use one of the following commands,

RHEL/CentOS 6:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

RHEL/CentOS 7:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Epel also recommends for RHEL 7, to enable the optional, extras, and HA repositories since EPEL packages may depend on packages from these repositories, using the following command,

# subscription-manager repos –enable “rhel-*-optional-rpms” –enable “rhel-*-extras-rpms” –enable “rhel-ha-for-rhel-*-server-rpms”

RHEL/CentOS 8:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Note:- EPEL also recommends for RHEL 8, to enable the code ready-builder-for-rhel-8-*-rpms repository since EPEL packages may depend on packages from it. To install it, use the following commands,

# ARCH=$( /bin/arch )

# subscription-manager repos –enable “codeready-builder-for-rhel-8-${ARCH}-rpms”

Note:- For CentOS 8, EPEL recommends to also enable the PowerTools repository since EPEL packages may depend on packages from it, run the following command to enable power tools,

# dnf config-manager –set-enabled PowerTools


Check repository

Once the EPEL repository has been installed, we can check it by executing the following command,

RHEL/CentOS 6/7

# yum repolist

RHEL/CentOS 8

# dnf repolist epel

We can now install the packages available in the EPEL repository. Please share this tutorial, or if you have any questions, concerns or suggestions, please send them to us using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Install EPEL repository on CentOS/RHEL 6, 7 & 8 appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/install-epel-repository-on-centos-rhel-6-7-8/feed/ 1 885
Beginner’s guide to NGINX SSL CONFIGURATION https://thelinuxgurus.com/beginners-guide-to-nginx-ssl-configuration/ https://thelinuxgurus.com/beginners-guide-to-nginx-ssl-configuration/#respond Tue, 27 Oct 2020 15:41:29 +0000 https://thelinuxgurus.com/?p=1247 Security is one of the main concerns that needs to be addressed on priority for all applications or websites. All websites are required to have...

The post Beginner’s guide to NGINX SSL CONFIGURATION appeared first on The Linux GURUS.

]]>
Security is one of the main concerns that needs to be addressed on priority for all applications or websites. All websites are required to have a valid SSL certificate installed in order to encrypt the data packets/traffic between users & websites. Even web browsers show a warning when we visit a website that does not have SSL certificate installed.

In this tutorial, we will discuss how we can perform Nginx SSL configuration to configure a SSL certificate to secure our websites hosted on Nginx. So start the complete process for Nginx SSL configuration but let’s discuss the prerequisites first.

Pre-requisites

Now let’s move on to Nginx SSL configuration part. We will first be creating a self-signed certificate first  & then will configure the Nginx web server to use that certificate.

Recommended Read: Create a SELF-SIGNED SSL Certificate in Linux

Also Read: How to Host Multiple Websites with Nginx in Linux


Create a self signed certificate

Create a certificate with the following command,

$ openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /home/shusain/test.key -out /home/shusain/test.crt

here, openssl command is used for managing ssl,

req –x509 is public key infrastructure for ssl,

-nodes, means we don’t need a passphrase,

-days 365 is the validity of the certificate in days,

-newkey rsa:2048  means cert will 2048 bit long & uses RSA as encryption,

-keyout,provides the location for private key,

-out provides the place our SSL certificate.

So now, we have our private key (home/shusain/test.key) & a self signed certificate (home/shusain/test.crt). We need both these to configure ssl certificates in nginx.

So let’s move them to a new folder for ease of administration,

# mkdir /etc/nginx/ssl

# mv /home/shusain/test.key /etc/nginx/ssl/

# mv /home/shusain/test.crt /etc/nginx/ssl/

Now let’s move on to next step i.e. Nginx SSL configuration.


Nginx SSL configuration

Now that we have the required private key and certificate with us, we configure the SSL certificate in Nginx. We can use ‘/etc/nginx/nginx.conf’ to configura the ssl in Nginx but it is advisable to create a separate file for ssl,

# vi /etc/nginx/conf.d/ssl.conf

& enter the following lines to the file,

server {

    listen 443 ssl;

    server_name example.com;

    ssl_certificate /etc/nginx/ssl/test.crt;

    ssl_certificate_key /etc/nginx/ssl/test.key;

    ssl_dhparam /etc/ssl/certs/dhparam.pem;

root /var/www/html;

index index.html index.htm index.nginx-debian.html;

}

All we have to do is to reload the nginx configuration to complete the Nginx SSL configuration & install ssl certificate in Nginx,

# systemctl reload nginx

Now we can access our website with the https followed by the website URL,

https://example.com

Since we are using a self-signed certificate, we might get a warning but we can ignore that & click on ‘Proceed anyway’ to open the website.


Additional Parameters for SSL

The above-mentioned parameters are the basic configuration for SSL, we can actually select a number of options like TLS versions. Ciphers suites as well depending on our need.

An example to additional parameters that can be used are,

server {

    listen 443 ssl;

    server_name example.com;

    ssl_certificate /etc/nginx/ssl/test.crt;

    ssl_certificate_key /etc/nginx/ssl/test.key;

    ssl_dhparam /etc/ssl/certs/dhparam.pem;

    root /var/www/html;

     index index.html index.htm;

    ssl_protocols TLSv1 TLSv1.1 TLSv1.2;

    ssl_prefer_server_ciphers on;

    ssl_ciphers “EECDH+AESGCM:EDH+AESGCM:AES256+EECDH:AES256+EDH”;

    ssl_ecdh_curve secp384r1;

    ssl_session_cache shared:SSL:10m;

    ssl_session_tickets off;

    ssl_stapling on;

    ssl_stapling_verify on;

    resolver 8.8.8.8 8.8.4.4 valid=300s;

    resolver_timeout 5s;

    add_header Strict-Transport-Security “max-age=63072000; includeSubdomains”;

    add_header X-Frame-Options DENY;

    add_header X-Content-Type-Options nosniff;

}

This completes our tutorial on how to perform Nginx SSL configuration & install a SSL certificate in Nginx. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Beginner’s guide to NGINX SSL CONFIGURATION appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/beginners-guide-to-nginx-ssl-configuration/feed/ 0 1247
Create a SELF-SIGNED SSL Certificate in Linux https://thelinuxgurus.com/create-a-self-signed-ssl-certificate-in-linux/ https://thelinuxgurus.com/create-a-self-signed-ssl-certificate-in-linux/#comments Tue, 29 Sep 2020 07:08:56 +0000 https://thelinuxgurus.com/?p=1222 Security threats like data theft etc are on the rise & it is of utmost importance that we employ some security to avoid such incidents....

The post Create a SELF-SIGNED SSL Certificate in Linux appeared first on The Linux GURUS.

]]>
Security threats like data theft etc are on the rise & it is of utmost importance that we employ some security to avoid such incidents. This is especially true when we are trying to access some websites over the public internet & our connections are not secure.

To avoid such unencrypted data transfers, we use SSL certificates. SSL or Secure Socket Layer is a protocol that is used for securing encrypt our website traffic. This avoids data theft, even if the data would have been intercepted by a 3rd party, it will be useless to them as the encryption used to secure the traffic is quite strong. 

SSL certificates are of such importance that now almost all web browsers show a warning when we are visiting a website that does not have a valid SSL certificate in use.

The SSL certificate that is used to secure the websites on the Public internet uses SSL certificates that are signed by Certification Authorities (CA) like Comodo, GeoTrust, Symantec, etc & they charge a fee for that. And then there are CAs like Let’s Encrypt which provide SSL certificate for free but for a lesser duration.

But we might not require any of these SSLs when we are using an SSL certificate for the testing environment or for development purposes. There we can only use self-signed certificates.

Recommended Read: How to create an SSL certificate with certbot

Also Read: How to install NGINX from Source packages in Linux

In this tutorial, we will discuss how to create a self-signed certificate in Linux. Let’s discuss the process,


Create Self Signed SSL certificate in Linux


To create a self-signed certificate in Linux, we need to have packages named ‘openssl’ & ‘mod_ssl’ installed on our system. Openssl is installed by default on all Linux distributions & we can install mod_ssl with the following command,

# yum install mod_ssl

Now we can create the SSL certificate using the openssl command mentioned below,

# openssl req -x509 -nodes -days 365 -newkey rsa:2048 -keyout /home/shusain/ssl.key -out  /home/shusain/ssl.crt

To describe the command mentioned above, 

openssl is the command for managing SSL,

req –x509 is the public key infrastructure for SSL,

-nodes, means we don’t need a passphrase,

-days 365 is the validity of the certificate in days

-newkey rsa:2048  means cert will 2048 bit long & uses rsa encryption,

-keyout, is the location to Private key,

-out is the location for the certificate.

We need to have both  /home/shusain/ssl.key &  /home/shusain/ssl.cert to configure it in our webserver. We will be discussing how we can install an SSL certificate in our Nginx as well as Apache in our future tutorials. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Create a SELF-SIGNED SSL Certificate in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/create-a-self-signed-ssl-certificate-in-linux/feed/ 1 1222
Scheduling CRON Jobs with Crontab for Beginners https://thelinuxgurus.com/scheduling-cron-jobs-with-crontab-for-beginners/ https://thelinuxgurus.com/scheduling-cron-jobs-with-crontab-for-beginners/#respond Tue, 18 Aug 2020 12:07:20 +0000 https://thelinuxgurus.com/?p=866 Crontab is an important utility that is used for scheduling cron jobs i.e. setting up a specified time-based job. Cron job can be a single...

The post Scheduling CRON Jobs with Crontab for Beginners appeared first on The Linux GURUS.

]]>
Crontab is an important utility that is used for scheduling cron jobs i.e. setting up a specified time-based job. Cron job can be a single command or we can also schedule cron to run bash scripts.

These cron jobs help us automate repetitive tasks like backups, system updation, or running some specific command or scripts, etc. We can schedule cron jobs & the system will then execute the mentioned commands or scripts without human intervention. Cron jobs can be scheduled to run on the minute, hour, day of the month, month, day of the week basis. We can also combine any of these to schedule cron jobs.

Recommended Read: Beginner’s guide to Backup Postgres Database

Also Read: How to setup SSH login without password on Linux systems


Scheduling Cron jobs


Syntax:- We need to provide the cron job in the following format,

(minute) (hour) (day of the month) (month) (day of the week) (command/script path)

* * * * * command, script(s)

- - - - -

| | | | |

| | | | ------ Day of the week (0 - 7) (Sunday=0 or 7)

| | | ------- Month (1 - 12)

| | -------- Day of the month (1 - 31)

| ---------- Hour (0 - 23)

------------ Minute (0 - 59)

Commands to list, delete or schedule cron jobs are mentioned below,

-> Schedule cron job or edit a job,

To edit or create a cronjob, run

$ crontab –e


-> Display all cronjobs

$ crontab –l


-> Removing a cronjobs

$ crontab –r

Or we can just edit out a job that we don’t want need with ‘crontab -e’ command.


-> Using crontab for other users

$ crontab -u test_user -e

$ crontab -u test_user -l

$ crontab -u test_user -r

Here, you can replace ‘test_user’ with the username you need to see access cron jobs for. The root user will access to cron jobs for all users by default.


Examples of scheduling cron jobs


1- Running a backup script named backup.sh located at /home/test_user everynight at 10:00PM,

00 22 * * * /etc/test_user/backup.sh


2- Running a weekly backup script named weekly_backup.sh on every Friday at 10:30,

30 23 * * 5 /etc/test_user/weekly_backup.sh


3- Running a monthly backup script named monthly_backup.sh on 30th day of every month at 11:45PM,

45 11 30 * * /etc/test_user/monthly_backup.sh


4- Running backup script named weekday_backup.sh on weekdays only at 11:59 PM

59 11 * * *1-5 /etc/test_user/weekday_backup.sh

or

59 11 * * *1 2 3 4 5 /etc/test_user/weekday_backup.sh

We can also run a script on selective days, like odd days,

59 11 * * *1 3 5 7 /etc/test_user/weekday_backup.sh


5- Running a command every 10 minutes,

* /10 * * * command

These were only some examples of how you can use cron jobs, there are plenty more combinations we can use. We now end our tutorial on scheduling cron jobs on the Linux system. Please feel free to send in any questions or queries you have using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Scheduling CRON Jobs with Crontab for Beginners appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/scheduling-cron-jobs-with-crontab-for-beginners/feed/ 0 866
Top Linux commands to monitor NETWORK https://thelinuxgurus.com/top-linux-commands-to-monitor-network/ https://thelinuxgurus.com/top-linux-commands-to-monitor-network/#comments Tue, 07 Jul 2020 05:40:12 +0000 https://thelinuxgurus.com/?p=1171 Monitoring the system & its resources is one of the most important tasks for a system admin & we should be aware of it. There...

The post Top Linux commands to monitor NETWORK appeared first on The Linux GURUS.

]]>
Monitoring the system & its resources is one of the most important tasks for a system admin & we should be aware of it. There are plenty of 3rd party tools like Nagios, Zabbix etc that we can use for complete system monitoring & are extremely useful when dealing with a number of systems. But if you have a single or less number of systems, then the best approach would be to use the Linux in-built monitoring commands.

Recommended Read: How to Execute a Command or a Script on system Startup or Reboot

Also Read: Learn to use KILL COMMAND in Linux

In this tutorial, we will only discuss Linux commands to monitor network traffic. On some Linux distributions these commands might be installed by default, but on some they might need to be installed. So let’s start by discussing the pre-requisites first.

Pre-Requisites

We need to have EPEL repository installed on our system in order to install some of these commands. We do have a nice, detailed article for installation of the same HERE https://thelinuxgurus.com/install-epel-repository-on-centos-rhel-6-7-8/. You can also use the commands below to install EPEL repository on your systems,

RHEL/CentOS 6:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-6.noarch.rpm

RHEL/CentOS 7:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-7.noarch.rpm

Epel also recommends for RHEL 7, to enable the optional, extras, and HA repositories since EPEL packages may depend on packages from these repositories, using the following command,

# subscription-manager repos –enable “rhel-*-optional-rpms” –enable “rhel-*-extras-rpms” –enable “rhel-ha-for-rhel-*-server-rpms”

RHEL/CentOS 8:

# yum install https://dl.fedoraproject.org/pub/epel/epel-release-latest-8.noarch.rpm

Now let’s discuss the Linux commands to monitor network one by one.


Netdiag utility

Netdiag is itself not a command itself but is a collection of network diagnostics tools. The commands like netwatch, trafshow & netload commands are all part of it & are also discussed in this article below.

RHEL/CentOS

# yum install netdiag

Fedora

# dnf install netdiag

Ubuntu/Debian

# apt-get install netdiag


Nload command

Nload command is used to fetch information about the incoming & outgoing traffic. It generates a graph that indicates the incoming and outgoing traffic. Nload command does not support many options i.e. we won’t get much information related to individual processes but we can adjust the scale.

So to Install it, use the following command,

RHEL/CentOS (need to have EPEL repo installed)

# yum install nload

Fedora

# dnf install nload

Ubuntu/Debian

# apt-get install nload

Now to start using it, run

# nload


Netwatch command

Netwatch command shows the total speed at which data transfer for each connection from the local system to the remote systems. If need to check the transfer speed from an interface, we can use the following command,

# netwatch -e en0sp3 -nt


Iftop command

Iftop command is one of the most useful Linux commands to monitor networks. It provides real-time monitoring of network bandwidth & provides the total data moving in & out of the individual socket connections i.e. it captures packets moving in and out from our network adapters & then it sums up to find the total bandwidth being utilized by a server.

Run the following command from your terminal to install it your server,

RHEL/CentOS (need to have EPEL repo installed)

# yum install iftop

Fedora

# dnf install iftop

Ubuntu/Debian

# apt-get install iftop

Then to start monitoring the network, run the following command,

# iftop

For more detailed information on the options that can be used with iftop, use command help,

# iftop –help


tcptrack command

tcptrack command is very similar to the iftop command. Tcptrack captures packets & then calculates the network bandwidth for each of the tcp connections. To calculate the network bandwidth, it uses the pcap library.
To install it on your systems, use the following command,

RHEL/CentOS

# yum install tcptrack

Fedora

# dnf install tcptrack

Ubuntu/Debian

# apt-get install tcptrack

To get the network stats, open terminal & run the following command,

# tcptrack


Iptraf commands

Another one of the useful network monitoring commands. Iptraf generates a colorful & interactive list of traffic in & out to/from other servers/hosts. The list has information about all the hosts from which traffic is going in & out.
To install it on the system, use one of the following commands,

RHEL/CentOS (need to have EPEL repo installed)

# yum install iptraf-ng

Fedora

# dnf install iptraf-ng

Ubuntu/Debian

# apt-get install iptraf-ng

To generate the network traffic reports, run the following command,

# iptraf


Netload command

Of all the commands that are part of netdiag package, netload is simplest to use & understand as it provides only a simple report on current network traffic from the system. It also shows the total amount of data transferred since its start.

To get the netload report, run the netload command followed by the ethernet port name. For example,

# netload en0sp3


Trafshow commands

Trafshow command is similar to the tcptrack command. It can filter the traffic based on pcap filters & shows data transfer speed of all active connections along with the protocol, tcp/udp.
To use it, execute the following command from the terminal,

# trafshow -i en0sp3 udp

These were some of the commands that we can use to monitor our Linux system network. We will also discuss some other commands to monitor system memory, CPU & disk usage in our future tutorials. Please feel free to send us any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Top Linux commands to monitor NETWORK appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/top-linux-commands-to-monitor-network/feed/ 1 1171
Learn to use KILL COMMAND in Linux https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/ https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/#respond Tue, 16 Jun 2020 06:51:20 +0000 https://thelinuxgurus.com/?p=981 At one time or another, you must have faced the problems with Linux processes, either process are stuck or are unresponsive completely. Some of the...

The post Learn to use KILL COMMAND in Linux appeared first on The Linux GURUS.

]]>
At one time or another, you must have faced the problems with Linux processes, either process are stuck or are unresponsive completely. Some of the time the process restart also does not work & the only thing that can be done is terminating the process completely, that’s where the kill command comes in handy.

Recommended Read: How to change timezone in Linux

Also Read: Examples on how to use PS COMMAND in Linux

There are many other commands as well that can perform the same operation but kill command is most popular & widely used. Let’s see the syntax for using kill command,

Syntax

# kill -signal pid(process_id)

It provides a lot of options i.e. signal to handle the processes. Let’s discuss a little more about kill command with the help of some examples.


Examples

List all the kill signals available

Kill has a lot of signals available to manage the running or stuck processes & we should know how to check & use them. To get the complete list of all kill signals, the command is

# kill -l

kill command

So there are 63 signals that we can use with kill command but most of them are not used at all. The mostly used signals are,

  • 1 (HUP) – Reload a process

  • 9 (KILL) – Kill a process

  • 15 (TERM) – Gracefully stop the process


Stop a process

To stop a process, we must know the process id which can be obtained by using the ps command,

# ps -ef | grep haproxy

Or you can also use another command to get the process id,

# pidof haproxy

Once you have the process id, we can use it to terminate/reload or gracefully stop the process. You can use the kill command the following 3 ways,

# kill -9 pid

# kill -SIGKILL pid

# kill -KILL pid

You can either use the signal number, signal name or signal name without SIG.


Reload a process

With kill command, we can also reload the process, again we would first need the process id first. We can then use the following command to reload the process,

# kill -1 pid

# kill -SIGHUP pid

# kill -HUP pid

We can use either of the three commands.


Gracefully stop a process

To gracefully stop a process, we can use the either of the following commands,

# kill -15 pid

# kill -SIGTERM pid

# kill -TERM pid

We end this tutorial on how to use kill in Linux. Please do let us know if you have any questions, queries or suggestions using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Learn to use KILL COMMAND in Linux appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/learn-to-use-kill-command-in-linux/feed/ 0 981
Beginner’s guide to Backup Postgres Database https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/ https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/#respond Tue, 28 Apr 2020 14:14:22 +0000 https://thelinuxgurus.com/?p=863 Backups are important & they are our only contingency for when we delete things that we should not or there are malfunctions hardware or otherwise....

The post Beginner’s guide to Backup Postgres Database appeared first on The Linux GURUS.

]]>
Backups are important & they are our only contingency for when we delete things that we should not or there are malfunctions hardware or otherwise. Backups at regular intervals are essential for any organization to maintain a proper working environment. Same goes for database, database backups are extremely essential as it holds transactional, user data among other things.

In this tutorial, we will learn about PostgreSQL backup. Before we start this, you can also refer to our tutorials on installing Postgresql on CentOS/RHEL, also for installation on Ubuntu & installing Postgresql from the source.

Recommended Read: Important postgresql commands for beginners


Backup Postgres Database


Postgresql provides backup utilities when we install postgresql on the server, they are pg_dump & pg_dumpall. Pg_dump is most useful for taking postgresql backup of a single database, while pg_dumpall provides the postgresql backup for all databases on the server. Let’s see some examples.

Backup Postgres database, single DB

Start by switching to the user postgres,

# su – postgres

Now to back up a database, use the following command,

$ pg_dump -U user_name -d thelinuxgurus > thelinuxgurus.bak

Here, ‘thelinuxgurus’ is the name of the database we need to backup. We can also use .sql or .tar as extension to backup file.


Taking backup of one or more tables in postgres

Command to take the backup of a single table from a database is,

$ pg_dump -U User_name -d database_name -t public.users_table > users_table.bak

To take the backup of more tables,

$ pg_dump -U User_name -d database_name -t public.users_table public.test_table public.test_table_2 > 3_tables.bak


Restoring a database

Now if we need to restore the backup, we need to drop the old database & create an empty database,

$ dropdb thelinuxgurus

$ createdb new_db

Not to restore the backup, use the following command,

$ psql new_db < thelinuxgurus.bak

Or we can also use pg_restore utility to restore a database, use the following command to restore the database using pg_restore utility,

$ pg_restore -d db_name /path/to/your/file/thelinuxgurus.bak -c -U db_user


Restore one or more tables from backup

Similarly, we can also restore the backup of one or more tables,

$ pg_restore -U user_name –data-only -d target-db-name -t table_name /path/to/your/file/users_table.bak


Taking only schema backup

To take the backup of schema only, use the following command,

$ pg_dump –schema=schema_name db_name > schema.bak


Restoring schema backup

To restore schema backup, use the following command,

$ psql -d db_name -U user_name < schema.bak


Taking all database backup

The second backup utility i.e. pg_dumpall is used for taking backup of all the databases on postgreSQL. To take backup use the following command,

$ pg_dumpall > all_databases.bak


Restore all databases backup

To restore all database backup, use the following command,

$ psql -f all_databases.bak postgres

We can also use all or any of the above-mentioned commands & create a cron job for it to automate our backups. Please refer to our tutorial on Scheduling Cron jobs on Linux system. We now end this tutorial on backup Postgres database. Please feel free to send in any questions or queries using the comment box below.

If you think we have helped you or just want to support us, please consider these:-

Connect to us: Facebook | Twitter | Linkedin

TheLinuxGURUS are thankful for your continued support.

The post Beginner’s guide to Backup Postgres Database appeared first on The Linux GURUS.

]]>
https://thelinuxgurus.com/beginners-guide-to-backup-postgres-database/feed/ 0 863