In this article, you will learn how to set up a cron job in Magento 2 via the Command Line. Setting the cron jobs is an essential part to ensure the proper functioning of your Magento 2 store.
Step 1. Connect to Magento server using SSH
Connect to the Magento server using SSH. Read details for Windows OS or MAC OS or Linux OS
Step 2. Find the PHP binary and php.ini path
Once you’ve connected to the Magento server – find the PHP binary and php.ini path
To discover the path to your PHP binary, please type the following command:
which php

A sample result will be as the following:
/usr/bin/php

Step 3. Open the cron tab editor
Execute the following command in order to edit the cron tab.
crontab -e

After this command has been performed – the cron tab editor will open.

Step 4. Copy the code to set up a cron job
To set up the cron jobs, paste the following lines of code:
* * * * * <path to php binary> <magento install dir>/bin/magento cron:run | grep -v "Ran jobs by schedule" >> <magento install dir>/var/log/magento.cron.log
* * * * * <path to php binary> <magento install dir>/update/cron.php >> <magento install dir>/var/log/update.cron.log
* * * * * <path to php binary> <magento install dir>/bin/magento setup:cron:run >> <magento install dir>/var/log/setup.cron.log
where <path to php binary> is the absolute file system path to your PHP binary, and <magento install dir> is your Magento root folder. For example, /var/www/mystore

This way your Magento 2 cron jobs should be up and running.