Modules – TecAdmin https://tecadmin.net How to guide for System Administrator's and Developers Sat, 31 Dec 2022 18:04:20 +0000 en-US hourly 1 https://wordpress.org/?v=6.1.1 How to Generate Random Password in Python https://tecadmin.net/how-to-generate-random-password-in-python/ https://tecadmin.net/how-to-generate-random-password-in-python/#respond Tue, 27 Dec 2022 09:07:35 +0000 https://tecadmin.net/?p=33004 In Python, you can generate a random password using the secrets module, which is part of the Python standard library. The secrets module provides a secure way to generate random strings, numbers, and other values that can be used for various purposes, such as generating passwords, tokens, or unique IDs. Tips for Generating Secure Passwords: [...]

The post How to Generate Random Password in Python appeared first on TecAdmin.

]]>
In Python, you can generate a random password using the secrets module, which is part of the Python standard library. The secrets module provides a secure way to generate random strings, numbers, and other values that can be used for various purposes, such as generating passwords, tokens, or unique IDs.

Tips for Generating Secure Passwords:

Here are a few tips to keep in mind when generating passwords:

  • Use a strong, random password generator to create passwords that are difficult to guess or crack.
  • Use a different password for each account or service that you use.
  • Use long passwords that are at least 12 characters long.
  • Use a combination of letters, numbers, and special characters in your passwords.
  • Avoid using easily guessable words or phrases in your passwords.

In this tutorial we will discuss two methods to generate random passwords in Python.

Using the Python `secrets` Module

The `secrets` module is part of the Python standard library and provides a secure way to generate random strings, numbers, and other values that can be used for various purposes, such as generating passwords, tokens, or unique IDs.

Here’s an example of how to use the secrets module to generate a random password in Python:

import secrets

def generate_password(length):
    # Generate a random string of hexadecimal digits
    password = secrets.token_hex(length // 2)
    # Return the first `length` characters of the password
    return password[:length]

password = generate_password(17)
print(password)

This code will generate a random password of the specified length, consisting of hexadecimal digits (0-9 and a-f). The generate_password() function uses the secrets.token_hex() function to generate a secure, random string of hexadecimal digits, and then it returns the first length characters of the string.

How to Generate Random Password in Python
Generate Random Password in Python #1

Using the Python `random` Module

You can also use the `random` module from the Python standard library to generate a random password. Here’s an example of how to do that:

import random
import string

def generate_password(length):
    # Generate a list of random characters
    characters = [random.choice(string.ascii_letters + string.digits + string.punctuation) for _ in range(length)]
    # Shuffle the list of characters
    random.shuffle(characters)
    # Return the shuffled list of characters as a string
    return ''.join(characters)

password = generate_password(17)
print(password)

This code will generate a random password of the specified length, consisting of uppercase and lowercase ASCII letters, digits, and punctuation marks. The `generate_password()` function uses the `random.choice()` function to randomly select characters from the `string.ascii_letters`, `string.digits`, and `string.punctuation` strings, and then it uses the `random.shuffle()` function to shuffle the list of characters. Finally, it uses the `join()` function to combine the shuffled list of characters into a single string.

How to Generate Random Password in Python
Generate Random Password in Python #2

I hope this tutorial helps you to understand how to generate passwords in Python scripts!

Conclusion

In conclusion, generating random passwords in Python is a useful task that can be easily accomplished using the random module and the string module. The `random` module provides functions for generating random numbers, and the `string` module provides functions for generating random strings. By combining these two modules, you can generate random passwords of any length and complexity.

You can also use the `secrets` module, which is a more secure alternative to the random module, to generate random passwords. Understanding how to generate random passwords in Python can be helpful in various scenarios, such as when you need to create secure passwords for user accounts or when you want to create unique passwords for different purposes.

The post How to Generate Random Password in Python appeared first on TecAdmin.

]]>
https://tecadmin.net/how-to-generate-random-password-in-python/feed/ 0
How To Install Apache mod_cloudflare on Debian https://tecadmin.net/install-apache-mod-cloudflare-on-debian/ https://tecadmin.net/install-apache-mod-cloudflare-on-debian/#comments Sun, 04 Oct 2020 04:46:32 +0000 https://tecadmin.net/?p=23045 Cloudflare is the most popular content delivery network service provider. Which also incudes DNS, DDoS protection and security for the websites. In action cloudflare act as reverse proxy server. Once the website traffic is routed with cloudflare network, the backend server don’t know the actual visitor ip. In result, you will see the cloudflare IP [...]

The post How To Install Apache mod_cloudflare on Debian appeared first on TecAdmin.

]]>
Cloudflare is the most popular content delivery network service provider. Which also incudes DNS, DDoS protection and security for the websites. In action cloudflare act as reverse proxy server. Once the website traffic is routed with cloudflare network, the backend server don’t know the actual visitor ip. In result, you will see the cloudflare IP address in Apache logs.

Now the question is how to get the real visitor IP in logs, instead of cloudflare IP. To resolve this, cloudflare provides an Apache module to get real visitor ip and log them.

This tutorial will help you to enable Apache mod_cloudflare module on Debian system. Which will log real visitor IP address to Apache access logs.

Install Apache mod_cloudflare on Debian

The cloudflare provides an official module for the Apache server to capture real ip address. You need to enable the PPA of cloudflare module to your Ubuntu system.

Add GPG – Open a terminal and execute below commands to enable add gpg key to your system.

sudo apt install curl 
curl -C - https://pkg.cloudflare.com/pubkey.gpg | sudo apt-key add - 

Add PPA – Then add the cloudflare repository to your debian system

echo "deb http://pkg.cloudflare.com/ `lsb_release -cs` main" | sudo tee /etc/apt/sources.list.d/cloudflare.list 

Install Package – Next, update Apt cache and install libapache2-mod-cloudflare package on your Ubuntu system.

sudo apt update 
sudo apt install libapache2-mod-cloudflare 

Press ‘Y’ for any confirmation asked during the installation.

Restart Apache

Once the installation completed, restart Apache2 service and check the active modules using the following commands.

sudo systemctl restart apache2 

That’s it. The Apache server will log real IP address of the visitor to the logs.

sudo apache2ctl -M 

Conclusion

In this tutorial, you have learned to install Apache cloudflare module on Debian Linux system.

The post How To Install Apache mod_cloudflare on Debian appeared first on TecAdmin.

]]>
https://tecadmin.net/install-apache-mod-cloudflare-on-debian/feed/ 1
How to Enable Apache mod_rewrite Module in Ubuntu & Debian https://tecadmin.net/enable-apache-mod-rewrite-module-in-ubuntu-linuxmint/ https://tecadmin.net/enable-apache-mod-rewrite-module-in-ubuntu-linuxmint/#comments Sat, 16 May 2015 02:46:01 +0000 https://tecadmin.net/?p=7834 The Apache mod_rewrite module is a rewriting engine based on defined rules. The Apache rewrite engine maps a URL to a directory path as well as to other URLs. In this tutorial, you will learn, how to enable the Apache mod_rewrite module and configure VirtualHost to use .htaccess files available under the document root. Sometimes [...]

The post How to Enable Apache mod_rewrite Module in Ubuntu & Debian appeared first on TecAdmin.

]]>
The Apache mod_rewrite module is a rewriting engine based on defined rules. The Apache rewrite engine maps a URL to a directory path as well as to other URLs. In this tutorial, you will learn, how to enable the Apache mod_rewrite module and configure VirtualHost to use .htaccess files available under the document root.

Sometimes you faced issues the Apache server is not reading your .htaccess or Apache is not rewriting URLs while we are using correct rewrite rules in configuration files. This happens due to the Apache rewrite module is not being enabled. When we installed a fresh Apache server mod_rewrite is not enabled by default on your server, So to use rewrite configurations you need to manually enable the mode_rewrite module on your system.

Enable Apache2 mod_rewrite Module

We use a2enmod command to enable any modules in Apache2 web server. So use following command to enable mod_rewrite module in your Apache setup.

sudo a2enmod rewrite

Enable .htaccess for VirtualHost

After enabling the Apache rewrite module, now you need to add “AllowOverride All” in your VirtualHost configuration file.

<VirtualHost *:80>
    ServerName  www.example.com
    DocumentRoot /var/www/html

    <Directory /var/www/html>
        AllowOverride All
    </Directory>	
</VirtualHost>

This setting can also be enabled globally by editing the Apache main configuration file.

<Directory /var/www/html>
    Options Indexes FollowSymLinks
    AllowOverride All
</Directory>

Restart Apache2

After enabling the mod_rewrite module in Apache you also need to reload the Apache2 server to reload all configurations to the running environment.

sudo systemctl restart apache2

The post How to Enable Apache mod_rewrite Module in Ubuntu & Debian appeared first on TecAdmin.

]]>
https://tecadmin.net/enable-apache-mod-rewrite-module-in-ubuntu-linuxmint/feed/ 2
How to enable or disable Apache2 Modules https://tecadmin.net/enable-disable-modules-in-apache2-on-ubuntu-linuxmint/ https://tecadmin.net/enable-disable-modules-in-apache2-on-ubuntu-linuxmint/#comments Sat, 16 May 2015 02:27:37 +0000 https://tecadmin.net/?p=7827 Apache2 is a most popular web server used in Linux operating systems. Apache is a modular web server where each functionality is served by specific modules. To add or remove any specific functionality to the Apache server we can simply enable or disable the corresponding module. All the Apache2 modules are stored under /etc/apache2/mods-available/ directory. [...]

The post How to enable or disable Apache2 Modules appeared first on TecAdmin.

]]>
Apache2 is a most popular web server used in Linux operating systems. Apache is a modular web server where each functionality is served by specific modules. To add or remove any specific functionality to the Apache server we can simply enable or disable the corresponding module.

All the Apache2 modules are stored under /etc/apache2/mods-available/ directory. Once we enable any module it makes a soft link to /etc/apache2/mods-enabled/ directory. The same process reverses, once we disable any module.

In this tutorial, you will learn about enabling and disabling Apache2 modules on Debian-based systems.

1. Enable Apache2 Module

We use a2enmod command to enable modules in Apache2 web server. For example, if we need to enable the Apache rewrite module use the following command.

sudo a2enmod rewrite 

Then reload the Apache configuration.

sudo systemctl relaod apache2 

2. Disable Apache2 Module

Similarly to disable module we use a2dismod command. For example, if we need to disable the Apache rewrite module use the following command.

sudo a2dismod rewrite 

Then reload the Apache configuration.

sudo systemctl relaod apache2 

3. Check Modules Status

Check the status of the specific module using the a2query command. For example to find the current status of the rewrite module run the below command.

sudo a2query -m rewrite 
Output
rewrite (enabled by site administrator)

4. List Apache2 Modules

To list all available Apache2 modules with the status, use the following command. The output will differ system to system.

sudo a2query -m 
Output
autoindex (enabled by maintainer script) mpm_prefork (enabled by maintainer script) authn_file (enabled by maintainer script) proxy (enabled by site administrator) authz_svn (enabled by maintainer script) dav (enabled by maintainer script) ... ... dav_svn (enabled by maintainer script) proxy_http (enabled by site administrator) authz_user (enabled by maintainer script) filter (enabled by maintainer script) access_compat (enabled by maintainer script) setenvif (enabled by maintainer script)

That’s it. Assuming this tutorial gives you little understanding about modules management in Apache2 web server.

The post How to enable or disable Apache2 Modules appeared first on TecAdmin.

]]>
https://tecadmin.net/enable-disable-modules-in-apache2-on-ubuntu-linuxmint/feed/ 4
How to Enable Event MPM in Apache 2.4 on CentOS/RHEL 7 https://tecadmin.net/enable-event-mpm-in-apache-2-4/ https://tecadmin.net/enable-event-mpm-in-apache-2-4/#comments Sun, 01 Mar 2015 03:20:20 +0000 https://tecadmin.net/?p=7239 Apache MPM (Multi-Processing Modules) are Apache modules for creating child processes in Apache. There are many Apache MPM available, Each of them works in his own way. If you are using default Apache installation, Apache will use Prefork MPM by default. Event MPM is launched with many improvements from worker MP. I prefer to use [...]

The post How to Enable Event MPM in Apache 2.4 on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
Apache MPM (Multi-Processing Modules) are Apache modules for creating child processes in Apache. There are many Apache MPM available, Each of them works in his own way. If you are using default Apache installation, Apache will use Prefork MPM by default.

Event MPM is launched with many improvements from worker MP. I prefer to use the Event MPM which is an improvement over the Worker MPM. Event MPM is that Event has a dedicated thread which handles all Keep Alive connections and requests.

This article will help you to Disable Prefork MPM and Enable Event MPM on Apache 2.4 running on your Linux operating system.

Enable Event MPM in Apache

First edit Apache MPM configuration file in your favorite text editor.

# vim /etc/httpd/conf.modules.d/00-mpm.conf

Comment LoadModule line for mpm_prefork_module, mpm_worker_module and Un comment LoadModule line for mpm_event_module in configuration as per showing below.


#LoadModule mpm_prefork_module modules/mod_mpm_prefork.so
#LoadModule mpm_worker_module modules/mod_mpm_worker.so

LoadModule mpm_event_module modules/mod_mpm_event.so 

enable event mpm

After making above changes just restart your Apache servers.

# systemctl restart httpd

Check Active MPM in Apache

Now you have successfully enabled Event MPM in your Apache server. To verify current MPM enabled on your server use following command.

[root@TecAdmin ~]# httpd -V | grep MPM

Server MPM:     event

The post How to Enable Event MPM in Apache 2.4 on CentOS/RHEL 7 appeared first on TecAdmin.

]]>
https://tecadmin.net/enable-event-mpm-in-apache-2-4/feed/ 4