A Pre-Shared Key (PSK) or also known as a shared secret is a string of characters that is used as an authentication key in cryptographic processes. A PSK is shared before being used and is held by both parties to the communication to authenticate each other, usually before other authentication methods such as usernames and passwords are applied.
It is commonly used in different types of Virtual Private Network (VPN) connections, wireless networks in a type of encryption known as WPA-PSK (Wi-Fi Protected Access Pre-Shared Key) and WPA2-PSK, and also in the EAP (Extensible Authentication Protocol Pre-Shared Key), and many others authentication mechanisms.
Among those data, you find the SECRETKEY setting and the database password. A common practice to hide these settings from version control is to create a file secrets.json at the root of your project ( thanks ' Two Scoops of Django ' for the idea ). Dec 14, 2017 Command-Line Tool. This module also implements a CLI tool, that can be used to generate secret keys for Django. For more information, use the following command: code-block:: console $ python3 -m djangokeys –help. For example, one could generate a new key and store it in the file secret.key by using the command below: code-block:: console. Aug 12, 2019 This secret key is added to an authenticator app (e.g., Google Authenticator) on a mobile device. The app can then generate TOTP values based on the current time. By default, it generates a new TOTP value every 30 seconds. MinTOTP is a Python tool that can be used to generate TOTP values from a secret key.
In this article, we will show you different ways to generate a strong Pre-Shared Key in Linux distributions.
1. Using OpenSSL Command
OpenSSL is a well-known and widely-used command-line tool used to invoke the various cryptography functions of OpenSSL’s crypto library from the shell. To generate a strong PSK use its rand sub-command which generates pseudo-random bytes and filter it through base64 encodings as shown.
2. Using GPG Command
GPG is a command-line tool to provide digital encryption and signing services using the OpenPGP standard. You can use its --gen-random
option to generate a strong PSK and filter it through base64 encoding as shown.
In the following commands, 1 or 2 is the quality level and 10, 20, 40, and 70 are the character counts.
Generate PSK Key Using GPG Command
3. Using Pseudorandom Number Generators
You can also use any of the pseudorandom number generators in Linux such as /dev/random or /dev/urandom, as follows. The -c
option of the head command helps to generate the number of characters.
4. Using date and sha245sum Commands
The date and sha256sum command can be combined to create a strong PSK as follows.
Generate PSK Using date Command
The above are some of the many ways of generating strong Pre-Shared Key in Linux. Do you know of any other methods? If yes, share it with us via the feedback form below.
Generate Django Secret Key Command Line Code
>python manage.py runserver |
Traceback (most recent call last): |
File 'manage.py', line 8, in <module> |
execute_from_command_line(sys.argv) |
File '//anaconda/lib/python2.7/site-packages/django/core/management/__init__.py', line 399, in execute_from_command_line |
utility.execute() |
File '//anaconda/lib/python2.7/site-packages/django/core/management/__init__.py', line 392, in execute |
self.fetch_command(subcommand).run_from_argv(self.argv) |
File '//anaconda/lib/python2.7/site-packages/django/core/management/base.py', line 242, in run_from_argv |
self.execute(*args, **options.__dict__) |
File '//anaconda/lib/python2.7/site-packages/django/core/management/base.py', line 279, in execute |
saved_locale = translation.get_language() |
File '//anaconda/lib/python2.7/site-packages/django/utils/translation/__init__.py', line 154, in get_language |
return _trans.get_language() |
File '//anaconda/lib/python2.7/site-packages/django/utils/translation/__init__.py', line 52, in __getattr__ |
if settings.USE_I18N: |
File '//anaconda/lib/python2.7/site-packages/django/conf/__init__.py', line 54, in __getattr__ |
self._setup(name) |
File '//anaconda/lib/python2.7/site-packages/django/conf/__init__.py', line 49, in _setup |
self._wrapped = Settings(settings_module) |
File '//anaconda/lib/python2.7/site-packages/django/conf/__init__.py', line 151, in __init__ |
raise ImproperlyConfigured('The SECRET_KEY setting must not be empty.') |
django.core.exceptions.ImproperlyConfigured: The SECRET_KEY setting must not be empty. |
commented Nov 8, 2016•
Solution of the problem Just like the error says, you have no SECRET_KEY defined. You need to add one to your settings.py. The SECRET_KEY can be just about anything..but if you want to use Django to generate one, you can do the following from the python shell:
Copy the SECRET_KEY to your settings file. |