My Youtube Channel

Please Subscribe

Flag of Nepal

Built in OpenGL

Word Cloud in Python

With masked image

Saturday, August 5, 2023

Difference between dnf, yum and apt in linux based operating system

 `dnf`, `yum`, and `apt` are package managers used in different Linux distributions. Each one has its specific features and is associated with different distributions.


1. **dnf (Dandified YUM)**:

   - Used primarily in RPM-based distributions like Fedora, CentOS 8, RHEL 8, and other derivatives.

   - Provides a more modern and improved version of `yum`.

   - Faster and more efficient due to the use of libsolv library for dependency resolution.

   - Has a different command syntax compared to `yum`.

   - Introduced in Fedora 18 and became the default package manager in CentOS 8 and newer.


2. **yum (Yellowdog Updater Modified)**:

   - Used in RPM-based distributions like CentOS 7, RHEL 7, and older versions of Fedora.

   - An older package manager that served as the predecessor to `dnf`.

   - Slower and less efficient compared to `dnf`, especially in large repositories with complex dependencies.

   - Has a different set of commands and options compared to `dnf`.

   - Still available in CentOS 8 but not installed by default.


3. **apt (Advanced Package Tool)**:

   - Used primarily in Debian-based distributions like Debian, Ubuntu, and their derivatives (e.g., Linux Mint, elementary OS).

   - Uses the `.deb` package format instead of RPM.

   - Has a different set of commands and options compared to `dnf` and `yum`.

   - Uses `dpkg` as the underlying low-level package manager.

   - Generally regarded as easy to use and user-friendly.


While all three package managers serve the same purpose of installing, removing, and managing software packages on a Linux system, the main differences lie in the distribution they are associated with, the package formats they handle (RPM for `dnf` and `yum`, and `.deb` for `apt`), and the specific commands and options they offer. The choice of package manager depends on the Linux distribution being used. For instance, if you are using Fedora, CentOS 8, or RHEL 8, `dnf` would be the default and recommended package manager, while for Debian-based systems, `apt` is the standard choice.

Difference between 'dnf' and 'yum' in Centos

`dnf` (Dandified YUM) has become the default package manager in CentOS 8 and newer versions. Both `dnf` and `yum` are package managers used in CentOS and other RPM-based Linux distributions, but there are some differences between the two:


1. **Performance**: `dnf` is generally faster and more efficient than `yum`. It uses the libsolv library for dependency resolution, which is more powerful and faster than the `yum`-based resolver.


2. **Command syntax**: While both `dnf` and `yum` have similar command structures, some commands and options may differ slightly between the two. For example, `dnf` uses "group" instead of "groupinstall" and "module" instead of "module install".


3. **Dependencies and plugins**: `dnf` uses a plugin model that's different from `yum`. Some plugins may be available for one but not the other, or they might have different implementations.


4. **Transaction history**: `dnf` keeps its transaction history in SQLite format, while `yum` uses the simpler "yum history" command.


5. **Default behavior**: In CentOS 8 and later, `dnf` is the default package manager, and `yum` is still available but not installed by default. In earlier versions of CentOS, `yum` was the default.


6. **User experience**: `dnf` provides better feedback during the command execution and generally has more user-friendly output.


Keep in mind that since `dnf` has been adopted as the default package manager, it is recommended to use `dnf` in CentOS 8 and newer versions for compatibility and better performance. If you are using an older CentOS version that still uses `yum`, consider upgrading to a newer release to take advantage of `dnf`.

Various search operation options on Centos

Search for files or directories:

In CentOS 7, you can use various commands and tools to search for files or folders. Here are some common methods:


1. Using the `find` command:

The `find` command is a powerful tool to search for files and directories based on various criteria.

To search for a file named `filename.txt` starting from the root directory (/), open a terminal and run:


find / -name "filename.txt"

Replace `"filename.txt"` with the name of the file you're looking for.


To search for a directory named `dirname`, use the same command:

find / -type d -name "dirname"


2. Using the `locate` command:

The `locate` command utilizes a pre-built database of files for faster searching.

First, make sure the `mlocate` package is installed:

sudo yum install mlocate


Then, update the database:

sudo updatedb


Finally, search for a file or directory:

locate filename.txt

locate dirname

Note that `locate` provides faster results but might not show the most up-to-date information as it depends on the last database update.


3. Using `grep` command (for specific text within files):

If you are looking for files containing specific text, you can use the `grep` command. For example, to search for the word "example" within all files in the current directory and its subdirectories:

grep -r "example" .

The `.` represents the current directory. You can replace it with a specific directory path.


4. Using `whereis` command (for system binaries and manuals):

The `whereis` command is helpful for finding the binary and source files of a command or application.

For example, to find the location of the `ls` command:

whereis ls

These methods should help you search for files and folders efficiently on CentOS 7. Choose the appropriate method based on your requirements.


Search by filename extension:

To search for files by their extension in CentOS 7, you can use the `find` command along with the `-name` option and a wildcard to specify the file extension. Here's how you can do it:

Let's say you want to search for files with the extension `.txt` in the `/home/user/documents` directory:

find /home/user/documents -type f -name "*.txt"


Explanation:

- `find`: The command to search for files and directories.

- `/home/user/documents`: The starting directory for the search. Replace this with the directory where you want to begin the search. If you don't know the directory name or path just use '/' instead of full path like 

find / -type f -name "*.txt"

- `-type f`: Specifies that we are only interested in files (not directories).

- `-name "*.txt"`: The `-name` option allows us to specify a pattern to match filenames. Here, we use the wildcard `*` to match any characters before the `.txt` extension. This way, it will find all files with the `.txt` extension.


You can adjust the file extension and the directory path as needed to search for different file types in different locations. If you want to search for different file extensions, simply change `*.txt` to the desired extension (e.g., `*.pdf`, `*.jpg`, etc.).

Uninstall MariaDB completely along with its dependencies from the Centos

 To uninstall MariaDB on CentOS 8, you can use the `yum` package manager. Follow these steps to uninstall MariaDB:


1. **Stop the MariaDB service**:

   Before uninstalling, it's better to stop the MariaDB service to avoid any issues. Open a terminal and run the following command:

   sudo systemctl stop mariadb


2. **Remove the MariaDB packages**:

   Once the service is stopped, you can proceed to remove the MariaDB packages using `yum`:

   sudo yum remove mariadb-server mariadb-client


3. **Remove data and configuration files (optional)**:

   By default, the package manager may not remove the MariaDB data and configuration files. If you want to remove them as well, run the following commands:

   sudo rm -rf /var/lib/mysql

   sudo rm -rf /etc/my.cnf


   Please be cautious while running the `rm` command, as it permanently deletes the files and directories.


4. **Clean up dependencies (optional)**:

   You can also clean up any unused dependencies to free up disk space:

   sudo yum autoremove


That's it! MariaDB should now be uninstalled from your CentOS 8 system. Before performing these steps, make sure to back up any important databases to prevent data loss.

Install MariaDB on Centos

 To install MariaDB on CentOS 8, follow these steps:


1. Update the system packages:

   Before installing any software, it's a good idea to update your system to ensure you have the latest packages. Open a terminal or SSH into your CentOS 8 server and run the following commands:

   sudo dnf clean all

   sudo dnf update


2. Install MariaDB server:

CentOS 8 uses the DNF package manager, so you can easily install MariaDB by running the following command:

   sudo dnf install mariadb-server


3. Start and enable the MariaDB service:

   After the installation is complete, start the MariaDB service and enable it to start on boot using the following commands:

   sudo systemctl start mariadb

   sudo systemctl enable mariadb


4. Secure the MariaDB installation:

   By default, MariaDB is not configured with a root password, and it is recommended to set a root password for security. You can run the following command to secure your installation:

   sudo mysql_secure_installation

   This command will prompt you to set the root password, remove anonymous users, disallow root login remotely, and remove the test database. You can choose 'Y' or 'N' based on your preferences and requirements.


5. Verify the installation:

   To check if MariaDB is running and to verify its version, you can use the following command:

   sudo systemctl status mariadb

   mysql --version


That's it! MariaDB is now installed and running on your CentOS 8 system. You can interact with the database using the `mysql` command-line client or other tools like phpMyAdmin if you have a web server installed.

Solved: MariaDB failed to start with error message "job for mairadb.service failed because the control process exited with error code"

Here are some steps you can follow to resolve the issue:


1. **Check for Running Processes**: As the logs indicate, another process is already using port 3306. You can verify this by running the following command:

   sudo netstat -tulnp | grep 3306


 The command will show you the process ID (PID) of the process using port 3306. Make a note of the PID.

for example,

[root@Pinrecovery ~]# sudo netstat -tulnp | grep 3306

tcp6       0      0 :::3306                 :::*                    LISTEN      110920/mysqld


Here, the process id is: 110920


2. **Stop the Conflicting Process**: Once you identify the PID of the process using port 3306, you can stop it using the `kill` command. Replace `<PID>` with the actual PID you obtained in the previous step:

   sudo kill <PID>


3. **Start MariaDB**: After stopping the conflicting process, try starting the MariaDB service again:

   sudo systemctl start mariadb


4. **Check SELinux**: If you're still having issues with starting MariaDB, ensure that SELinux is not causing any problems. Temporarily disable SELinux to see if it resolves the issue:

   sudo setenforce 0

   However, keep in mind that disabling SELinux is not recommended for security reasons. If SELinux is causing the issue, you should investigate and configure SELinux policies appropriately.


5. **Verify Configuration**: Double-check your MariaDB configuration files (`/etc/my.cnf` or `/etc/mysql/my.cnf`) for any incorrect settings. Ensure that there are no duplicate configurations or conflicts with other services.


6. **Check Hardware/Software Issues**: If the problem persists, investigate for any potential hardware or software issues on your system that might be affecting MariaDB's ability to start.


After attempting the above steps, try starting the MariaDB service again. If the issue persists, review the error messages carefully to understand the root cause, and if needed, seek further assistance from the MariaDB community or forums.

Solution for "error 1045: access denied for user 'root'@'localhost' (using password: no)"

The error message "1045: Access denied for user 'root'@'localhost' (using password: no)" indicates that you are trying to connect to the MariaDB database server as the 'root' user without providing a password, but the server is expecting one.

Here are some steps to troubleshoot and resolve the issue:

1. Check your password:

   Ensure that you are using the correct password for the 'root' user. By default, MariaDB sets an empty password for the 'root' user during installation. If you have set a password and forgotten it, you might need to reset it.


2. Provide the password in your PHP script:

   If you have set a password for the 'root' user, you need to provide it when connecting to the database using `mysqli`. Update your PHP script to include the correct password:


   <?php

   $servername = "localhost";

   $username = "root";

   $password = "your_root_password"; // Update this with the actual password

   $dbname = "your_database";


   // Create connection

   $conn = new mysqli($servername, $username, $password, $dbname);


   // Check connection

   if ($conn->connect_error) {

       die("Connection failed: " . $conn->connect_error);

   }


   echo "Connected successfully";


   // Close connection

   $conn->close();

   ?>



3. Verify MariaDB service status:

   Make sure the MariaDB service is running on your CentOS 8 system. You can check the status using the following command:

   sudo systemctl status mariadb


   If it's not running, start the service:

   sudo systemctl start mariadb


4. Check MariaDB user privileges:

   It's possible that the 'root' user does not have the necessary privileges to connect from 'localhost'. Log in to the MariaDB server as the root user:

   sudo mysql -u root


   Once logged in, check the user privileges:

   MariaDB [(none)]> SELECT user, host FROM mysql.user;

 Make sure there is an entry for 'root' user with 'localhost' as the host. If it's not there, you can add it:


   MariaDB [(none)]> CREATE USER 'root'@'localhost' IDENTIFIED BY 'your_root_password';

   MariaDB [(none)]> GRANT ALL PRIVILEGES ON *.* TO 'root'@'localhost' WITH GRANT OPTION;

   MariaDB [(none)]> FLUSH PRIVILEGES;

 

   Remember to replace `'your_root_password'` with the actual password you want to set.


5. Firewall considerations:

   Ensure that there are no firewall rules blocking the connection to the MariaDB server on localhost.

After performing these steps, try running your PHP script again. It should connect to the MariaDB server without the access denied error.


If you still encounter issues with access denied, here are a few things to check:


1. Verify the MariaDB root password:

   If you are unable to log in as the root user using the correct password, it's possible that the password is incorrect. You can try resetting the root password following these steps:


   - Stop the MariaDB service:

   sudo systemctl stop mariadb

 

   - Start the MariaDB server without permission checks:

   sudo mysqld_safe --skip-grant-tables &


   - Connect to the MariaDB server as the root user:

   mysql -u root

 

   - Update the root user's password:

   USE mysql;

   UPDATE user SET password = PASSWORD('new_password') WHERE User = 'root';

   FLUSH PRIVILEGES;


   Replace `'new_password'` with your desired new password.


   - Exit the MariaDB prompt:

   EXIT;


   - Stop the MariaDB server:

   sudo pkill mysqld_safe


   - Start the MariaDB service again:

   sudo systemctl start mariadb


2. Check for other potential login issues:

   It's possible that there are other issues causing the access denied error. For example, the 'root' user might not be allowed to connect from 'localhost'. Make sure you have the correct host specified in your PHP script (e.g., `'localhost'`).


3. Verify PHP configuration:

   Ensure that you are using the correct PHP configuration (`php.ini`) and that it is loading the `mysqli` extension properly.


Will "mysqli" extension work for MariaDB database?

Yes, `mysqli` can work with MariaDB in PHP. The `mysqli` extension stands for "MySQL Improved" and is designed to work with both MySQL and MariaDB databases. MariaDB is a fork of MySQL, so they share a lot of similarities and are largely compatible with each other.

When you use the `mysqli` extension in PHP, you can connect to both MySQL and MariaDB databases using the same functions and methods. This is because the `mysqli` extension provides an improved and more feature-rich API for accessing MySQL and MariaDB databases in PHP.

Here's a simple example of connecting to a MariaDB database using `mysqli` in PHP:


<?php

$servername = "localhost";

$username = "your_username";

$password = "your_password";

$dbname = "your_database";


// Create connection

$conn = new mysqli($servername, $username, $password, $dbname);


// Check connection

if ($conn->connect_error) {

    die("Connection failed: " . $conn->connect_error);

}


echo "Connected successfully";


// Close connection

$conn->close();

?>


Remember to replace `your_username`, `your_password`, and `your_database` with your actual database credentials.

So, whether you are working with MySQL or MariaDB, you can use `mysqli` in PHP to interact with the database effectively.

Install oci8 on centos 8

 Install oci8 on centos 8

 

Now that you have the necessary tools and libraries installed, you can proceed with the next steps to install the OCI8 extension for PHP on CentOS 8:

 

1. Install the Oracle Instant Client:

   - Download the Oracle Instant Client RPM packages for your architecture from the Oracle website (https://www.oracle.com/database/technologies/instant-client/linux-x86-64-downloads.html). You'll need  oracle-instantclient-basic ,  oracle-instantclient-devel and oracle-instantclient-sqlplus packages.

   - Transfer the downloaded RPM packages to your CentOS 8 system if you downloaded them on a different machine.

Note: for centos, it is better to download “.rpm” file rather than “.zip”

2. Install the Oracle Instant Client RPM packages:

Go to the directory where you downloaded the oracle instant-client files and install those files:

Let’s take example for version oracle instant-client 11.2,

sudo dnf install oracle-instantclient11.2-basic-11.2.0.4.0-1.x86_64.rpm  

sudo dnf install oracle-instantclient11.2-devel-11.2.0.4.0-1.x86_64

sudo dnf install oracle-instantclient11.2-sqlplus-11.2.0.4.0-1.x86_64

To verify whether the Oracle Instant Client "devel" package is installed on your CentOS system, you can use the package management tool rpm or dnf. Here's how you can check for the presence of the Oracle Instant Client devel package:

Using ‘rpm’:

rpm -qa | grep oracle-instantclient-devel

Using ‘dnf’:

dnf list installed | grep oracle-instantclient-devel

 

3. Verify the ORACLE_HOME environment variable:

echo $ORACLE_HOME

Ensure that the ORACLE_HOME environment variable is set correctly and points to the location where you installed the Oracle Instant Client. If it's not set correctly, you can set it as follows:

export ORACLE_HOME=/path/to/instant/client

During the installation process, you may be prompted to provide the path to the Oracle Instant Client library. If prompted, enter the correct path:

Enter the path: instantclient,/usr/lib/oracle/19.20/client64/lib

 

 

 

4. Set the environment variables required for OCI8 and PHP:

 

echo 'export ORACLE_HOME=/usr/lib/oracle/19.12/client64' | sudo tee -a /etc/profile.d/oracle.sh

echo 'export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/usr/lib/oracle/19.12/client64/lib' | sudo tee -a /etc/profile.d/oracle.sh

sudo ldconfig

Once you are done with above steps, the environment is set for oci8 installation, follow the bellows steps now,

5. Stop Apache and uninstall older version of OCI8 if any (stopping Apache is very important):

 service httpd stop

 pecl uninstall oci8

 

6. Install php-pear and php devel:

 sudo yum install php-pear php-devel

 pear download pecl/oci8

7. The next commands depend on the version of oci8 downloaded above.

$ tar xvzf oci8-2.2.0.tgz

$ cd oci8-2.2.0/

$ phpize

$ export PHP_DTRACE=yes

 

 

8. Make sure of the instantclient path below... mine was version 11.2 so it was located in this folder... Also make note some tutorials ask for the ORACLE_HOME folder which theoretically is /usr/lib/oracle/11.2/client64 but if its instantclient then put the lib folder underneath it (worked for me at least:)

$ ./configure --with-oci8=instantclient,/usr/lib/oracle/12.2/client64/lib/

$ make

$ make install

 

9. NOW an .so file built in: /usr/lib64/php/modules/oci8.so

10. check whether oci8 has been successfully installed or not:

php -m | grep oci8

11. sudo service httpd restart

The steps may not be needed in most of the cases. If indeed, it is required in your case go through these steps as well (though it is suggested to first try running before implementing the below steps):

# THIS STEP NOT NEEDED if SELinux disabled on your server/box, but if SELinux is enabled run: setsebool -P httpd_execmem 1

# NOW add:   extension=oci8.so    at the bottom of your php.ini file (probably in /etc/php.ini)

# Add extension_dir=/usr/lib64/php/modules/

Install Apache, PHP on Centos 8

 

Apache installation on centos 8

To install Apache on CentOS 8, you can use the `dnf` package manager, which is the replacement for `yum` in CentOS 8. Here's a step-by-step guide to installing Apache:

 

1. Open a terminal on your CentOS 8 system.

 

2. Update the package list to ensure you have the latest information about available packages:

sudo dnf update

 

3. Install Apache using the `dnf` package manager:

sudo dnf install httpd

 

4. After the installation is complete, start the Apache service:

sudo systemctl start httpd

 

5. Enable Apache to start on boot:

sudo systemctl enable httpd

 

6. Check the status of Apache to ensure it's running without any issues:

sudo systemctl status httpd

 

7. Adjust the firewall settings to allow incoming HTTP traffic:

sudo firewall-cmd --add-service=http --permanent

sudo firewall-cmd --reload

 

Now, Apache should be installed and running on your CentOS 8 system. You can verify its functionality by opening a web browser and accessing your server's IP address or domain name. You should see the default Apache welcome page if everything is set up correctly.

 

PHP installation on centos 8

 

To install PHP on CentOS 8, you can use the `dnf` package manager. Additionally, you may want to install some commonly used PHP extensions to ensure the proper functioning of PHP-based applications. Here's a step-by-step guide to installing PHP:

 

1. Open a terminal on your CentOS 8 system.

 

2. Update the package list to ensure you have the latest information about available packages:

sudo dnf update

 

3. Install PHP and some commonly used extensions:

sudo dnf install php php-cli php-fpm php-mysqlnd php-pdo php-gd php-xml php-mbstring

 

The packages above include the basic PHP package (`php`), command-line interface (`php-cli`), PHP-FPM (FastCGI Process Manager) for serving PHP through a web server, MySQL support (`php-mysqlnd`), PDO (PHP Data Objects) for database connectivity (`php-pdo`), GD library for image manipulation (`php-gd`), XML support (`php-xml`), and multibyte string support (`php-mbstring`).

 

4. After the installation is complete, start and enable the PHP-FPM service:

sudo systemctl start php-fpm

sudo systemctl enable php-fpm

 

5. Check the status of PHP-FPM to ensure it's running without any issues:

sudo systemctl status php-fpm

 

6. Restart Apache: After making any changes to the Apache or PHP-FPM configuration, restart Apache to apply the changes:

sudo systemctl restart httpd

 

 

Now, PHP is installed and ready to be used on your CentOS 8 system. You can test your PHP installation by creating a PHP file with the following content:

 

<?php

   phpinfo();

?>

 

Save the file as `info.php` in your web server's document root directory (typically `/var/www/html/`):

 

sudo echo "<?php phpinfo(); ?>" > /var/www/html/info.php

 

Then, open a web browser and navigate to `http://your_server_ip/info.php` or `http://your_domain/info.php`. You should see a PHP information page displaying PHP version, configuration settings, and more. Remember to remove this `info.php` file after testing for security reasons.

 

Run/Test website on Smartphone that is hosted on local PC

Thursday, August 3, 2023

Control session in PHP to prevent unauthorized access of pages directly ...

Sunday, July 30, 2023

What is Rainbow table used for Hacking?

 A rainbow table is a type of precomputed lookup table used in password cracking and cryptographic attacks. It is a specialized data structure that enables an attacker to quickly reverse the hash value of a password or other data encrypted with a hash function.


When passwords are stored in a database or transmitted over a network, they are often hashed first. Hashing is a one-way function that converts the password into a fixed-length string of characters. It is designed to be irreversible, meaning that it should be computationally infeasible to derive the original password from the hash.


However, attackers can still attempt to crack passwords by using rainbow tables. Here's how they work:


1. **Generating the Rainbow Table**: To create a rainbow table, an attacker precomputes a large number of hash values for various possible passwords and stores them in a table. This process is computationally intensive and time-consuming, but it needs to be done only once.


2. **Hash Lookup**: When an attacker gets hold of a hashed password from a target system, instead of directly trying to reverse the hash, they can simply look up the hash value in their precomputed rainbow table to find a matching entry.


3. **Recovery**: Once a match is found, the attacker can retrieve the corresponding password from the rainbow table, thus successfully cracking the hashed password.


To protect against rainbow table attacks, security experts recommend using additional measures, such as salting passwords. Salting involves adding a unique random value (the salt) to each password before hashing it. This makes rainbow tables ineffective because attackers would need to create separate rainbow tables for each possible salt value, which is impractical due to the vast number of combinations.


By using strong, salted cryptographic hashing algorithms and enforcing proper password management practices, organizations can enhance the security of their systems and protect against rainbow table attacks.

Wednesday, July 26, 2023

What is Crontab in Unix OS?

Crontab is a command used in Unix-like operating systems to schedule and automate the execution of tasks at specific intervals. It stands for "cron table," where "cron" is derived from the Greek word "chronos," meaning time. Crontab allows users to define a list of commands or scripts that need to be executed periodically according to a predefined schedule.


Each user on a Unix-based system can have their own crontab, which lists the tasks they want to run automatically. The tasks are specified in a text file, and the crontab command is used to manage and manipulate this file.


To view or edit your crontab, you can use the following commands:

- To edit your crontab: `crontab -e`

- To view your crontab: `crontab -l`


The basic syntax of a crontab entry consists of six fields, indicating the timing of the task execution:


```

* * * * * command_to_be_executed

- - - - -

| | | | |

| | | | +----- Day of the week (0 - 7) (Sunday is both 0 and 7)

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

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

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

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

```


Using this syntax, you can specify the minute, hour, day of the month, month, and day of the week when a particular command should be executed.


For example:

- `* * * * * command` means the command will run every minute.

- `0 3 * * * command` means the command will run at 3:00 AM every day.

- `15 12 * * * command` means the command will run at 12:15 PM every day.


Some more examples: 

Sure, here are some more examples of crontab commands and their syntax:


1. Run a script every day at 2:30 PM:

   ```

   30 14 * * * /path/to/your_script.sh

   ```


2. Run a command every Monday at 8:00 AM:

   ```

   0 8 * * 1 command_to_run

   ```


3. Run a script every hour:

   ```

   0 * * * * /path/to/your_script.sh

   ```


4. Run a script every 15 minutes:

   ```

   */15 * * * * /path/to/your_script.sh

   ```


5. Run a command on specific days of the month (1st and 15th) at 10:00 PM:

   ```

   0 22 1,15 * * command_to_run

   ```


6. Run a command on specific months (January, April, July, October) on the 5th day at 12:00 PM:

   ```

   0 12 5 1,4,7,10 * command_to_run

   ```


7. Run a command on weekdays (Monday to Friday) at 6:30 AM:

   ```

   30 6 * * 1-5 command_to_run

   ```


8. Run a script every Sunday at midnight (12:00 AM):

   ```

   0 0 * * 0 /path/to/your_script.sh

   ```


9. Run a command every 10 minutes between 9 AM and 5 PM on weekdays:

   ```

   */10 9-17 * * 1-5 command_to_run

   ```


10. Run a command every even hour (0, 2, 4, 6, 8, ...):

   ```

   0 */2 * * * command_to_run

   ```


Remember, the fields in the crontab entry represent minute, hour, day of the month, month, and day of the week. You can mix and match these fields to create specific schedules for running commands or scripts. Additionally, you can use the `*` wildcard to specify "every" for a particular field, and you can use comma-separated values to specify multiple allowed values for a field. The syntax allows for a lot of flexibility in defining the timing of scheduled tasks.

Crontab is a powerful tool that allows system administrators and users to automate repetitive tasks, such as backups, system maintenance, data processing, and more. It is widely used to schedule tasks on servers and other Unix-based systems to ensure that certain operations occur regularly and without manual intervention.

What is AAA sever and its application in Telecom industry?

What is AAA server? 

An AAA server stands for "Authentication, Authorization, and Accounting" server. It is a centralized network server that provides three essential functions for managing user access to resources in a computer network:


1. Authentication: The AAA server verifies the identity of users or devices trying to access the network. It ensures that users are who they claim to be before allowing them access to network resources. Authentication methods can include username/password combinations, digital certificates, biometrics, or other multifactor authentication mechanisms.


2. Authorization: After successful authentication, the AAA server determines the level of access or permissions that the authenticated user or device should have within the network. It enforces access control policies, deciding what resources the user is allowed to use and what actions they can perform based on their role or group membership.


3. Accounting: The AAA server tracks and records the activities of authenticated users during their network session. This information includes details such as when the user logged in, which resources they accessed, how long they stayed connected, and other relevant session-related data. The accounting data is crucial for billing, auditing, and troubleshooting purposes.


AAA servers play a vital role in network security and management by centralizing and streamlining user access control. Instead of managing authentication and authorization on individual devices or services, organizations can use AAA servers to handle these tasks across the entire network. This centralization improves security, simplifies administration, and allows for consistent access control policies.


RADIUS (Remote Authentication Dial-In User Service) and TACACS+ (Terminal Access Controller Access Control System Plus) are two popular protocols used to communicate between network devices (such as routers, switches, or firewalls) and AAA servers to perform authentication, authorization, and accounting functions.


Application in Telecom Industry:

In the telecommunications industry, AAA (Authentication, Authorization, and Accounting) servers play a crucial role in managing user access to various network services and ensuring the security, efficiency, and accountability of these services. Here are some specific uses and importance of AAA servers in telecom:


1. Subscriber Authentication: AAA servers are used to authenticate subscribers trying to access telecommunications services, such as mobile data, voice calls, or broadband internet. This ensures that only authorized users can connect to the network, preventing unauthorized access and potential security breaches.


2. Service Authorization: Once a subscriber is authenticated, the AAA server determines what services the user is allowed to access based on their subscription, plan, or other relevant factors. For example, it verifies if the subscriber has the necessary data plan to access the internet or if they are eligible for specific value-added services.


3. Resource Access Control: In telecom networks, various network elements like switches, routers, and gateways need to interact with the AAA server to control subscriber access to specific resources. The AAA server communicates with these network elements to enforce access control policies and ensure that users can only access the services they are entitled to use.


4. Roaming and Interconnection: In the context of mobile networks, AAA servers are crucial for handling roaming scenarios. When a subscriber roams onto another network, the AAA server of the visited network communicates with the home network's AAA server to authenticate the user and determine the applicable services and billing arrangements.


5. Accounting and Billing: The accounting function of AAA servers is vital for tracking usage patterns and collecting data related to subscribers' network activities. This data is used for billing purposes, enabling telecommunications providers to accurately charge their customers based on the services they have used.


6. Policy Enforcement: Telecom operators use AAA servers to enforce various policies, such as Quality of Service (QoS) policies that prioritize certain types of traffic over others. This helps in ensuring a better user experience for critical services like voice calls or real-time video streaming.


7. Fraud Prevention: AAA servers contribute to fraud prevention by detecting and blocking suspicious or unauthorized activities, such as SIM cloning or unauthorized access attempts.


8. Seamless Handovers: In mobile networks, AAA servers assist in seamless handovers between different network cells or technologies, ensuring continuity of services as subscribers move within the coverage area.


Overall, AAA servers are essential in the telecom industry to provide a secure and efficient network experience for subscribers, control access to valuable resources, enable seamless interconnection and roaming, and facilitate accurate billing and accounting processes. They are a fundamental component of the infrastructure that enables telecommunications services to function effectively and securely.

Tuesday, July 25, 2023

What is Archive logs in Oracle database?

An archive log is a term commonly used in the context of database management systems, particularly with relation to Oracle Database.


In a database system, the archive log refers to a copy of a redo log file that has been filled with data and then archived (backed up) to a storage location, such as a separate disk or tape. The redo log files store a record of changes made to the database, and these changes are essential for recovering the database in the event of a failure or for performing certain types of backups (e.g., hot backups).


Here's a brief overview of how archive logs work in Oracle Database:


1. Redo Log Files: When changes are made to the database, they are first written to the redo log files in a circular fashion. These files are crucial for maintaining a record of all transactions that modify the database.


2. Log Switch: Once a redo log file is filled with data, a log switch occurs, and the database starts writing to a new redo log file. The filled redo log file is now ready for archiving.


3. Archiving: The filled redo log file is copied (archived) to a separate location known as the archive log destination. This process ensures that a copy of the redo log is preserved even after a log switch, which helps in data recovery and backup operations.


4. Backup and Recovery: By regularly archiving the redo logs, database administrators can use them to recover the database to a specific point in time in case of a system failure or data corruption. Additionally, archive logs are necessary for performing consistent backups while the database remains operational (hot backups).


It's essential to manage archive logs properly to avoid running out of disk space and to ensure database recoverability. Administrators often set up proper archiving policies and regularly back up archived logs to free up space and safeguard critical data.

Wednesday, July 19, 2023

How Truecaller app decides which name to display among many?

When multiple people save the same phone number with different names in their contacts, Truecaller's caller identification algorithm takes several factors into account to decide which name to display when that number calls a Truecaller user:


1. **User Contribution**: Truecaller relies heavily on crowdsourced data, which means that user contributions play a significant role in determining the caller's name. If a large number of users have saved a particular name for a specific phone number, that name is more likely to be displayed for other Truecaller users when they receive a call from that number.


2. **Contact Frequency**: Truecaller considers the frequency with which a specific name is associated with the phone number in the contacts of its users. If a particular name appears more frequently than others, it is given higher priority for display.


3. **Contact Details**: Truecaller may prioritize names that have additional details, such as a profile picture, address, or other information, as these entries tend to be more comprehensive and credible.


4. **User Interaction**: Truecaller also takes into account user interactions and feedback. If a user frequently interacts with a contact or tags a specific name for a particular phone number, it can influence the caller ID display for that number.


5. **Data Confidence and Consistency**: Truecaller uses various data sources to build its database. The algorithm assesses the confidence and consistency of the data before displaying a name. If multiple sources have consistent information, it is more likely to be displayed.


6. **Personal Contacts**: If a Truecaller user has a specific contact saved with a name in their personal address book, Truecaller may prioritize that name over other user-contributed names.


7. **Local Language and Region**: Truecaller considers the local language and regional preferences when displaying caller names, especially if the caller ID information is provided in multiple languages.


8. **Relevance to User**: The algorithm may also consider the relevance of the name to the user based on their geographical location, social connections, and other factors.


It's important to note that Truecaller's caller identification system continuously learns and improves over time based on user behavior, feedback, and data contributions. As a result, the accuracy and relevance of the displayed names may vary depending on the information available in the Truecaller database and user-contributed data.

How Truecaller app works?

1. **Data Collection**: Truecaller collects contact information from various sources, including users' address books, publicly available directories, social media platforms, and user-generated content. This data is used to build a comprehensive global phone number database.

2. **User Registration and Verification**: When a user installs the Truecaller app, they need to register and verify their phone number. During registration, the app requests permissions to access the user's contact list.


3. **Data Synchronization**: After the user grants permission, Truecaller synchronizes the user's contact list with its own database. This allows the app to match incoming calls with known phone numbers and display relevant information about the caller, such as the caller's name, profile picture, and location.


4. **Crowdsourced Data**: Truecaller utilizes crowdsourcing to improve its database continuously. Users can contribute by reporting spam calls, tagging unknown numbers, or updating contact information. This data is then verified and used to enhance the accuracy of the caller identification system.


5. **Caller Identification**: When a user receives an incoming call, Truecaller uses the synchronized database to identify the caller by matching the incoming phone number with the data available in its database. If there is a match, the app displays the caller's information on the user's screen, providing them with more context about the call.


6. **Spam Detection and Blocking**: Truecaller employs algorithms and user-generated spam reports to identify and block spam calls automatically. When the app detects a spam call, it notifies the user and provides options to block or report the number.


7. **Privacy and Consent**: Truecaller respects user privacy and allows individuals to control their information. Users can choose to unlist their numbers from the Truecaller database and decide whether or not to share their contacts with the service.


8. **Premium Features**: Truecaller offers premium features for a subscription fee, such as ad-free usage, contact requests, and enhanced spam blocking.


**Architecture**:

Truecaller's architecture is likely to consist of several components, such as:


- **Mobile Apps**: The Truecaller app is available on multiple platforms (Android, iOS, etc.), allowing users to access its services.


- **Web Services**: Truecaller likely has web services that handle user registrations, data synchronization, and communication with the database.


- **Database**: The core of Truecaller's architecture is its extensive database of phone numbers, contact information, and spam reports. This database is the backbone of the caller identification system.


- **Machine Learning and Algorithms**: Truecaller uses machine learning algorithms to improve caller identification accuracy and detect spam calls. These algorithms continuously learn from user behavior and data.


- **Crowdsourcing Platform**: There is a crowdsourcing platform where users can contribute by reporting spam and updating contact information.


- **APIs**: Truecaller may have APIs that allow integration with other services and apps.


Saturday, July 15, 2023

Birthday Paradox and Birthday attack: how is it associated with Birthday?

Birthday Paradox:

The birthday paradox, also known as the birthday problem, is a surprising phenomenon in probability theory. It states that in a group of relatively few people, the probability of two people sharing the same birthday is higher than what one might intuitively expect.


The paradox arises from the fact that the number of possible pairs of people with the same birthday grows rapidly as the group size increases. To understand this, let's consider an example:


Suppose you have a group of 23 people. The goal is to calculate the probability that at least two people in the group have the same birthday.


To solve this problem, it is easier to calculate the probability of no two people sharing the same birthday and subtract it from 1 (the total probability).


For the first person, their birthday can be any of the 365 days of the year. The second person should have a different birthday, which leaves 364 possible options. The third person should also have a different birthday from the first two, which leaves 363 possible options, and so on.


The probability of no two people sharing the same birthday in a group of 23 can be calculated as:


(365/365) * (364/365) * (363/365) * ... * (343/365)


To find the probability of at least two people sharing the same birthday, we subtract this probability from 1:


1 - [(365/365) * (364/365) * (363/365) * ... * (343/365)]


After performing the calculations, we find that the probability is approximately 0.507, or around 50%. This means that in a group of just 23 people, there is a 50% chance that at least two people will have the same birthday.


This result is counterintuitive because we tend to think that a larger group is needed to have a significant probability of shared birthdays. However, due to the large number of possible pairs of individuals within the group, the probability increases rapidly.


In cryptography, the birthday paradox is relevant to birthday attacks on hash functions. It demonstrates that the probability of finding collisions (two inputs with the same hash value) increases much faster than one might expect as the number of hash calculations grows. Cryptographic algorithms must take this into account to ensure the security and integrity of data.



Birthday attack

Certainly! Let's dive into more details about birthday attacks in the context of cryptography.


A birthday attack is a type of cryptographic attack that takes advantage of the birthday paradox to find collisions in a hash function more efficiently than a brute-force approach. Instead of trying all possible inputs, the attack leverages the higher probability of finding collisions due to the pigeonhole principle.


In a hash function, the goal is to map an input of any length to a fixed-size output, known as the hash value or hash code. A secure hash function should produce a unique hash value for each unique input, making it computationally infeasible to find two different inputs that result in the same hash value (a collision).


However, due to the birthday paradox, the probability of finding a collision in a hash function increases rapidly as the number of hashed inputs grows. The birthday attack exploits this higher probability to find collisions more efficiently.


The attack works by generating a large number of inputs, calculating their hash values, and comparing them to look for matches. As the number of inputs increases, the probability of finding a collision approaches 1, meaning that a collision is highly likely.


To carry out a successful birthday attack, the attacker needs to generate a significantly lower number of inputs than the total number of possible inputs. This makes the attack more efficient than a brute-force approach, which would require trying all possible inputs.


For example, consider a hash function with a 128-bit hash value. A brute-force approach to finding a collision would require trying approximately 2^64 inputs, which is computationally infeasible. However, using a birthday attack, the attacker can find a collision with a much lower number of inputs, such as the square root of the total number of possible inputs, which is only 2^64/2^64 = 2^32 inputs. This is a significant reduction in computational effort.


To mitigate birthday attacks, cryptographic algorithms and hash functions are designed with larger hash sizes (e.g., 256-bit) to make the probability of collisions extremely low, even when the number of hashed inputs is relatively large. Additionally, other security measures, such as salting and key stretching, can be employed to enhance the security of hash functions and protect against birthday attacks.


It's worth noting that while birthday attacks are a concern in cryptography, they generally require a large number of hash computations and are more relevant in specific scenarios where collision resistance is critical, such as digital signatures and certificate authorities. For many general-purpose applications, standard cryptographic hash functions provide sufficient security against birthday attacks.


Why is it named "Birthday attack"?

The term "birthday" in the context of the birthday attack refers to the concept of the birthday paradox, which is a counterintuitive result in probability theory. The birthday paradox states that in a relatively small group of people, the probability of two people sharing the same birthday is higher than what one might expect.


The connection between the birthday paradox and the birthday attack lies in the underlying principle they both share—the pigeonhole principle. The birthday paradox is a demonstration of the pigeonhole principle in action, showing that in a group of people, the number of possible pairs with matching birthdays increases rapidly as the group size grows.


The birthday attack in cryptography exploits this higher probability of collisions, as seen in the birthday paradox, to find collisions in hash functions more efficiently. It takes advantage of the fact that the number of possible inputs is much larger than the number of possible hash values, creating a scenario where the probability of finding a collision becomes significant.


The name "birthday attack" is given to this cryptographic attack because it draws an analogy to the birthday paradox. Just as the paradox demonstrates that the probability of shared birthdays is surprisingly high in a small group, the birthday attack leverages the same principle to find collisions in hash functions more efficiently than expected.


So, the term "birthday" in the birthday attack refers to the connection between the attack's exploitation of collision probabilities and the surprising nature of the birthday paradox.

Pigeonhole principle application in Cryptography

 In cryptography, the pigeonhole principle is often applied to understand the limits and vulnerabilities of certain cryptographic techniques, specifically in the context of hashing and collision detection. Here are a couple of examples:



1. Hash Function Collisions:

A hash function takes an input and produces a fixed-size output called a hash value or hash code. The pigeonhole principle helps us understand that if we have more possible inputs than the number of distinct hash values the function can produce, there must be at least two inputs that will result in the same hash value. This is known as a collision.


For example, consider a hash function that produces a 32-bit hash code. If we try to hash more than 2^32 inputs (around 4.3 billion), according to the pigeonhole principle, at least two inputs will result in the same hash code. This property is crucial in cryptography for detecting potential weaknesses in hash functions and ensuring that they can resist collision attacks.


2. Birthday Paradox:


The birthday paradox is an application of the pigeonhole principle that demonstrates the surprising probability of two individuals sharing the same birthday within a relatively small group. Although it is not directly related to cryptography, it has implications for cryptographic techniques like birthday attacks.


In cryptography, a birthday attack takes advantage of the birthday paradox to find collisions in a hash function more efficiently than a brute-force approach. Instead of trying all possible inputs, the attack leverages the higher probability of finding collisions due to the pigeonhole principle. By calculating the expected number of attempts needed to find a collision, cryptographic experts can determine the security strength of a hash function against birthday attacks.


These examples illustrate how the pigeonhole principle is utilized in cryptography to analyze the limitations and vulnerabilities of certain cryptographic techniques, particularly in hash function collisions and birthday attacks. By understanding these principles, cryptographic algorithms can be designed and evaluated to withstand potential attacks and ensure secure communication and data protection.